problems with Shell_NotifyIcon
- From: "Andrew Smith" <someone@xxxxxxxxxxx>
- Date: Thu, 20 Oct 2005 14:56:48 +1000
Hi guys,
I'm an absolute novice when it comes to using Windows API calls, but thought
I'd have a go at writing a command line application that allows a user to
specify a piece of text which will be shown as a balloon hint in the system
tray. After some research, I found the Shell_NotifyIcon command and I've
had some limited success. I've run into the following problems:
(Running VS6, with the Feb 2003 platform SDK installed)
1. Once my icon has been added to the tray, it disappears whenever a user
moves the mouse over the top of the icon. This seems like strange behaviour
and I'd rather it remain regardless of mouse movements.
2. NOTIFYICONDATA->uTimeout seems to be completely ignored. According to
the msdn, the system enforces a min/max timeout of 10/30 seconds. It
doesn't seem to matter what I specify - the balloon stays up until the user
dismisses it. At the moment I've got a very dodgy Sleep() in place as a
work-around.
3. I'd like to get a callback from the tray when a user has dismissed the
balloon. I've looked at some example code, and it seems that I need to
create a window to receive notification messages. Can I do that from a
console application? If not, can I make a win32 app that has an invisible
window and still interacts with the command line?
Here's the extremely simplistic code that I have so far:
#define _WIN32_IE 0x0501
#include "shellapi.h"
#include "winuser.h"
int main (int argc, char* argv[])
{
NOTIFYICONDATA data;
ZeroMemory(&data,sizeof(data));
data.cbSize = sizeof(NOTIFYICONDATA);
data.uCallbackMessage = 0;
//Title
strncpy(data.szInfoTitle, "title", sizeof(data.szInfoTitle));
//Message
strncpy(data.szInfo, "message", sizeof(data.szInfo));
//Timeout
data.uTimeout = 15000;
data.uVersion = NOTIFYICON_VERSION;
data.dwInfoFlags = NIIF_INFO;
//Load the icon
HICON icon = (HICON)LoadImage( NULL,
MAKEINTRESOURCE(32514),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_SHARED);
data.hIcon = icon;
//Unique identifier
data.uID = 1;
//Use the icon and use balloon functionality
data.uFlags = NIF_ICON | NIF_INFO;
//Add the icon to the tray and show message
bool blnReturn = Shell_NotifyIcon(NIM_ADD, &data);
//Sleep for x milliseconds
Sleep(10000);
if (icon)
{
DestroyIcon(icon);
}
//Delete the tray icon
Shell_NotifyIcon(NIM_DELETE, &data);
return 0;
}
Any suggestions would be most appreciated.
Cheers,
Andrew
.
- Follow-Ups:
- Re: problems with Shell_NotifyIcon
- From: Gary Chanson
- Re: problems with Shell_NotifyIcon
- Prev by Date: Re: Special case where GetWindowText fails under XP
- Next by Date: Re: problems with Shell_NotifyIcon
- Previous by thread: RE: Skins
- Next by thread: Re: problems with Shell_NotifyIcon
- Index(es):
Relevant Pages
|