Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system tray menu problem

Status
Not open for further replies.

indigoblue

Programmer
Sep 7, 2000
9
0
0
GB
Hi, im trying to use a popup menu near to the clock - i've got the following to work:
- a) icon displayed in system tray
- b) main callback function receiving mouse messages from the icon
- c) a menu defined in my resource file

however, when i execute the code below, I get what looks like a popup menu, at the correct position (on top of the icon) but it only has the width of a couple of pixels. I can click on the very thin bar & it seems to have the spacers in the correct position, but its quite useless because i cant see any text (im using vs.net btw if that helps...)

code:

case WM_TRAYICON:

traymenu = LoadMenu(NULL,MAKEINTRESOURCE(IDR_OPENMENU));

switch(lParam)
{
case WM_RBUTTONDOWN:

// Display and track the popup menu
#ifdef _WIN32_WCE
DWORD messagepos = GetMessagePos();
point.x = GET_X_LPARAM(messagepos);
point.y = GET_Y_LPARAM(messagepos);

#else
GetCursorPos(&point);
#endif

SetForegroundWindow(hWnd);
TrackPopupMenu(traymenu,TPM_RIGHTBUTTON,point.x,point.y,0,hWnd,NULL);

PostMessage(hWnd, WM_NULL, 0, 0);

DestroyMenu(traymenu);

anyone got any ideas why this is wrong?
 
I made some modification to your code:

case WM_TRAYICON:

traymenu = LoadMenu(NULL,MAKEINTRESOURCE(IDR_OPENMENU));

switch(lParam)
{
case WM_RBUTTONDOWN:

// Display and track the popup menu
#ifdef _WIN32_WCE
DWORD messagepos = GetMessagePos();
point.x = GET_X_LPARAM(messagepos);
point.y = GET_Y_LPARAM(messagepos);

#else
GetCursorPos(&point);
#endif

SetForegroundWindow(hWnd);


HMENU hPopup;
hPopup=GetSubMenu(traymenu,0);


TrackPopupMenu(hPopup,TPM_RIGHTBUTTON,point.x,point.y,0,hWnd,NULL);

PostMessage(hWnd, WM_NULL, 0, 0);

DestroyMenu(hPopup);
DestroyMenu(traymenu);

The reason your code doesn't worked right is that you didn't track the popup of the menu but the menu itself which is a different thing.

Let me know if you still have problems,
Hope this is helpful,s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top