Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The Below code is to create an popup menu on system tray Icon
C++
VOID DisplayMenu(HWND hWnd)
{
	HMENU hMenu ;
	POINT pCursor;
	hMenu = LoadMenu(hInst,MAKEINTRESOURCE(IDC_GETSCREEN));
	GetCursorPos(&pCursor);
	TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_NOANIMATION, pCursor.x, pCursor.y, 0, hWnd, NULL);
}


this function is being called on click on the system tray menu

IDC_GETSCREEN is a menu resource ID the lay out is given below:
________ __________
|File | | Help |
-------- ----------
|Exit | |About |
--------- ------------

As you see this is the primary menu that is created with new project of Visual C++.

Now My problem is
1. When when I click on the icon on the system tray it create the menu. but the text File and Help is not visible. Even though I can browse through the menu.
2. When I Click on something else the menu does not disappear.

Can anyone point me out my missing points

Thanks in advance

[Edit]I took care of problem 2
with below function:

C++
VOID DisplayMenu(HWND hWnd)
{
	HMENU hMenu ;
	POINT pCursor;
	hMenu = LoadMenu(hInst,MAKEINTRESOURCE(IDC_GETSCREEN));
	GetCursorPos(&pCursor);
	SetForegroundWindow(hWnd);
	TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_NOANIMATION, pCursor.x, pCursor.y, 0, hWnd, NULL);
	PostMessage(hWnd, WM_NULL, 0, 0);
}


[/Edit]
Posted
Updated 22-Feb-12 22:04pm
v2

1 solution

You need a second level of menu (a submenu) in a popup; and no I have no idea why. Take a look at this section[^] of one of my articles, for the code to do it.
 
Share this answer
 
Comments
Mohibur Rashid 23-Feb-12 19:58pm    
Thanks for answering

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900