• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1925
  • Last Modified:

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.

  • 2
1 Solution

> 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,
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now