> So, like I said, if I call SetBalloonTip(), with a custom icon
> (not one of the default ones) my system tray icon also changes.
That is because you are changing the tray icon in both calls. You did not
say which OS you are running. NIIF_USER only works on XP SP2 and later.
For XP SP1 and earlier, NIIF_USER has no effect, thus you cannot apply
custom icons. In Vista, use the nid.hBalloonIcon member instead of
nid.hIcon.
> I overcame it my doing this:
>
> SetBalloonTip()
> SetSysTrayIcon()
Only because you are changing the nid.hIcon member in SetBalloonTip(), and
then changing it back in SetSysTrayIcon(). Which would suggest that
NIIF_USER does not work on your system.
Gambit
I'm having two issues with my system tray application. I posted about it
some time ago but didn't get any ideas and didn't chase it up. Background
is that I have a System Tray application that displays Balloon tips to the
user when certain events happen. These notification events are sent to the
system tray application via an IPC channel.
My first issue is (and it may be the cause of my second problem) is that
when I display a balloon tip, with a custom icon, my system tray icon
changes to that of the balloon tip - the two do not seem to change
independently of each other. I overcame this with a hack by forcing the
system tray icon to be changed again, straight after the call to display the
balloon tip but it's not great.
I have several wrapper functions to allow various different changes, these
look like this :
bool TMainForm::SetSysTrayIcon(UINT p_uResId)
{
bool bRtn = false;
if (bTrayIconActive)
{
EnterCriticalSection(&csIPCCallBack);
try
{
HICON hIcon = (HICON)Utils->RtnIcon(p_uResId, 16);
//LR_DEFAULTCOLOR);
nid.hIcon = hIcon;
nid.uFlags = NIF_ICON;
bRtn = (bool)Shell_NotifyIcon(NIM_MODIFY, &nid);
::DestroyIcon(hIcon);
}
__finally
{
LeaveCriticalSection(&csIPCCallBack);
}
}
return bRtn;
}
bool TMainForm::SetBalloonTip(const AnsiString &p_szTitle, const AnsiString
&p_szBody, DWORD p_dwIcon,
UINT p_uTimeout, bool p_bRespondUClick)
{
bool bRtn = false;
if (bTrayIconActive)
{
EnterCriticalSection(&csIPCCallBack);
try
{
HICON hIcon = NULL;
if ((p_dwIcon >= NIIF_NONE) && (p_dwIcon <= NIIF_ERROR))
{
nid.uFlags = NIF_INFO;
nid.dwInfoFlags = p_dwIcon;
}
else
{
nid.uFlags = NIF_INFO | NIF_ICON;
nid.dwInfoFlags = NIIF_USER;
hIcon = (HICON)Utils->RtnIcon(p_dwIcon, 16); //
LR_DEFAULTCOLOR);
nid.hIcon = hIcon;
}
nid.uTimeout = (p_uTimeout * 1000); // convert time to ms
lstrcpyn(nid.szInfoTitle, p_szTitle.c_str(),
MAX_TRAY_BALLOON_TITLE);
lstrcpyn(nid.szInfo, p_szBody.c_str(), MAX_TRAY_BALLOON_BODY);
if (!bRespondToUserClick)
bRespondToUserClick = p_bRespondUClick;
if (bRtn = (bool)Shell_NotifyIcon(NIM_MODIFY, &nid))
{
lstrcpyn(nid.szInfoTitle, "\0", MAX_TRAY_BALLOON_TITLE);
lstrcpyn(nid.szInfo, "\0", MAX_TRAY_BALLOON_BODY);
}
if (hIcon)
::DestroyIcon(hIcon);
}
__finally
{
LeaveCriticalSection(&csIPCCallBack);
}
}
return bRtn;
}
So, like I said, if I call SetBalloonTip(), with a custom icon (not one of
the default ones) my system tray icon also changes. I overcame it my doing
this:
SetBalloonTip()
SetSysTrayIcon()
- which forces the original system tray icon to be re-displayed - the
flicker isn't noticeable but I don't like it.
My second problem may be related to the first. My system tray applicationis
forced to run when a user logs on using the HKLM Run registry key. When my
System Tray first runs, it displays a balloon tip to instruct the user
that it is running correctly. however, when the user logs on, the balloon
tip that is displayed, shows the icon of the last balloon that was
displayed. I've posted a screen shot to show what I mean to
borland.public.attachments. In this case, my balloon tip is showing that of
the Windows Security Alerts balloon tip
Hope this all makes sense, any help would be excellent.
Mike C
The screen shots that you can see is taken from Windows XP service Pack 2 -
should work based on this...
I would assum that is NIIF_USER was not supported, I wouldn't be able to
change the icon at all, which i can.
Any other ideas?
Mike
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:4861...@newsgroups.borland.com...
>