Solved

VC++ program with NOTIFYICONDATA cannot compile

Posted on 2003-10-29
4
1,741 Views
Last Modified: 2012-06-27
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];
#else
        CHAR   szTip[128];
#endif
#if (_WIN32_IE >= 0x0500)
        DWORD dwState;
        DWORD dwStateMask;
        CHAR   szInfo[256];
        union {
            UINT  uTimeout;
            UINT  uVersion;
        } DUMMYUNIONNAME;
        CHAR   szInfoTitle[64];
        DWORD dwInfoFlags;
#endif
#if (_WIN32_IE >= 0x600)
        GUID guidItem;
#endif
} NOTIFYICONDATAA, *PNOTIFYICONDATAA;

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.

Thanks.
0
Comment
Question by:js_cheng
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 200 total points
ID: 9647081
js_cheng:

> 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,
Dex*
0
 

Author Comment

by:js_cheng
ID: 9651212
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

NOTIFYICONDATA icon;

// 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.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
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.
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9651771
js_cheng:

> 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.

Dex*
0
 
LVL 1

Expert Comment

by:Kanchipuramdeena
ID: 24324927
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?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now