Newbie Needs Shell_NotifyIcon Help

Newbie Needs Shell_NotifyIcon Help

Post by John Bowma » Wed, 14 Jun 2000 04:00:00



Hello,

I'm new to programming the Windows shell.  I'm trying to simply get my
dialog based application to display an icon in the system tray.
Unfortunately, all it ever does it create the empty space for the icon and
the icon never gets displayed.

Below is my code that as best as I can tell from the info (MSDN Library)
I've unearthed so far should work.  Can someone with experience explain what
I need to do, to do this correctly?  I must be missing something, and can't
figure out what it is.

 CVerseMemorizerDlg *pThis;
 pThis = this;

 HWND HThis = pThis->GetSafeHwnd();
 HICON HThisIcon;

 TCHAR szToolTip[64] = "My Tool Tip\0";
 HThisIcon = pThis->GetIcon(FALSE);

 NOTIFYICONDATA pTrayIcon;

 pTrayIcon.cbSize = sizeof(NOTIFYICONDATA);
 pTrayIcon.hWnd = HThis;
 pTrayIcon.uID = NULL;
 pTrayIcon.uFlags = NIF_ICON || NIF_TIP || NIF_MESSAGE;
 pTrayIcon.uCallbackMessage = NULL;
 pTrayIcon.hIcon = HThisIcon;

    if (szToolTip)
        lstrcpyn(pTrayIcon.szTip, szToolTip, sizeof(pTrayIcon.szTip));
    else
        pTrayIcon.szTip[0] = '\0';

 Shell_NotifyIcon(NIM_ADD, &pTrayIcon);

TIA,
--
John Bowman
Verona, WI

 
 
 

Newbie Needs Shell_NotifyIcon Help

Post by John Bowma » Wed, 14 Jun 2000 04:00:00


Damit,

Thanks for the response.  Your help was immense.  It is now working.

Quote:> uID
> Application-defined identifier of the taskbar icon. The shell uses hWnd
and
> uID to identify which icon is to be operated on when Shell_NotifyIcon is
> invoked. You can have multiple icons associated with a single hWnd by
> assigning each a diffent uID.

I guess I still don't understand what this means.  I read this in the docs
but it still doesn't tell me where/what value this represents.  Is it the
index of the icon in the EXE?  In my case there is only the one.

Quote:> :  pTrayIcon.uFlags = NIF_ICON || NIF_TIP || NIF_MESSAGE;

>I think you meant to use | here, not ||, unless this is a typo...

Oops! Standard newbie mistake.   This was the key to getting it to work.
Thanks for spotting it.

Quote:> :  pTrayIcon.uCallbackMessage = NULL;

> If uCallbackMessage is NULL, exactly how is the shell going to notify you?

NIY - I will add this after I get the icon to appear and disappear
correctly.

Thanks again for your help & education.  I'll keep slogging along.

--
John Bowman
Verona, WI

 
 
 

Newbie Needs Shell_NotifyIcon Help

Post by Damit Senanayak » Thu, 15 Jun 2000 04:00:00



: I'm new to programming the Windows shell.  I'm trying to simply get my
: dialog based application to display an icon in the system tray.
: Unfortunately, all it ever does it create the empty space for the icon and
: the icon never gets displayed.

Your code looks OK, except for the following (some may not be relevant
though they caught my eye):

:  pTrayIcon.uID = NULL;

uID shouldn't be NULL, although it's not stated in the docs:

uID
Application-defined identifier of the taskbar icon. The shell uses hWnd and
uID to identify which icon is to be operated on when Shell_NotifyIcon is
invoked. You can have multiple icons associated with a single hWnd by
assigning each a diffent uID.
<<

:  pTrayIcon.uFlags = NIF_ICON || NIF_TIP || NIF_MESSAGE;

I think you meant to use | here, not ||, unless this is a typo...

:  pTrayIcon.uCallbackMessage = NULL;

If uCallbackMessage is NULL, exactly how is the shell going to notify you?

uCallbackMessage
Application-defined message identifier. The system uses this identifier to
send notifications to the window identified in hWnd. These notifications are
sent when a mouse or event occurs in the bounding rectangle of the icon or
the icon is selected or activated with the keyboard. The wParam parameter of
the message contains the identifier of the taskbar icon in which the event
occurred. The lParam parameter holds the mouse or keyboard message
associated with the event. For example, when the mouse cursor moves over a
taskbar icon, lParam is set to WM_MOUSEMOVE. See the Taskbar guide chapter
for further discussion.
<<

-- also --
(Taskbar chapter)
Receiving status area callback messages
Applications commonly put icons in the status area of the taskbar to serve
as status indicators. You can provide additional information when the user
performs mouse actions, such as moving the mouse pointer over the icon or
clicking the icon.

The system notifies you of mouse and keyboard events by sending an
application-defined callback message that is associated with a particular
icon. In this way, the system can notify an application when the user, for
instance, clicks the icon or selects it by pressing a key.

You define an icon's callback message when you add the icon to the taskbar.
The callback message identifier is specified in the uCallbackMessage member
of the NOTIFYICONDATA structure passed with NIM_ADD. When an event occurs,
the system sends the callback message to the window procedure of the window
specified by the hWnd member. The wParam parameter of the message contains
the identifier of the taskbar icon in which the event occurred. The lParam
parameter holds the mouse or keyboard message associated with the event. For
example, when the mouse pointer moves onto a taskbar icon, lParam contains
WM_MOUSEMOVE.

The results of various mouse events can be summarized as follows:

  a.. When the user moves the mouse pointer over the icon, the system
displays the tooltip text that was specified in NOTIFYICONDATA.
  b.. When the user clicks the icon, your application receives a
WM_LBUTTONDOWN notification.
  c.. When the user right-clicks the icon, your application receives a
WM_RBUTTONDOWN notification.
  d.. When the user double-clicks the icon, your application receives a
WM_LBUTTONDBLCLK notification.
Typically, clicking the icon causes the application to display a window with
additional information, right-clicking displays a shortcut menu, and
double-clicking executes the default shortcut menu command.

For an example of how to change the tooltip text associated with a status
area icon, see Balloon Tooltips for Status Bar Icons.

Versions 5.0 and later of the shell handle Shell_NotifyIcon mouse and
keyboard events differently than earlier shell versions, found on Windows NT
4.0, Windows 95, and Windows 98. The differences are:

  a.. If a user requests a notify icon's context menu with the keyboard, the
version 5.0 shell sends the associated application a WM_CONTEXTMENU message.
Earlier versions send WM_RBUTTONDOWN and WM_RBUTTONUP messages.
  b.. If a user selects a notify icon with the keyboard and activates it
with the space bar or ENTER key, the version 5.0 shell sends the associated
application an NIN_KEYSELECT notification. Earlier versions send
WM_RBUTTONDOWN and WM_RBUTTONUP messages.
  c.. If a user selects a notify icon with the mouse and activates it with
the ENTER key, the version 5.0 shell sends the associated application an
NIN_SELECT notification. Earlier versions send WM_RBUTTONDOWN and
WM_RBUTTONUP messages.
You can select which way the shell should behave by calling Shell_NotifyIcon
with dwMessage set to NIM_SETVERSION. Set the uVersion member of the
NOTIFYICONDATA structure to indicate whether you want version 5.0 or
pre-version 5.0 behavior.
<<
--

Please reply to newsgroups, not by e-mail. | ICQ: 6930718

 
 
 

Newbie Needs Shell_NotifyIcon Help

Post by Damit Senanayak » Thu, 15 Jun 2000 04:00:00



: Thanks for the response.  Your help was immense.  It is now working.

Well, good to know that...

: I guess I still don't understand what this means.  I read this in the docs
: but it still doesn't tell me where/what value this represents.  Is it the
: index of the icon in the EXE?  In my case there is only the one.

From my reading of the docs, it appears that uID can be whatever you want it
to be, so you might want to choose some (meaningful) value.

[ || instead of | ]

: Oops! Standard newbie mistake.   This was the key to getting it to work.
: Thanks for spotting it.

Don't worry, I've been bitten by that too before!

: NIY - I will add this after I get the icon to appear and disappear
: correctly.

OK, but you might want to consider it so that it does something useful. :-)
Also, you might want to consider using a custom message (e.g. WM_APP + 200)
so that it doesn't conflict with a standard (or MFC) message.

Also, your icon should hang around for the duration that your systray item
is there.

: Thanks again for your help & education.  I'll keep slogging along.

I think that there are several MFC systray classes around, but I can't
remember their URLs right now... maybe CodeGuru
(http://codeguru.earthweb.com) has some?
--

Please reply to newsgroups, not by e-mail. | ICQ: 6930718

 
 
 

Newbie Needs Shell_NotifyIcon Help

Post by Richard S. Vidi » Thu, 15 Jun 2000 04:00:00


The uID parameter permits an application to manage multiple icons in the
system tray (without having to designate unique windows to receive mouse
events for each of them).  When the shell forwards mouse events to your
application, the wParam portion of the message contains the uID of the icon
the event is associated with.  As for whether a given uID can be NULL (zero)
or not, I'm not sure (I've always used 1, 2, ... etc. as needed), but I'd be
surprised if 0 didn't work.




> : Thanks for the response.  Your help was immense.  It is now working.

> Well, good to know that...

> : I guess I still don't understand what this means.  I read this in the
docs
> : but it still doesn't tell me where/what value this represents.  Is it
the
> : index of the icon in the EXE?  In my case there is only the one.

> From my reading of the docs, it appears that uID can be whatever you want
it
> to be, so you might want to choose some (meaningful) value.

> [ || instead of | ]

> : Oops! Standard newbie mistake.   This was the key to getting it to work.
> : Thanks for spotting it.

> Don't worry, I've been bitten by that too before!

> : NIY - I will add this after I get the icon to appear and disappear
> : correctly.

> OK, but you might want to consider it so that it does something useful.
:-)
> Also, you might want to consider using a custom message (e.g. WM_APP +
200)
> so that it doesn't conflict with a standard (or MFC) message.

> Also, your icon should hang around for the duration that your systray item
> is there.

> : Thanks again for your help & education.  I'll keep slogging along.

> I think that there are several MFC systray classes around, but I can't
> remember their URLs right now... maybe CodeGuru
> (http://codeguru.earthweb.com) has some?
> --

> Please reply to newsgroups, not by e-mail. | ICQ: 6930718

 
 
 

Newbie Needs Shell_NotifyIcon Help

Post by Valery Kriga » Fri, 14 Jul 2000 04:00:00


"John Bowman" wrote

Quote:> I'm new to programming the Windows shell.  I'm trying to simply get my
> dialog based application to display an icon in the system tray.
> Unfortunately, all it ever does it create the empty space for the icon and
> the icon never gets displayed.

> Below is my code that as best as I can tell from the info (MSDN Library)
> I've unearthed so far should work.  Can someone with experience explain
what
> I need to do, to do this correctly?  I must be missing something, and
can't
> figure out what it is.

 You can use this small progaram as an example. it puts an icon and start
xxx.exe
on left doubleclick. and it removes itself on right doubleckick
It was 1.260 bytes in size when I tested it :)

#include "stdafx.h"

#define WM_ICON_NOTIFY  (WM_USER+10)
#define ICON_ID         17
#define ICON_NUM        0
#define EXEC_NAME       "xxx.exe"
#define TOOLTIP_TEXT    "xxx launcher"

LRESULT CALLBACK
WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{   if( lParam==WM_LBUTTONDBLCLK ) // && uMsg==WM_ICON_NOTIFY
        WinExec(EXEC_NAME, SW_SHOWNORMAL);
    if( lParam==WM_RBUTTONDBLCLK )
        PostQuitMessage(0);
    return  DefWindowProc(hwnd, uMsg, wParam, lParam);

Quote:}

int APIENTRY
WinMainCRTStartup(void)
{ WNDCLASS      wnd_class= {NULL, WindowProc, 0,0, GetModuleHandle(NULL),
NULL,
                            NULL, NULL, NULL, TOOLTIP_TEXT};
  MSG               msg;
  NOTIFYICONDATA    nid= {sizeof(NOTIFYICONDATA), NULL,ICON_ID,
NIF_ICON|NIF_MESSAGE|NIF_TIP,
                            WM_ICON_NOTIFY, NULL,TOOLTIP_TEXT};

    RegisterClass(&wnd_class);
    nid.hWnd= CreateWindow(TOOLTIP_TEXT, TOOLTIP_TEXT, NULL,
          0,0, 0,0, NULL, NULL, wnd_class.hInstance, 0);
    if( nid.hIcon= ExtractIcon(wnd_class.hInstance, EXEC_NAME, ICON_NUM) )
    {   Shell_NotifyIcon(NIM_ADD, &nid);

        while( GetMessage(&msg,NULL,0,0) )
        {   //TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
     Shell_NotifyIcon(NIM_DELETE, &nid);
    }
    return 0;

Quote:}

 
 
 

1. Newbie Needs Help w/ NotifyIconData and Shell_NotifyIcon

Hello,

I'm trying to use the NotifyIconData structure and the Shell_NotifyIcon
function to modify an icon I've placed in the system tray for my simple app.
The app correctly places/deletes and responds to clicks on the icon it
places in the system tray when the program starts. Basically, all I want to
be able to to do is to change the icon to a disabled form of the icon and
back again when the app is disabled and re-enabled (much like a virus
scanner program typically does).  It would appear from the sparse
documentation that I need to use the NIM_MODIFY value when I call
Shell_NotifyIcon.  OK, but how do I set the correct hWnd and uID for the new
icon (in NotifyIconData structure) when needed, and then the original icon
when needed?  The documentation says:

uID  "Application-defined identifier of the taskbar icon. The shell uses
hWnd and uID to identify which icon is to be operated on when
Shell_NotifyIcon is invoked. You can have multiple icons associated with a
single hWnd by assigning each a diffent uID."

How specifically do I do that?  Currently, the original icon of the window
is specified in the structure and uID is NULL when the original icon is
added/deleted.

Any help would be much appreciated. TIA,

--
John Bowman
Verona, WI

2. NM3.0 with N serverT

3. Help with Shell_NotifyIcon

4. 16-bit windows internet programming opportunity. Respond ASAP.

5. Newbie needs help with DTP a book.....HELP!

6. 3 domains

7. Newbie Mistake: Re Needed FAQ for Newbie

8. XPath in VBA

9. Total Newbie with Minolta DualScan II Needs Help Please

10. Newbie Needs Help Choosing Scanner

11. Newbie to OS 10.2 needs Vuescan help w Canon 656U

12. Newbie; Need help deciding between scanning options

13. newbie needs help with cable