The code to change the coordinates individually is as follows, moving left:
procedure Tform1.button1click (sender:tobject); begin 0, Panel1. left-, Panel1. Top, Panel1. Width, Panel1. Height, Swp_nozorder + swp_noactivate); End;
Each time the coordinates are changed, the setbounds is called, and the SetWindowPos function is called, but once I block the Updatebounds function, the control starts from the second time, and it has no effect:
procedure Tform1.button1click (sender:tobject); begin Panel1. Left:=panel1. left-; End;
What is this for? The reason is that after using the API to achieve the appropriate purpose, the Delphi property values must be modified for the next use. Otherwise, the next time Delphi will be the original left value minus 10, so that it does not appear to be moved. So the key is the code in Updatebounds:
proceduretwincontrol.updatebounds;varParenthandle:hwnd; Rect:trect; windowplacement:twindowplacement;beginGetWindowRect (Fhandle, Rect);//API, get the client area, note that the second parameter is a pointer, but Delphi directly uses //Important If you have a child window style, you should re-display it based on the parent control's position on the screen ifGetWindowLong (Fhandle, Gwl_style) andWs_child <>0 Then beginParenthandle:= GetWindowLong (Fhandle, gwl_hwndparent);//Api,fixme can also get the parent control handle as simple as this? Just this place . ifParenthandle <>0 Then beginwindows.screentoclient (Parenthandle, rect.topleft);//APIwindows.screentoclient (Parenthandle, rect.bottomright); End; End; //important after using the API to achieve the actual effect, but also to change the value of the Delphi attribute, otherwise the value of the property remains the last value, so that the next time it will not be moved //error: After displaying, update the properties of the win control based on Windows internal information //Important If exit here, then only the first time the coordinates can be moved, the back cannot be moved. After all, it works here.Fleft: =Rect.left; Ftop:=Rect.top; Fwidth:= Rect.right-Rect.left; Fheight:= Rect.bottom-Rect.top; //to re-rivet after updating coordinates and length width //Fixme don't need to be aligned, there are so many places elsewhere.Updateanchorrules;End;
The last few words. This will achieve the purpose of modifying the values.
--------------------------------------------------------------------
Another way to change the coordinates of a Windows window (Pro-Test):
procedureTform1.button2click (sender:tobject);varwindowplacement:twindowplacement;//Windows fabric type, containing 6 items, such as maximizing minimized window positionbeginwindowplacement.length:=SizeOf (windowplacement); GetWindowPlacement (Panel1.handle, @WindowPlacement); //API, get struct pointer, including 7 items //Change the location information for a windowWindowplacement.rcnormalposition: =Panel1.boundsrect; WindowPlacement.rcNormalPosition.Left:= WindowPlacement.rcNormalPosition.Left-Ten; WindowPlacement.rcNormalPosition.Right:= WindowPlacement.rcNormalPosition.Right-Ten; SetWindowPlacement (Panel1.handle, @WindowPlacement);End;
After using the SetWindowPos API function to move the window, you also need to modify the Delphi property values for the next use, otherwise there will be a problem (not the API does not work, but the wrong coordinate values are used)