如何在非客户区域处理按钮事件

时间:2013-05-19 16:22:43

标签: c++ windows qt button nonclient-area

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

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);
}

1 个答案:

答案 0 :(得分:1)

是的,这很容易做到。 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