Jump to content
Sign in to follow this  
EvilRubberDuck

Several problems (winsetstate and moving the window)

Recommended Posts

EvilRubberDuck

1-

So i was trying to do a macro, to change the output of the sound from my speaker to my phones.

i started with this 

run("Control.exe Mmsys.cpl")
WinWait("Som")

im portuguese so som=sound xD

but everytime i run this command the window opens in a diferent location (i really can't understand why), so i found this code in your forums

; Center Window on Screen
; Author cdkid and Valuater

Func _Middle($win, $txt)
    $size = WinGetClientSize($win, $txt)
    Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
    Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
    Return WinMove($win, $txt, $x, $y)
EndFunc  ;==>_Middle 

my problem is how do i define which windows it is to move. If im not wrong $win and $txt are both variables, and from what i could understand we dont need the part of $txt right? so i could do this 

Func _Middle($win)
    $size = WinGetClientSize($win, "")
    Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
    Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
    Return WinMove($win, "", $x, $y)
EndFunc  ;==>_Middle

now i only need to define $win but i think u need to  put like this WinMove("class or title", "", $x, $y) so if i define the variable Local $win=Som but it doesn't work :/

2-

so i tried almost everything reopen the window of google chrome when its minimized, and i only found one way:

Local $var = WinList()
For $i = 1 To $var[0][0]
; Only display visble windows that have a title
If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
Local $result = StringInStr($var[$i][0], "Chrome")

if $result > 0 Then
WinSetState($var[$i][0],"", @SW_RESTORE)
EndIf

EndIf
Next

Func IsVisible($handle)
If BitAND(WinGetState($handle), 2) Then
Return 1
Else
Return 0
EndIf

EndFunc ;==>IsVisible

but i still dont understand why when i use winsetstate with program class and with @SW_SHOW or @SW_RESTORE my chrome doesn't maximize, im using windows 7 x64 and i saw, in a post, someone that could so... (btw i have chrome fixed where the programs icons appear when opened)

If u could help me i would apreciate :)

EvilRubberDuck

Share this post


Link to post
Share on other sites
l3ill

Hi EvilRubberDuck,

  I think I got lost somewhere in the translation :-)

Where did we go from Speaker settings to Google Chrome?

No Matter, here is an example of how to get the handle of a window.

Once you have the handle you can boss it around all you like  :)

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This will be window nr. 1")

Local $handle1 = WinGetHandle("[CLASS:Notepad]", "This will be window nr. 1")

WinMove($handle1, "", 0, 0, 370, 370, 5)

Bill

Share this post


Link to post
Share on other sites
KaFu
EvilRubberDuck

Bill, thank your for your reply it help me understand better winmove command but still i have to ask something. I did this to your code: 

Run("notepad.exe")
WinWaitActive("[CLASS:Notepad]")

Local $handle1 = WinGetHandle("[CLASS:Notepad]", "")

WinMove($handle1, "", 0, 0, 370, 370, 5)

and it still works, so my question is why doesnt this code work:

Run("notepad.exe")
WinWaitActive("[CLASS:Notepad]")

; Center Window on Screen
; Author cdkid and Valuater

Local $win=WinGetHandle("[CLASS:Notepad]", "")
Func _Middle($win)
    $size = WinGetClientSize($win)
    Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
    Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
    Return WinMove($win, "", $x, $y)
EndFunc  ;==>_Middle

about chrome is a completely  diferent question xD

Kafu, thank you also for replying, if i could understand right your program enables me to change my default audio device, with a specific command in a autoit code?

Share this post


Link to post
Share on other sites
UEZ

EvilRubberDuck,

when you don't call the function it will never work! ;)

Run("notepad.exe")

WinWaitActive("[CLASS:Notepad]")


; Center Window on Screen

; Author cdkid and Valuater

_Middle(WinGetHandle("[CLASS:Notepad]", ""))

Func _Middle($win) ;shortened
    Local $size = WinGetClientSize($win)
    Return WinMove($win, "", (@DesktopWidth - $size[0]) / 2, (@DesktopHeight - $size[1]) / 2)
EndFunc  ;==>_Middle

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
EvilRubberDuck

LOOOOOOOL completely forgot about that xD

Thank you UEZ

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  

×