gpt4 book ai didi

windows - 未收到 WM_LBUTTONDOWN 和 WM_LBUTTONUP

转载 作者:可可西里 更新时间:2023-11-01 10:56:12 25 4
gpt4 key购买 nike

我创建了顶层窗口,但由于未知原因,我的 WNDPROC 没有收到 WM_LBUTTONDOWN/WM_LBUTTONUPWM_MOUSEMOVE 消息。

有什么建议吗?

相关代码:

WNDCLASSEX wc = {0};
Wc.cbSize = 48;
Wc.cbWndExtra = 80;
Wc.hCursor = LoadCursorW(g_hInstance, MAKEINTRESOURCEW(1002));
Wc.style = CS_GLOBALCLASS | CS_DBLCLKS;
Wc.lpszClassName = Ici[dItemIndex].sInit;
Wc.lpfnWndProc = Ici[dItemIndex].wInit;

RegisterClassExW(&Wc);

g_hRuler1 = CreateWindowExW(WS_EX_TOOLWINDOW,
RULER_CONTROL,
L"",
WS_POPUP|WS_VISIBLE|0x1,
100 ,100, 40, RECTHEIGHT(g_rScreen),
NULL, NULL, hInst, NULL);

LRESULT WINAPI Ruler_Window(HWND hWindow, UINT uWindow, WPARAM wParam, LPARAM lParam)
{
if (uWindow == WM_GETMINMAXINFO)
{
goto DODEFAULT;
}

if (uWindow == WM_NCCREATE)
{
g_pGRI = RULER_ALLOCATE();

RULER_SET_POINTER(hWindow, (LONG_PTR)g_pGRI);

return 1L;
}

g_pGRI = RULER_GET_POINTER(hWindow);

g_pGRI->hWindow = hWindow;

switch(uWindow)
{
case WM_CREATE:
{
return Ruler_OnCreate(wParam, lParam);
}

case WM_PAINT:
{
return Ruler_OnPaint(wParam, lParam);
}

case WM_MOUSEMOVE:
{
return Ruler_OnMouseMove(wParam, lParam);
}

case WM_DESTROY:
{
return Ruler_OnDestroy(wParam, lParam);
}

case WM_SETCURSOR:
{
return Ruler_OnSetCursor(wParam, lParam);
}

case WM_LBUTTONDOWN:
{
return Ruler_OnLeftButtonDown(wParam, lParam);
}

case WM_LBUTTONUP:
{
return Ruler_OnLeftButtonUp(wParam, lParam);
}

case GM_SETINDICATORS:
{
return Ruler_OnSetIndicators(wParam, lParam);
}

DODEFAULT:
return DefWindowProcW(hWindow, uWindow, wParam, lParam);
}

}

单击左键后窗口的 Spy++ 消息。

enter image description here

最佳答案

我认为这里的问题是您很可能没有从自定义 wndProc 方法 (Ruler_Window) 中调用 DefWindowProc

wndProc 中的代码结构有点……有趣。

您在 switch 语句中处理您感兴趣的消息(WM_NCCREATE 除外,这很好),但您的 switch 语句实际上没有 default: 条目...相反,您创建了一个名为 DODEFAULT 的标签,您只引用一次 - 当消息为 WM_GETMINMAXINFO 时,您可以转到 DODEFAULT。忽略此处使用 goto 的问题,您基本上不会处理代码中列出的消息以外的任何消息,更重要的是,您不会将其他消息传递给默认处理程序.

Ruler_Window 方法的非常快速、非常简单的重写:

LRESULT WINAPI Ruler_Window(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_NCCREATE)
{
g_pGRI = RULER_ALLOCATE();
RULER_SET_POINTER(hWindow, (LONG_PTR)g_pGRI);
return DefWindowProcW(hWindow, uMsg, wParam, lParam);
}

// not sure what g_pGRI is, guessing it's a global?
// should this actually be passed into the handlers below?
g_pGRI = RULER_GET_POINTER(hWindow);
g_pGRI->hWindow = hWindow;

switch(uMsg)
{
case WM_CREATE:
return Ruler_OnCreate(wParam, lParam);

case WM_PAINT:
return Ruler_OnPaint(wParam, lParam);

case WM_MOUSEMOVE:
return Ruler_OnMouseMove(wParam, lParam);

case WM_DESTROY:
return Ruler_OnDestroy(wParam, lParam);

case WM_SETCURSOR:
return Ruler_OnSetCursor(wParam, lParam);

case WM_LBUTTONDOWN:
return Ruler_OnLeftButtonDown(wParam, lParam);

case WM_LBUTTONUP:
return Ruler_OnLeftButtonUp(wParam, lParam);

case GM_SETINDICATORS:
return Ruler_OnSetIndicators(wParam, lParam);

default:
break;
}

return DefWindowProcW(hWindow, uMsg, wParam, lParam);
}

请注意,恕我直言,我还将消息参数的名称更改为 uMsg,因为这样可以更轻松地阅读代码。

关于windows - 未收到 WM_LBUTTONDOWN 和 WM_LBUTTONUP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18254433/

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