Jump to content

Recommended Posts

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
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
Posted

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 :(

Posted

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 :(

Posted

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

Posted

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.

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
Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...