Popup menus SubMenus overlapping
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Popup menus SubMenus overlapping

  1. #1
    Join Date
    Jun 2013
    Posts
    20

    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

    Name:  examplepic.png
Views: 303
Size:  28.0 KB


    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,604

    Re: Popup menus SubMenus overlapping

    Quote Originally Posted by william3711 View Post
    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

  3. #3
    Join Date
    Jun 2013
    Posts
    20

    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?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,604

    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

  5. #5
    Join Date
    Jun 2013
    Posts
    20

    Re: Popup menus SubMenus overlapping

    Would either of them be the reason the windows are overlapping

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,604

    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

  7. #7
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,844

    Re: Popup menus SubMenus overlapping

    Quote Originally Posted by william3711 View Post
    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #8
    Join Date
    Jun 2013
    Posts
    20

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center