Использование Contex menu в ATL
Для примера вот код без создания ресура:
HMENU hMenu;
hMenu = CreatePopupMenu();
if (NULL == hMenu)
throw L"Can't create popup menu";
MENUITEMINFO mii = {0};
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
mii.fType = MFT_STRING;
mii.fState = MFS_ENABLED;
mii.wID = 1;
mii.dwTypeData = (LPSTR)"Refresh";
if(FALSE == InsertMenuItem(hMenu, 0, TRUE, &mii))
throw L"Can't insert menu item 1";
mii.wID = 2;
mii.dwTypeData = (LPSTR)"Sort...";
if(FALSE == InsertMenuItem(hMenu, 1, TRUE, &mii))
throw L"Can't insert menu item 2";
mii.wID = 3;
mii.dwTypeData = (LPSTR)"Reset";
if(FALSE == InsertMenuItem(hMenu, 2, TRUE, &mii))
throw L"Can't insert menu item 3";
mii.wID = 4;
mii.dwTypeData = (LPSTR)"Filter...";
if(FALSE == InsertMenuItem(hMenu, 3, TRUE, &mii))
throw L"Can't insert menu item 4";
HWND hWnd = ::GetForegroundWindow();
short nX;
short nY;
POINT pnt;
GetCursorPos( &pnt);
nX = (short) pnt.x;
nY = (short) pnt.y;
UINT nID = TrackPopupMenu(
hMenu,
TPM_LEFTALIGN | TPM_RETURNCMD,
nX, nY, 0, hWnd, NULL);
PostMessage(WM_NULL, 0, 0);
if (nID==1) {
MessageBox("1","1",MB_OK);
}
if (nID==2) {
MessageBox("2","2",MB_OK);
}
if (nID==3) {
MessageBox("3","3",MB_OK);
}
if (nID==4) {
MessageBox("4","4",MB_OK);
}
А вот с ресурсом:
HMENU hMenu;
HMENU a1=::LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENUPOPUP));
hMenu=GetSubMenu(a1,0);
//char buff[1000]="";
// sprintf_s(buff,sizeof(buff),"%s",a1);
// MessageBox(buff,"Error",MB_OK);
HWND hWnd = ::GetForegroundWindow();
short nX;
short nY;
POINT pnt;
GetCursorPos( &pnt);
nX = (short) pnt.x;
nY = (short) pnt.y;
UINT nID = TrackPopupMenu(
hMenu,
TPM_LEFTALIGN | TPM_RETURNCMD,
nX, nY, 0, hWnd, NULL);
PostMessage(WM_NULL, 0, 0);
Ошибка в строке
LoadMenu(
Может кто поможет буду очень благодарен!!!!