VC6自带的ShellApi.h和Shell32.lib库文件版本太旧,不提供对系统托盘API新特性的支持。
升级SDK 参见
定义在stdafx.h文件
#define _WIN32_IE 0x0500
要包含的头文件
#include <shellapi.h>
#pragma comment(lib, "shellapi.lib")
两个函数
- void BuildTrayIcon(HWND hwnd) //最小化到托盘
- {
- NOTIFYICONDATA notifyIconData;
- ZeroMemory( ¬ifyIconData, sizeof( notifyIconData ) );
- notifyIconData.cbSize = sizeof( notifyIconData );
- notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP|NIF_INFO;
- notifyIconData.hIcon = LoadIcon((HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE) ,
- MAKEINTRESOURCE(IDI_ICONAPP));
- notifyIconData.uID = IDI_ICONAPP;
- notifyIconData.hWnd = hwnd;
- notifyIconData.uCallbackMessage = WM_CLICKBIT; //自定义消息,在Myfunction.h中定义
- lstrcpy(notifyIconData.szTip, TEXT("xxx"));
- notifyIconData.dwState =
- notifyIconData.uTimeout = 5000/*超时毫秒数*/;
- notifyIconData.dwInfoFlags = NIIF_NONE;
- lstrcpy(notifyIconData.szInfoTitle, TEXT("托盘化;-):"));
- lstrcpy(notifyIconData.szInfo, TEXT("没有关闭哦。 嘿嘿~~~"));
- Shell_NotifyIcon( NIM_ADD, ¬ifyIconData );
- }
- //销毁系统托盘图标
- void DestroyTrayIcon(HWND hwnd)
- {
- NOTIFYICONDATA notifyIconData;
- ZeroMemory(¬ifyIconData, sizeof(notifyIconData));
- notifyIconData.cbSize = sizeof( notifyIconData );
- notifyIconData.uID = IDI_ICONAPP;
- notifyIconData.hWnd = hwnd;
- Shell_NotifyIcon(NIM_DELETE, ¬ifyIconData);
- }
参考: