How to drag a untitled window

Source: Internet
Author: User

Sometimes, we need to paint the title of the window, or hide the window title, then the question is, which is how to drag the untitled window?
The essence of this question is how to drag the mouse over the client area of the window and move the window.
Normally, a window is only in the area of the title bar and responds to a mouse-dragged message. The client area of the window does not respond.
So there's a way that we can trick windows into thinking that when the mouse clicks the client area of the window, it clicks on the title bar.
There is a news that wm_nchittest.
The MSDN explanation for it is:
The WM_NCHITTEST message is sent to a window when the cursor moves, or if a mouse button is pressed or released. If the mouse is not captured, the message was sent to the window beneath the cursor. Otherwise, the message is sent to the window, which has captured the mouse.
The message is sent when the mouse moves or the mouse button is pressed.
If the return value of the WM_NCHITTEST message response function is htclient, indicating that the mouse is clicked on the client area, Windows sends a WM_LBUTTONDOWN message to the window if wm_ The return value of Nchittest's message response function is not htclient (possibly Htcaption, htclose, Htmaxbutton, etc.), which is the non-client area of the mouse click, and Windows sends a WM_NCLBUTTONDOWN message to the window.
The introduction doesn't have much to do with this, but it can help you understand it.
The next step is to implement the exact method, which is divided into two steps:
1. Add On_wm_nchittest () in Message_map
2. Manually add response function uint Onnchittest (CPoint point)
This should be handled as follows:
UINT Cyourclass::onnchittest (CPoint point) {uint Nh=cdialog::onnchittest (point); return ((nh==htclient)? HTCAPTION:NH);}

The second way is simple, is to handle the mouse left-click message:
First, add the left mouse button to click the message, with automatic Add.
void Cyourclass::onlbuttondown (UINT nflags, CPoint point) {//Todo:add your message handler code here and/or call DefaultS Endmessage (wm_syscommand,0xf012,0); Cdialog::onlbuttondown (nflags, point);}

Attention is paid to SendMessage (wm_syscommand,0xf012,0);
This is not the same as the effect of the first method, sending a message stating that the Send Sc_move + htcaption, so here shorthand becomes 0xf012.

How to drag a untitled window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.