gpt4 book ai didi

c++ - 为什么 Shell_NotifyIcon 气球提示不起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:01:35 25 4
gpt4 key购买 nike

根据我所看到的一切,当我在应用程序窗口中左键单击时,以下 C++ 程序应该会从托盘图标显示气球工具提示,但它无法正常工作。谁能告诉我我错过了什么?

这是在 XP 上的 Shell32.dll 版本 6.0(使用 DllGetVersion 验证)。

谢谢!

    #include "stdafx.h"
#include "shellapi.h"

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;

WNDCLASS wc;
memset(&wc, 0, sizeof(wc));
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "sysTrayTest";
RegisterClass(&wc);

HWND hWnd = CreateWindow("sysTrayTest", "",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 500, 500,
NULL, NULL, hInstance, NULL);
if (hWnd)
{
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
{
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(NOTIFYICONDATA));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = 1;
Shell_NotifyIcon(NIM_DELETE, &nid);

PostQuitMessage(0);
}
break;

case WM_CREATE:
{
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(NOTIFYICONDATA));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_USER + 200;
nid.hIcon = LoadIcon(NULL, IDI_INFORMATION);
lstrcpy (nid.szTip, "Test Tip");
Shell_NotifyIcon(NIM_ADD, &nid);
}
break;

case WM_LBUTTONDOWN:
{
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(NOTIFYICONDATA));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = 1;
nid.uFlags = NIF_INFO;
lstrcpy(nid.szInfo, "Test balloon tip");
lstrcpy(nid.szInfoTitle, "Test Title");
nid.dwInfoFlags = NIIF_INFO;
nid.uTimeout = 15000;
Shell_NotifyIcon(NIM_MODIFY, &nid);
}
break;

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

最佳答案

呸,我想通了。出于某种原因,我的标题...

sizeof(NOTIFYICONDATA) == 508

鉴于...

NOTIFYICONDATA_V3_SIZE == 504
NOTIFYICONDATA_V2_SIZE == 488
NOTIFYICONDATA_V1_SIZE == 88

如果我指定 V2 或 V3 而不是 sizeof(NOTIFYICONDATA),则气球提示显示得很好。

关于c++ - 为什么 Shell_NotifyIcon 气球提示不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/775700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com