I am trying to add a menubar I created in my resource to a dialog from my resource, but I can't quite figure out how to.
I searched a lot of guides on that, but they all seem to be working only with
TypeError: $q.resolve is not a function
at http://localhost:8080/build/js/all-136a0f7ece.js:46792:32
at Object.forEach (http://localhost:8080/build/js/all-136a0f7ece.js:350:20)
at Object.resolve (http://localhost:8080/build/js/all-136a0f7ece.js:46790:19)
at Object.$modal.open (http://localhost:8080/build/js/all-136a0f7ece.js:47357:69)
at Scope.$scope.open (http://localhost:8080/build/js/all-136a0f7ece.js:46443:35)
at fn (eval at <anonymous> (http://localhost:8080/build/js/all-136a0f7ece.js:13036:15), <anonymous>:4:203)
at callback (http://localhost:8080/build/js/all-136a0f7ece.js:23090:17)
at Scope.$eval (http://localhost:8080/build/js/all-136a0f7ece.js:15719:28)
at Scope.$apply (http://localhost:8080/build/js/all-136a0f7ece.js:15818:23)
at HTMLAnchorElement.<anonymous> (http://localhost:8080/build/js/all-136a0f7ece.js:23095:23)
which seems to be a very old relic according to Does ATL/WTL still require the use of a global _Module variable?
Most of these guides want to tackle the problem using this method:
_Module
However, I would like to know what the "modern" way would be then, considering the CMenu menu;
menu.Attach( LoadMenu( _Module.GetResourceInstance(),MAKEINTRESOURCE(<Menubar ID>)));
SetMenu( menu );
-way is outdated.
Can anyone point me to a solution?
答案 0 :(得分:3)
WinAPI函数的第一个参数LoadMenu是应该加载菜单的模块的HINSTANCE。如果您的应用资源位于可执行文件中(而不是单独的资源DLL),您可以通过调用GetModuleHandle(NULL)
获取其实例:
menu.Attach(LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(<Menubar ID>)));
在其他情况下,您需要将模块名称传递给函数。
顺便说一下,加载菜单的更简单方法是:
CMenu menu;
menu.LoadMenu(MAKEINTRESOURCE(<ID>));
以下是atluser.h中的实现方式:
BOOL LoadMenu(ATL::_U_STRINGorID menu)
{
ATLASSERT(m_hMenu == NULL);
m_hMenu = ::LoadMenu(ModuleHelper::GetResourceInstance(), menu.m_lpstr);
return (m_hMenu != NULL) ? TRUE : FALSE;
}
因此,您可以使用ModuleHelper
而不是_Module
。它来自atlapp.h:
inline HINSTANCE GetResourceInstance()
{
#if (_ATL_VER >= 0x0700)
return ATL::_AtlBaseModule.GetResourceInstance();
#else // !(_ATL_VER >= 0x0700)
return ATL::_pModule->GetResourceInstance();
#endif // !(_ATL_VER >= 0x0700)
}
ATL::_AtlBaseModule.GetResourceInstance
函数返回编译ATL的模块的句柄(如果我没记错的话)。