自己处理WM_NCHITTEST消息,将如果鼠标点击在客户区则置换为标题栏:
LRESULT CMainDlg::OnNchitTest( UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/ )
{UINT nHitTest;
nHitTest = ::DefWindowProc(m_hWnd,WM_NCHITTEST,wParam,lParam);
if(nHitTest == HTCLIENT && ::GetAsyncKeyState(MK_LBUTTON) < 0)
{
nHitTest = HTCAPTION;
}
return nHitTest;
}
顺便粘贴下WM_NCHITEST消息的MSDN:
Sent to a window in order to determine what part of the window corresponds to a particular screen coordinate. This can happen, for example, when the cursor moves, when a mouse button is pressed or released, or in response to a call to a function such as WindowFromPoint. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.
A window receives this message through its WindowProc function.
Parameters
-
wParam
-
This parameter is not used.
lParam
-
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.
Return Value
The return value of the DefWindowProc function is one of the following values, indicating the position of the cursor hot spot.
Return code/value | Description |
---|---|
| In the border of a window that does not have a sizing border. |
| In the lower-horizontal border of a resizable window (the user can click the mouse to resize the window vertically). |
| In the lower-left corner of a border of a resizable window (the user can click the mouse to resize the window diagonally). |
| In the lower-right corner of a border of a resizable window (the user can click the mouse to resize the window diagonally). |
| In a title bar. |
| In a client area. |
| In a Close button. |
| On the screen background or on a dividing line between windows (same as HTNOWHERE, except that the DefWindowProc function produces a system beep to indicate an error). |
| In a size box (same as HTSIZE). |
| In a Help button. |
| In a horizontal scroll bar. |
| In the left border of a resizable window (the user can click the mouse to resize the window horizontally). |
| In a menu. |
| In a Maximize button. |
| In a Minimize button. |
| On the screen background or on a dividing line between windows. |
| In a Minimize button. |
| In the right border of a resizable window (the user can click the mouse to resize the window horizontally). |
| In a size box (same as HTGROWBOX). |
| In a window menu or in a Close button in a child window. |
| In the upper-horizontal border of a window. |
| In the upper-left corner of a window border. |
| In the upper-right corner of a window border. |
| In a window currently covered by another window in the same thread (the message will be sent to underlying windows in the same thread until one of them returns a code that is not HTTRANSPARENT). |
| In the vertical scroll bar. |
| In a Maximize button. |
Remarks
Use the following code to obtain the horizontal and vertical position:
xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam);
xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam);
You can also use the MAKEPOINTS macro to convert the lParam parameter to a POINTS structure.
Windows Vista: When creating custom frames that include the standard caption buttons, this message should first be passed to the DwmDefWindowProc function. This enables the Desktop Window Manager (DWM) to provide hit-testing for the captions buttons. If DwmDefWindowProc does not handle the message, further processing of WM_NCHITTEST may be needed.