qq状态栏图标,状态栏图标示列

 
#include
#include
#include
#include
#include "resource.h"
#pragma comment(lib, "shell32.lib")
#if (_WIN32_IE >= 0x0600)
#define SIZE_OF_NID NOTIFYICONDATA_V2_SIZE
#else
#define SIZE_OF_NID sizeof(NOTIFYICONDATA)
#endif
#define ICONID 1
#define WM_STATUSBAR_ICON_CALLBACK WM_USER + 1
#define CLASS_NAME _T("TrayClass")
HINSTANCE g_hInst;
BOOL CreateStatusBarIcon(HWND hWnd, HICON hIcon)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = SIZE_OF_NID;
nid.hWnd = hWnd;
nid.uID = ICONID;
nid.uCallbackMessage = WM_STATUSBAR_ICON_CALLBACK;
nid.uFlags = NIF_ICON | NIF_MESSAGE;
nid.hIcon = hIcon;
return Shell_NotifyIcon(NIM_ADD, &nid);
}
BOOL DelStatusBarIcon(HWND hWnd)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = SIZE_OF_NID;
nid.hWnd = hWnd;
nid.uID = ICONID;
return Shell_NotifyIcon(NIM_DELETE, &nid);
}
BOOL ShowInfoOnStatusBarIcon(HWND hWnd, LPCTSTR lpszInfo, LPCTSTR lpszTitle, DWORD dwTimeout)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = SIZE_OF_NID;
nid.hWnd = hWnd;
nid.uID = ICONID;
nid.uFlags = NIF_INFO;
nid.dwInfoFlags = NIIF_INFO;
nid.uTimeout = dwTimeout;
if (_tcslen(lpszInfo) < 255)
_tcscpy(nid.szInfo, lpszInfo);
if (_tcslen(lpszTitle) < 63)
_tcscpy(nid.szInfoTitle, lpszTitle);
return Shell_NotifyIcon(NIM_MODIFY, &nid);
}
BOOL ShowTipOnStatusBarIcon(HWND hWnd, LPCTSTR lpszTip)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = SIZE_OF_NID;
nid.hWnd = hWnd;
nid.uID = ICONID;
nid.uFlags = NIF_TIP;
if (_tcslen(lpszTip) < 64)
_tcscpy(nid.szTip, lpszTip);
return Shell_NotifyIcon(NIM_MODIFY, &nid);
}
BOOL FocusStatusBarIcon(HWND hWnd)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = SIZE_OF_NID;
nid.hWnd = hWnd;
nid.uID = ICONID;
return Shell_NotifyIcon(NIM_SETFOCUS, &nid);
}
void HandleStatueBarIconMsg(HWND hwnd, UINT uMsg)
{
switch (uMsg)
{
case WM_MOUSEMOVE:
ShowTipOnStatusBarIcon(hwnd, _T("This is tip samples."));
break;
case WM_LBUTTONDOWN:
ShowInfoOnStatusBarIcon(hwnd, _T("Button down _disibledevent=> HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU1));
HMENU hmenuPopup = GetSubMenu(hMenu, 0);
SetForegroundWindow(hwnd);
GetCursorPos(&pt);
TrackPopupMenu(hmenuPopup, TPM_LEFTBUTTON, pt.x, pt.y, 0, hwnd, NULL);
DestroyMenu(hMenu);
}
break;
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
{
HICON hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON1));
CreateStatusBarIcon(hwnd, hIcon);
}
return 0;
case WM_DESTROY:
{
DelStatusBarIcon(hwnd);
PostQuitMessage(0);
}
return 0;
case WM_STATUSBAR_ICON_CALLBACK:
{
HandleStatueBarIconMsg(hwnd, (UINT)lParam);
}
return 0;
case WM_COMMAND:
{
int id = (int)wParam;
if (id == ID__EXIT)
DestroyWindow(hwnd);
else if (id == ID__ABOUT)
MessageBox(hwnd, _T("Statue bar icon sample"), _T("About"), MB_OK|MB_ICONINFORMATION);
}
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
BOOL bRet;
MSG msg = {0};
WNDCLASS wc = {0};
HWND hwnd;
g_hInst = hInstance;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.lpszClassName = CLASS_NAME;
if (!RegisterClass(&wc))
{
printf("Register class failed\n");
return -1;
}
hwnd = CreateWindow(CLASS_NAME, _T(""),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hwnd)
{
printf("Create window failed\n");
return -1;
}
ShowWindow(hwnd, SW_HIDE);
while ((bRet = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
printf("GetMessage error. (0x%x)\n", GetLastError());
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
Tags:  状态栏图标变大了 安卓状态栏图标 状态栏图标 隐藏状态栏图标 qq状态栏图标

延伸阅读

最新评论

发表评论