We're using SetWindowPos to well, set the position of a window and it's working great.
The only qualm I have with it, is that if the window we're moving is maximized, then it will move and become the proper size, however, it will still believe itself to be in the maximized state, and continue showing the "Restore" button.
Is there a way, once SetWindowPos is called, to tell that window to replace the Maximize button?
Also note: These windows aren't necessarily Windows Forms windows, but could be applications such as Explorer, Chrome, Firefox, Notepad, etc.
Here's our call to SetWindowPos:
PInvokeMethods.SetWindowPos(
hwnd, 0,
position.Left + x, position.Top + y, position.Width, position.Height,
PInvokeMethods.SWP_NoZOrder | PInvokeMethods.SWP_NoActivate);
If you want to set state and position in a single call, there is the SetWindowPlacement API.
First of all you would call GetWindowPlacement to fill out a WINDOWPLACEMENT struct with the current values. Then you would modify the showCmd and rcNormalPosition members. And then you would fire the modified struct back at SetWindowPlacement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With