gpt4 book ai didi

c - 如何响应有关列表框项目中右键的鼠标消息?

转载 作者:太空宇宙 更新时间:2023-11-04 04:36:52 25 4
gpt4 key购买 nike

如果我使用win32 api,如何响应WM_RBUTTONUP?

case WM_RBUTTONUP:
{
break;
}
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId) {
case IDE_FRIEND:
{
switch (wmEvent) {
case WM_RBUTTONUP:
{
POINT pt;
GetCursorPos(&pt);
TrackPopupMenu(g_hMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, nullptr);
break;
}
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
break;
}

当我点击鼠标右键时,不会输入'case WM_RBUTTONUP'

'IDE_FRIEND' 与列表框关联。

最佳答案

右键单击列表框将为父窗口生成上下文消息。你应该能够像这样捕捉它:

case WM_CONTEXTMENU:
{
if (hListBox == (HWND)wParam)
{
int x = LOWORD(lParam);
int y = HIWORD(lParam);
TrackPopupMenu(g_hMenu, TPM_RIGHTBUTTON, x, y, 0, hWnd, nullptr);
}
break;
}

case WM_RBUTTONUP:
{
//main window's right-click message
break;
}

case WM_COMMAND:
{
//...
}

编辑:对子类做同样的事情

#include "CommCtrl.h" //may need to add this
#pragma comment(lib, "comctl32.lib")

LRESULT CALLBACK ListBoxProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
UINT_PTR, DWORD_PTR)
{
switch (msg){

case WM_RBUTTONUP:
{
//add listbox menu here
break;
}

case WM_NCDESTROY://safely remove subclass
{
RemoveWindowSubclass(hwnd, ListBoxProc, 0);
return DefSubclassProc(hwnd, msg, wp, lp);
}

}

return DefSubclassProc(hwnd, msg, wp, lp);
}

LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
//...
case WM_CREATE:
ListBox = CreateWindow(L"listbox", ... )
SetWindowSubclass(ListBox, ListBoxProc, 0, 0);
//...
}

关于c - 如何响应有关列表框项目中右键的鼠标消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29897055/

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