Sign in to follow this  
Followers 0
nf67

Unable to maximize a window sometimes.

11 posts in this topic

#1 ·  Posted (edited)

Hi there,

I got stuck at this while trying to write some kind of window management tool,

apparently WinSetState("[active]","",@SW_MAXIMIZE) doesn't work in some situations.

After moving a window to a corner this line won't do anything. Could it be because moving a window messes up the "activeness" of that window (in which case [active] has no effect)? Minimize() always works fine however, despite its similar setup. I'm left clueless.

Here's the entire script:

#include <Misc.au3>

;=================VARIABLES==============
$W = @DesktopWidth
$H = @DesktopHeight

$HW = @DesktopWidth / 2
$HH = @DesktopHeight / 2
;========================================

;=================HOTKEYS================

;CORNERS
HotKeySet("{NUMPAD7}", "TopLeft")
HotKeySet("{NUMPAD9}", "TopRight")
HotKeySet("{NUMPAD1}", "BottomLeft")
HotKeySet("{NUMPAD3}", "BottomRight")

;TOP & BOTTOM
HotKeySet("{NUMPAD8}", "Top")
HotKeySet("{NUMPAD2}", "Bottom")

;LEFT & RIGHT
HotKeySet("{NUMPAD4}", "Left")
HotKeySet("{NUMPAD6}", "Right")

;FULL & MINIMIZE
HotKeySet("{NUMPAD5}", "Full")
HotKeySet("{NUMPAD0}", "Minimize")

;========================================

While 1
WEnd

;=================FUNCTIONS==============

;CORNERS (No resize if L-Ctrl is down)
Func TopLeft()
    If _IsPressed("11")=1 Then
        MsgBox(0,"","")
        WinMove("[active]","",0,0)
    Else
        WinMove("[active]","",0,0,$HW,$HH)
    EndIf
    Redraw() ;Does nothing it seems, see Redraw() function below.
EndFunc

Func TopRight()
    If _IsPressed("11")=1 Then
        $Size = WinGetClientSize("[active]")
        WinMove("[active]","",$W-$Size[0],0)
    Else
        WinMove("[active]","",$HW,0,$HW,$HH)
    EndIf
    Redraw() ;Does nothing it seems, see Redraw() function below.
EndFunc

Func BottomLeft()
    If _IsPressed("11")=1 Then
        $Size = WinGetClientSize("[active]")
        WinMove("[active]","",0,$H-$Size[1])
    Else
        WinMove("[active]","",0,$HH,$HW,$HH)
    EndIf
    Redraw() ;Does nothing it seems, see Redraw() function below.
EndFunc

Func BottomRight()
    If _IsPressed("11")=1 Then
        $Size = WinGetClientSize("[active]")
        WinMove("[active]","",$W-$Size[0],$H-$Size[1])
    Else
        WinMove("[active]","",$HW,$HH,$HW,$HH)
    EndIf
    Redraw() ;Does nothing it seems, see Redraw() function below.
EndFunc

;TOP & BOTTOM
Func Top()
    WinMove("[active]","",0,0,$W,$HH)
EndFunc

Func Bottom()
    WinMove("[active]","",0,$HH,$W,$HH)
EndFunc

;LEFT & RIGHT
Func Left()
    WinMove("[active]","",0,0,$HW,$H)
EndFunc

Func Right()
    WinMove("[active]","",$HW,0,$HW,$H)
EndFunc

;FULL & MINIMIZE
Func Full()
    WinSetState("[active]","",@SW_MAXIMIZE)
EndFunc

Func Minimize()
    WinSetState("[active]","", @SW_MINIMIZE)
EndFunc
;========================================

;===============REDRAW===================
Func Redraw()
        $Handle = WinGetHandle("[active]")
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $Handle, "int", 0x111, "int", 28931, "int", 0)
EndFunc
;========================================

P.S: To prevent the shadow from messing up, I took the redraw from here, didn't fix it unfortunately.

Any suggestions? :(

Edited by nf67

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Yeah I had already done so in a previous attempt, but was annoyed by the space wasted with window borders :(

if you compare them side by side, @SW_MAXIMIZE gives you a much better full screen view... if it works, that is.

Edited by nf67

Share this post


Link to post
Share on other sites

As a workaround put a

WinSetState("[active]","",@SW_RESTORE)

directly before the

WinSetState("[active]","",@SW_MAXIMIZE)

...

And I'm still trying to figure out how to redraw the shadows after a move operation :(

Share this post


Link to post
Share on other sites

Ah nice KaFu, I didn't know about @SW_RESTORE, I could also very well use this in another part of my script :-).

It is indeed just a workaround but atleast it actually works :(

Share this post


Link to post
Share on other sites

Could anyone shed some more light on this issue? Is it a bug perhaps? :(

Share this post


Link to post
Share on other sites

I think the 'bug' you refer to is when you resize an already-maximized window. The window will still consider itself maximized, and in fact comes up as maximized when tested. You have to 'unmaximize' it first before moving it. @SW_RESTORE is easiest

Share this post


Link to post
Share on other sites

So you mean that the window considers itself resized even though it's not? Perhaps there's some kind of "refresh window state" or something :-/ ?

Thank you for your help.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Just change your 'Full' function to this:

Func Full()
    WinMove("[active]","",0,0,$W,$H)
EndFunc

You might want to grab the 'active' window position before making modifications so that a 'restore' is possible.. though once you minimize the window the 'active' window no longer is the same one.

By the way, a 'Sleep' in the While loop would be a good idea.

*Edit: Oops, just noticed someone suggested the same thing. If you don't like the borders being visible, you can get the border size, set the Window to a negative start 0-$iBorderSize and a larger-than screen width ($W+$iBorderSize). Of course, if your script exits, it'll be difficult for a user to grab onto the 'corners' for a resize unless you do it through the System menu functions.

Also, to help you with that - Use GetSystemMetricsto get sizes of Windows elements

Edited by Ascend4nt

Share this post


Link to post
Share on other sites

Thanks, I'll look into it... :( still wondering why it doesn't work, but I guess I'll have to accept that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0