-
July 16th, 2013, 11:08 PM
#1
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
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
-
July 17th, 2013, 02:54 AM
#2
Re: Popup menus SubMenus overlapping
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:
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?
Victor Nijegorodov
-
July 17th, 2013, 07:12 AM
#3
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?
-
July 17th, 2013, 07:25 AM
#4
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.
Victor Nijegorodov
-
July 17th, 2013, 07:34 AM
#5
Re: Popup menus SubMenus overlapping
Would either of them be the reason the windows are overlapping
-
July 17th, 2013, 07:36 AM
#6
Re: Popup menus SubMenus overlapping
I don't know because I never used menu items of the type MF_STRING with the NULL-id!
Victor Nijegorodov
-
July 17th, 2013, 07:54 AM
#7
Re: Popup menus SubMenus overlapping
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 25th, 2013, 03:36 PM
#8
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|