2

编辑:我使用以下代码在窗口的非客户区(标题栏)上绘制了一个按钮。所以我的问题是:是否可以从此按钮处理鼠标单击事件?

bool MainWindow::winEvent(MSG *pMessage, long *result)
{
    UINT m = pMessage->message;
    if(m == WM_NCPAINT || m == WM_ACTIVATE)
    {
        HWND id = winId();
        HDC hDeviceContext = GetWindowDC(id);
        RECT rc = {10, 10, 65, 25};
        DrawFrameControl(hDeviceContext, &rc, DFC_BUTTON, DFCS_BUTTONPUSH);
        ReleaseDC(id, hDeviceContext);
        return true;
    }
    return QWidget::winEvent(pMessage, result);
}
4

1 回答 1

2

是的,这很容易做到。Windows 提供了一些专门针对非客户区的消息。例如,您有 WM_NCMOUSEMOVE,它可以像 WM_MOUSEMOVE 一样处理,但专门针对非客户区。大多数消息的工作方式与它们的客户区对应物一样,并且通常具有相同的数据结构。下面是非客户区消息的列表。

WM_NCCREATE
WM_NCDESTROY 
WM_NCCALCSIZE
WM_NCHITTEST 
WM_NCPAINT 
WM_NCACTIVATE

WM_NCMOUSEMOVE
WM_NCLBUTTONDOWN
WM_NCLBUTTONUP
WM_NCLBUTTONDBLCLK
WM_NCRBUTTONDOWN
WM_NCRBUTTONUP
WM_NCRBUTTONDBLCLK
WM_NCMBUTTONDOWN
WM_NCMBUTTONUP
WM_NCMBUTTONDBLCLK

WM_NCXBUTTONDOWN
WM_NCXBUTTONUP
WM_NCXBUTTONDBLCLK

WM_NCMOUSEHOVER
WM_NCMOUSELEAVE
于 2013-05-19T20:50:25.877 回答