VC++ mouse non-display area hit test message WM_NCHITTEST and related programming problems learning 1

This message represents the non-display area hit test; the non-display area should refer to the area outside the window client area;
this message takes precedence over all other display area and non-display area mouse messages; the lParam parameter contains the x and y screen coordinates of the mouse position , WParam is not useful here;

The return value of the message:
    one of the mouse hit test enumeration values ​​listed below; 

HTBORDER is on the border of a window that does not have a variable-size border. 
HTBOTTOM is at the bottom of the horizontal border of the window. 
HTBOTTOMLEFT is in the lower left corner of the window border.  
HTBOTTOMRIGHT is in the lower right corner of the window border.  
HTCAPTION is in the title bar.  
HTCLIENT is in the client area.  
HTERROR is on the screen background or the dividing line between windows (same as HTNOWHERE, except that the DefWndProc function of Windows generates a system beep to indicate the error).  
HTGROWBOX is in the size box.  
HTHSCROLL is on the horizontal scroll bar.  
HTLEFT is on the left border of the window.  
HTMAXBUTTON is on the maximize button.  
HTMENU is in the menu area.  
HTMINBUTTON is on the minimize button.  
HTNOWHERE is on the screen background or the dividing line between windows.  
HTREDUCE is on the minimize button.  
HTRIGHT is on the right border of the window.  
HTSIZE is in the size box. (Same as HTGROWBOX)  
HTSYSMENU is on the close button of the control menu or sub-window.  
HTTOP is above the horizontal border of the window.  
HTTOPLEFT is in the upper left corner of the window border.  
HTTOPRIGHT is in the upper right corner of the window frame.  
HTTRANSPARENT is in a window covered by other windows.  
HTVSCROLL is in the vertical scroll bar.  
HTZOOM is on the maximize button.

A classic application of this message is to drag a form without a title bar, or how can I drag this form in the client area;
 

win10, VC6; create a new dialog box project, or single document project; the code is,

UINT CMainFrame::OnNcHitTest(CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	UINT nHitTest = CFrameWnd::OnNcHitTest (point);
    if (nHitTest == HTCAPTION)
	{
		AfxMessageBox("鼠标在标题条中!!!");
	}
	 //if ((nHitTest == HTCLIENT) && (::GetAsyncKeyState (MK_LBUTTON) < 0))
	 //{
     //   nHitTest = HTCAPTION;
		//AfxMessageBox("鼠标在标题条中!!!");
	 //}
	return CFrameWnd::OnNcHitTest(point);
}

If this message is handled by the dialog class or view class, and the code is added, the error is as follows;

That is, this message can only be processed by the main frame class; the code is as before;

According to the definition of this message, run the program and see if the dialog box pops up when the mouse is placed on the window title bar; the result is that there is no response; the commented part and the uncommented part of the code are the same;

Reorganize next time;

If the WM_NCHITTEST message does not appear in the class wizard; make the following selections;

From the code point of view, the message response function receives the mouse point coordinates, and then calls CFrameWnd::OnNcHitTest (point) through the point coordinates to obtain the enumeration value of the mouse position;

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/113786736