Article View: borland.public.cppbuilder.nativeapi
Article #94System Tray Balloon Tips displaying incorrect icons.
From: Mike Collins
Date: Tue, 24 Jun 2008 17:55
Date: Tue, 24 Jun 2008 17:55
112 lines
4781 bytes
4781 bytes
Hi all,
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
Technical Details
Message-ID:
<4861244e@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ef219a66c8f2d044 X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost> Newsgroups: borland.public.cppbuilder.nativeapi Subject: System Tray Balloon Tips displaying incorrect icons. Date: Tue, 24 Jun 2008 17:55:33 -0000 Lines: 118 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.3959 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133 NNTP-Posting-Host: 89.241.70.243 Message-ID: <4861244e@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1214325838 89.241.70.243 (24 Jun 2008 09:43:58 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail