3
votes

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);

3

3 Answers

5
votes

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.

3
votes

Maybe you could try to call ShowWindow with SW_SHOWNORMAL before trying to change the position.

0
votes

SetWindowPos doesn't change the window state (only its position).

Please use the SetWindowPlacement instead, and fulfill the WindowPlacement structure ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms632611(v=vs.85).aspx) with the SHowCmd member set to SW_SHOWMAXIMIZED