middlel
asked on
Setting up a pop-up menu
Hi,
At the moment, I have created my pop-up menu like so:
BOOL bSuccess;
HMENU hMenu = CreatePopupMenu();
bSuccess = AppendMenu( hMenu, MF_STRING, 1, "&Colours" );
bSuccess = AppendMenu( hMenu, MF_STRING, 2, "&Highlight" );
UINT iMenu = TrackPopupMenu( hMenu, TPM_RIGHTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON, point.x, point.y, 0, m_xList.GetParent(), NULL );
I would prefer to define a menu resource instead, but I am not sure how to reference that instead. I have looked at the method LoadMenu() but I can't get hold of the hInstance to the application.
Are there any other ways to do this..
TIA
Emma
At the moment, I have created my pop-up menu like so:
BOOL bSuccess;
HMENU hMenu = CreatePopupMenu();
bSuccess = AppendMenu( hMenu, MF_STRING, 1, "&Colours" );
bSuccess = AppendMenu( hMenu, MF_STRING, 2, "&Highlight" );
UINT iMenu = TrackPopupMenu( hMenu, TPM_RIGHTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON, point.x, point.y, 0, m_xList.GetParent(), NULL );
I would prefer to define a menu resource instead, but I am not sure how to reference that instead. I have looked at the method LoadMenu() but I can't get hold of the hInstance to the application.
Are there any other ways to do this..
TIA
Emma
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hmm.. that is what I thought.. Unfortunately my application is an ATL dll and the only WinMain() I have is in in the little Win32 exe that launches the dll. I can't rely on that hInstance because my dll may have a VB container next time and then I would not be able to get the hInstance.
regards,
Emma
regards,
Emma
If it's an dll there should be a DllMain which get's the instance handle for the dll passed as argument...
if it is an ATL DLL then you can use
_Module.GetResourceInstanc e()
_Module.GetResourceInstanc
ASKER
thanks a lot...
Emma
Emma
to use LoadMenu you need the instance handle of the module from which you want to load the menu. The instance handle is passed to the WinMain function of your application.
hint: to create a popup menu from resource you'll have to create an empty (dummy-)menu including your popup menu as 'child' menu and load it like this:
HMENU hMenu = LoadMenu( hInstance, ID_MY_DUMMY_MENU );
HMENU hPopupMenu = GetSubMenu( hMenu, 0 );
TrackPopupMenu( hPopupMenu, ... );
hope that helps,
ZOPPO