1 Attachment(s)
Popup menus SubMenus overlapping
I am writing a program in c++ with the Win32 API I created a popup menu with multiple submenus the submenus open up fine but when I open one and go to another they just overlap each other
Heres a screenshot and my code
Attachment 31599
Code:
case WM_RBUTTONDOWN:
{
HMENU hPopupMenu = CreatePopupMenu();
HMENU hSubMenu = CreatePopupMenu();
HMENU hLetterMenu = CreatePopupMenu();
HMENU hNumberMenu = CreatePopupMenu();
HMENU hBrowserMenu = CreatePopupMenu();
HMENU hToggleMenu = CreatePopupMenu();
HMENU hFunctionMenu = CreatePopupMenu();
HMENU hMediaMenu = CreatePopupMenu();
HMENU hComboMenu = CreatePopupMenu();
HMENU hMouseMenu = CreatePopupMenu();
AppendMenu(hPopupMenu, MF_STRING | MF_POPUP, UINT_PTR(hLetterMenu), L"Letter Keys");
AppendMenu(hPopupMenu, MF_STRING |MF_POPUP, UINT_PTR(hNumberMenu), L"Number Keys");
AppendMenu(hPopupMenu, MF_STRING | MF_POPUP, UINT_PTR(hToggleMenu), L"Toggle Keys");
AppendMenu(hPopupMenu, MF_STRING | MF_POPUP, UINT_PTR(hMediaMenu), L"Media Keys");
AppendMenu(hPopupMenu, MF_STRING | MF_POPUP, UINT_PTR(hFunctionMenu), L"Function Keys");
AppendMenu(hPopupMenu, MF_STRING | MF_POPUP, UINT_PTR(hComboMenu), L"Combo Keys");
AppendMenu(hPopupMenu, MF_STRING | MF_POPUP, UINT_PTR(hMouseMenu), L"Mouse Buttons");
for(int j = 0; j < 26; ++j)
{
AppendMenu(hLetterMenu, MF_STRING , 0,letterarray[j]);
}
for(int j = 0; j < 10; ++j)
{
AppendMenu(hNumberMenu, MF_STRING, 0,numberArray[j]);
}
for(int j = 0; j < 8; ++j)
{
AppendMenu(hMediaMenu, MF_STRING, 0, mediaArray[j]);
}
for(int j = 0; j < 5; ++j)
{
AppendMenu(hMouseMenu, MF_STRING, 0, mouseArray[j]);
}
for(int j = 0; j < 12; ++j)
{
AppendMenu(hFunctionMenu, MF_STRING, 0, functionArray[j]);
}
for(int j = 0; j < 3; ++j)
{
AppendMenu(hToggleMenu, MF_STRING, 0, toggleArray[j]);
}
SetForegroundWindow(ghMainWnd);
GetCursorPos(&mouseposition);
TrackPopupMenu(hPopupMenu, TPM_TOPALIGN | TPM_LEFTALIGN , mouseposition.x, mouseposition.y, 0, hWnd, NULL);
return 0;
}
the arrays are LPCWSTR arrays containing the strings to be drawn
Re: Popup menus SubMenus overlapping
Quote:
Originally Posted by
william3711
Code:
case WM_RBUTTONDOWN:
{
HMENU hPopupMenu = CreatePopupMenu();
...
AppendMenu(hPopupMenu, MF_STRING | MF_POPUP, UINT_PTR(hLetterMenu), L"Letter Keys");
...
for(int j = 0; j < 26; ++j)
{
AppendMenu(hLetterMenu, MF_STRING , 0, letterarray[j]);
}
for(int j = 0; j < 10; ++j)
{
AppendMenu(hNumberMenu, MF_STRING, 0, numberArray[j]);
}
...
SetForegroundWindow(ghMainWnd);
GetCursorPos(&mouseposition);
TrackPopupMenu(hPopupMenu, TPM_TOPALIGN | TPM_LEFTALIGN , mouseposition.x, mouseposition.y, 0, hWnd, NULL);
return 0;
}
The third parameter of AppendMenu is:
Quote:
uIDNewItem
[in] Specifies either the identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, a handle to the drop-down menu or submenu.
Why it it zero for all menu items? :confused:
Re: Popup menus SubMenus overlapping
They are all set to zero because I haven't gotten around to that yet I just learned how to create popup menus and submenus and I was testing out how it worked and I noticed the submenus overlapping on another and I went looking for an answer but couldn't find any. But oddly enough it is working fine now and I don't know why. If you don't mind me asking how is them being set to zero relevant to the question I asked?
Re: Popup menus SubMenus overlapping
You cannot handle these menu items because:
a) zero (or NULL) id is reserved for separator
b) all menu items have the same id.
Re: Popup menus SubMenus overlapping
Would either of them be the reason the windows are overlapping
Re: Popup menus SubMenus overlapping
I don't know because I never used menu items of the type MF_STRING with the NULL-id!
Re: Popup menus SubMenus overlapping
Quote:
Originally Posted by
william3711
Would either of them be the reason the windows are overlapping
Why don't you just try changing the identifier of the new menu items so that they are all unique and see what happens. Looking things up in documentation (eg MSDN) and trying things out are part of the learning process.
Re: Popup menus SubMenus overlapping
I did change all the identifiers and I have the same problem but only when the menu is over the controller sprite oddly enough.