Jump to content
  • Advertisement
Sign in to follow this  
Bagel Man

TrackPopupMenuEx

This topic is 4859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a weird problem with TrackPopupMenuEx. When I call it, the menu pops up, but it's very narrow and has no text. Submenus pop up like they should, and they do have text. Anyone see what I'm doing wrong?
#include <windows.h>
#include "resource.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND mWnd=0;
HMENU TestMenu=0;

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= 0;
	wcex.lpszClassName	= "MyWinClass";
	wcex.hIconSm		= 0;
	RegisterClassEx(&wcex);

	mWnd = CreateWindow("MyWinClass", "MyWin", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
	if (!mWnd)  return 0;
	ShowWindow(mWnd, nCmdShow);
	UpdateWindow(mWnd);

	TestMenu=LoadMenu(hInstance, (LPCSTR)IDR_TESTMENU);

	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	case WM_CONTEXTMENU:
		TrackPopupMenuEx(TestMenu, 0, LOWORD(lParam), HIWORD(lParam), hWnd, 0);
		return 0;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

Share this post


Link to post
Share on other sites
Advertisement
Menus loaded from resources like that cannod be displayed as popup menus. You should either create and fill the menu dynamically with CreatePopupMenu and AppendMenu, or create the menu as a popup menu in the resources like that


if your menu looks like that
a
b>b1
b2
c

It should look like this
P>a
b>b1
b2
c


then immediately after loading it call
TestPopupMenu = GetSubMenu(TestMenu, 0);
and track and use TestPopupMenu instead.

If you have a lot of popup menus you can insert them all into one big menu and load them appropriately...

Share this post


Link to post
Share on other sites
Have you tried using the MAKEINTRESOURCE macro in the second parameter of LoadMenu?

ie:

HMENU TestMenu=LoadMenu(MAKEINTRESOURCE(IDR_TESTMENU));

Share this post


Link to post
Share on other sites
Quote:
Original post by Bleys
Menus loaded from resources like that cannod be displayed as popup menus.


Sure they can. But he's using the menu wrong...

If you want to use pop-up menus from a resource, you use submenus



// Imagine your menu looks like this in the resource editor:
//
// [SELECT] [MULTI]
//
// The options you put in each of those two "submenus" will be what pops up

hmenu = ::LoadMenu(hinstance,menuId);
hmenuSel = ::GetSubMenu(hmenu,0); // The select menu (as a popup)
hmenuMulti = ::GetSubMenu(hmenu,1); // The multi menu (as a popup)

Share this post


Link to post
Share on other sites
Quote:
Original post by Verg
...
Sure they can. But he's using the menu wrong...

If you want to use pop-up menus from a resource, you use submenus
...


Yeah, excuse my poor English.
Me-sa cannot express self good, do he?...
But isn't that basically what i said

Quote:
Original post by me
blah blah...
...then immediately after loading it call
TestPopupMenu = GetSubMenu(TestMenu, 0);
and track and use TestPopupMenu instead.


Actually what I meant was:
Loading a menu and trying to display it as popup right away won't work, unless it is created and used in the folowing maner: blah blah the same submenu stuff i already posted"




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!