Drag method for continued on the dialog box

zhaozj2021-02-11  164

For dialogs without the title bar, use the mouse to handle the simple method for: the message wm_nchittest is processed, then make the judgment of the mouse location, if the mouse location is in the client area where the window is to be moved, return to the signal in the title bar. It is also to deceive Windows, let it mistakenly think that you click on the title bar, so you can drag the window normally.

Specific function examples are as follows:

Uint ctimewakedlg :: Onnchnittest (cpoint point)

{

Uint hit = cdialog :: Onnittest (Point);

Return (Hit == HTCLIENT) HTCAPTION: HIT);

}

However, when we run, we find that this mobile method, anywhere in the electric shock customer area can move the entire window, but in most applications, we hope that only part of the region will start function.

In this way, I thought of the processing of the parameter Point, but I know, the Point here is not coordinates in the current active window, but the coordinates of the entire Windows desktop. To determine which part of the mouse click on the client area, you must correspond to the current window.

Thus, the application function getWindowPlacement gets the position of the current window on the screen, so that the position can be positioned with Point. The parameter type of this function is a WindowPlacement structure. Prototype

TypeDef struct tagwindowplacement {/ * wndpl * /

Uint Length;

Uint flags;

Uint showcmd;

Point PtminPosition;

Point ptmaxposition;

Rect rcNORMALPSITION;

WINDOWPLACEMENT;

Among them, the sixth variable rcnormalPosition is where the window is normally displayed. In this way, the coordinates of the window are obtained on the desktop. By comparing the coordinates of the Point, you will get the correct result. We modify the above function as follows, and you will get only the top left corner of the window to play a function of dragging.

Uint ctimewakedlg :: Onnchnittest (cpoint point)

{

Uint hit = cdialog :: Onnittest (Point);

IF (hit == htclient)

{

WindowPlacement Winplace;

GetWindowPlacement (& Winplace);

INT XP = Winplace.rcnormalPosition.RcNORMALPSITION.LEFT;

INT YP = Winplace.rcnorMalPosition.top;

IF ((Point.x> XP) && (Point.x YP) && (Point.Y

Return HTCAPTION;

Else

Return Hit;

}

Else

Return Hit;

}

Ok, then draw a picture in the upper left corner, it is more obviously beautiful.

J

转载请注明原文地址:https://www.9cbs.com/read-5915.html

New Post(0)