473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tray icon's menu

Looking for a good example of how to show a popup menu in response to the user right-clicking on the icon in the 'taskbar notification area' (tray). I'm fine with creating the icon and responding to its messages. It's the showing of the popup menu I can't do
I've tried it using TrackPopupMenu function, but it returns 0 and GetLastError when called immediately after it returns zero aswell. The menu passed to TrackPopupMenu was got from GetSubMenu(hMenuMain, 0) (where hMenuMain was got by calling LoadMenu(hInst, IDR_MENU), and IDR_MENU is the only menu resource in the application, and it has only got one 'sub' menu )

Can anyone lend any assistance

Thank

Nov 17 '05 #1
2 3559
Here is a sample for your reference

CTest::OnIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
switch (lParam)
{
case WM_RBUTTONDOWN:
HMODULE mod = GetModuleHandle(NULL);

POINT point;
GetCursorPos(&point);

HMENU menu = LoadMenu(mod, MAKEINTRESOURCE(IDR_MENU1));
HMENU hmenuTrackPopup = GetSubMenu(menu, 0);
SetForegroundWindow(m_hWnd);
TrackPopupMenu(hmenuTrackPopup, 0, point.x, point.y, 0, m_hWnd, 0);
PostMessage(WM_NULL, 0, 0);
DestroyMenu(menu);
}

return 0;
};
"Bonj" <an*******@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
Looking for a good example of how to show a popup menu in response to the user right-clicking on the icon in the 'taskbar notification area' (tray).
I'm fine with creating the icon and responding to its messages. It's the
showing of the popup menu I can't do! I've tried it using TrackPopupMenu function, but it returns 0 and GetLastError when called immediately after it returns zero aswell. The menu
passed to TrackPopupMenu was got from GetSubMenu(hMenuMain, 0) (where
hMenuMain was got by calling LoadMenu(hInst, IDR_MENU), and IDR_MENU is the
only menu resource in the application, and it has only got one 'sub' menu ))
Can anyone lend any assistance?

Thanks

Nov 17 '05 #2
Right, that's great cheers.
It's the setforegroundwindow I was forgetting, would omitting that cause the
menu not to display at all?

Also what's the null message for?
"Leo Lin" <le*****@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Here is a sample for your reference

CTest::OnIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
switch (lParam)
{
case WM_RBUTTONDOWN:
HMODULE mod = GetModuleHandle(NULL);

POINT point;
GetCursorPos(&point);

HMENU menu = LoadMenu(mod, MAKEINTRESOURCE(IDR_MENU1));
HMENU hmenuTrackPopup = GetSubMenu(menu, 0);
SetForegroundWindow(m_hWnd);
TrackPopupMenu(hmenuTrackPopup, 0, point.x, point.y, 0, m_hWnd, 0);
PostMessage(WM_NULL, 0, 0);
DestroyMenu(menu);
}

return 0;
};
"Bonj" <an*******@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
Looking for a good example of how to show a popup menu in response to the
user right-clicking on the icon in the 'taskbar notification area' (tray).
I'm fine with creating the icon and responding to its messages. It's the
showing of the popup menu I can't do!
I've tried it using TrackPopupMenu function, but it returns 0 and GetLastError when called immediately after it returns zero aswell. The

menu passed to TrackPopupMenu was got from GetSubMenu(hMenuMain, 0) (where
hMenuMain was got by calling LoadMenu(hInst, IDR_MENU), and IDR_MENU is the only menu resource in the application, and it has only got one 'sub'

menu ))
Can anyone lend any assistance?

Thanks


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James | last post by:
Is there a way to Owner drawn tray context menu ? - I know that there is a bug with the custom drawing of a context menu assigned to a tray icon - but I was hoping someone could advise me as to how...
7
by: Danielb | last post by:
I want my application to run most of the time as just an notify icon visible in the system tray, with some dialogs windows that open if the user selects an option from the context menu on the tray...
4
by: utkarsh | last post by:
Hi, I want to develop a Window Service in C# that should be capable of sisplaying the a icon in the window tray. Based on some logic in service, icon should be changed to some other...
10
by: One Handed Man [ OHM ] | last post by:
If this is duplicated, I'm sorry because I cant find the original post I made today Anyway . . Now its my turn to ask a question I want to develop an app which will run in the system tray....
8
by: george d lake | last post by:
Hi, I have an app that runs in the system tray. When I exit the app (from a button on a form) the app ends but the icon stays in the tray. Any ideas? here is the code I use to end the app ...
5
by: Casper | last post by:
I'm trying to get my program to run in the system tray. I've looked at dozend of tutorials on the web and on newsgroups but I just dont get it! Has anyone got any links or example code that ...
5
by: Robert Smith | last post by:
Hello, I have often seen system tray icons that you click on and a popup menu appears. Is it possible to do this in Visual basic.net or are there any controls that allow this to be achieved. ...
1
by: Janiv Ratson | last post by:
Hello, I have an MFC MDI application and a Windows Forms (2.0) Tray Icon application. I want to run a command on the tray application via my MFC application. There is a "Register" context menu...
4
by: ewokspy | last post by:
I have a system tray icon with a context menu set to appear on right-click. On a right click the menu appears fine and I can select an option. The problem is that the event doesn't fire immediately....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.