VC++ program with NOTIFYICONDATA cannot compile

Hi experts,

I have a program that displays an icon on the taskbar nitification area but it won't compile after I tried adding in codes for ballon tips. FYI, I am using VC++ 6 with the latest platform SDK installed (and registered with Visual Studio) running on Windows XP Professional SP1 or Windows NT 4.0 SP 6 (depending on whether it's at work or home). The errors displayed is:
error C2065: 'NIF_INFO' : undeclared identifier
error C2039: 'uTimeout' : is not a member of '_NOTIFYICONDATAA'
error C2039: 'szInfoTitle' : is not a member of '_NOTIFYICONDATAA'
error C2039: 'szInfo' : is not a member of '_NOTIFYICONDATAA'

It's as if I'm still using the old version of shellapi.h although when I clicked on the "see declaration of '_NOTIFYICONDATAA'", I can see it defined as:
typedef struct _NOTIFYICONDATAA {
        DWORD cbSize;
        HWND hWnd;
        UINT uID;
        UINT uFlags;
        UINT uCallbackMessage;
        HICON hIcon;
#if (_WIN32_IE < 0x0500)
        CHAR   szTip[64];
        CHAR   szTip[128];
#if (_WIN32_IE >= 0x0500)
        DWORD dwState;
        DWORD dwStateMask;
        CHAR   szInfo[256];
        union {
            UINT  uTimeout;
            UINT  uVersion;
        CHAR   szInfoTitle[64];
        DWORD dwInfoFlags;
#if (_WIN32_IE >= 0x600)
        GUID guidItem;

I have also added #include <shellapi.h> and also included shell32.lib in the project setting's object/library modules. Have also defined #define _WIN32_IE 0x0500.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


> I have also added #include <shellapi.h> and also included shell32.lib in the
> project setting's object/library modules.
> Have also defined #define _WIN32_IE 0x0500.

Is that definition declared BEFORE you include <shellapi.h>?  If not, that's your problem.

If it is, then you ARE using an old version of ShellAPI.h.  To fix that, you need to make sure that your Platform SDK directories are used BEFORE the standard VC++ directories.  Here's how:
     1) In VC++, go to Tools -> Options.
     2) Select "Include Files" under "Show Directories For".
     3) Make sure "\Program Files\Microsoft SDK\include" (for example)
          is higher in the list than "\Program Files\Microsoft Visual Studio\VC98\Include"

NOTE: Your directories may be different depending on where you have installed things.  Basically, you need to get it to use the SDK directory because it has the updated ShellAPI.h that you want, and the old VC98\Include has the old version that is missing those things.

Hope that helps,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
js_chengAuthor Commented:
Hey Dex,

Thanks for commenting. The #define _WIN32_IE 0x0500 is before shellapi.h. I've also checked the include path and it's correct. I have registered it using the options provided by the Platform SDK itself. Like I said when I clicked on the error, it actually opens up the correct header as shown in my question. I just don't understand why VC++ is complaining that those variables are not member of NOTIFYICONDATA. The codes look pretty simple, just that it's not compiling.

Here is a simplified example of what happens in the program:

#include <shellapi.h>

#define _WIN32_IE 0x0500 //assume IE5 for testing


// some variables
char titleText[64] = "Some title";
char balloonText[256] = "Some text";

// shows the icon, this part works and the icon is displayed
//iconData.cbSize = sizeof(NOTIFYICONDATA); // use this normally
icon.cbSize = NOTIFYICONDATA_V2_SIZE; // use this if try to display ballon text
icon.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
icon.hWnd = hWnd;
strcpy(icon.szTip,"Tooltip text");
icon.uCallbackMessage = WM_ICON_NOTIFY;
icon.uID = 9999;
Shell_NotifyIcon(NIM_ADD, &icon);

// try to show balloon, this doesn't compile :-(
icon.uFlags |= NIF_INFO;
icon.uTimeout = 10000;
strcpy(icon.szInfoTitle, titleText);
strcpy(icon.szInfo, balloonText);
Shell_NotifyIcon(NIM_MODIFY, &icon);

Any mistakes here? I'm not using and don't plan on using MFC or any of those newfangled stuff. Just plain old C and C++. Can anyone please help out? Thanks.

> Thanks for commenting. The #define _WIN32_IE 0x0500 is before shellapi.h. I've
> also checked the include path and it's correct.

Okay...  I just gotta check the easy stuff first, right?  :)

Anyways, here is what I want you to try next:
  1) Add _WIN32_IE=0x500 to your PROJECT's preprocessor options.  This ensures it is defined before anything is included.
  2) After that, do a FULL Rebuild of your project.

If it is still giving you grief, then search your computer for all files named "ShellAPI.h".  Rename ALL of them "ShellAPI-old.h" (or whatever) EXCEPT for the one in your "Platform SDK" directory.

Hi Dexstar

>> Add _WIN32_IE=0x500 to your PROJECT's preprocessor options.  This ensures it is defined before anything is included.

Thanks for you valuable comments.

With the same set of code running the application in windows NT does not show the ballon tip
Is there anyway I could show ballon tip in Windows NT?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.