Reputation: 2881
EDIT: I’ve used the following code to draw a push button at the non client area (the title bar) of my window. So my question is: Is possible to handle mouse click event from this button?
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);
}
Upvotes: 2
Views: 1728
Reputation: 20073
Yes this is quite easy to do. Windows provides several messages specifically for the non-client area. For example you have WM_NCMOUSEMOVE which can be handled just like WM_MOUSEMOVE but specifically for the non-client area. Most of the messages work like their client-area counterparts and usually with the same data structures. Below is a list of non-client area messages.
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
Upvotes: 2