Sign in to follow this  
Followers 0
gius

WinActivate

6 posts in this topic

Hello everyone,

with this code

pressing the button "+" applies the "zoom" in the window MS Word

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>

Opt("WinTitleMatchMode", -2)

$Form1 = GUICreate("", @DesktopWidth - 50, 50, 20, 0, BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX,$WS_THICKFRAME))
$Label1 = GUICtrlCreateLabel("ZOOM", 15, 20, 62, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("+", 95, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("-", 140, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("F", 330, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button4 = GUICtrlCreateButton("F", 370, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
           _zoom1 ("microsoft word")
    Case $Button2
           _zoom2 ("microsoft word")
    Case $Button3
           _zoom3 ("Firefox")
    Case $Button4
           _zoom4 ("Firefox")
 
    Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
 WEnd

Func _zoom1($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("up", 1)
   Send("{CTRLUP}")
EndFunc

Func _zoom2($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("down", 1)
   Send("{CTRLUP}")
EndFunc

Func _zoom3($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("up", 1)
   Send("{CTRLUP}")
EndFunc

Func _zoom4($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("down", 1)
   Send("{CTRLUP}")
EndFunc

but does not function with Mozilla Firefox,
why?
Can you help me to understand?

thank you

Share this post


Link to post
Share on other sites



try this 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>

Opt("WinTitleMatchMode", -2)

$Form1 = GUICreate("", @DesktopWidth - 50, 50, 20, 0, BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX,$WS_THICKFRAME))
$Label1 = GUICtrlCreateLabel("ZOOM", 15, 20, 62, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("+", 95, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("-", 140, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("F", 330, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button4 = GUICtrlCreateButton("F", 370, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
           _zoom1 ("microsoft word")
    Case $Button2
           _zoom2 ("microsoft word")
    Case $Button3
           _zoom3 ("[CLASS:MozillaWindowClass]")
    Case $Button4
           _zoom4 ("[CLASS:MozillaWindowClass]")
 
    Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
 WEnd
Func _zoom1($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("up", 1)
   Send("{CTRLUP}")
EndFunc

Func _zoom2($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("down", 1)
   Send("{CTRLUP}")
EndFunc

Func _zoom3($hWnd)
   if WinActivate($hWnd) then Send("{CTRL}^{+}{+}")
EndFunc

Func _zoom4($hWnd)
      if WinActivate($hWnd) then Send("{CTRL}^{-}{-}")
EndFunc

Share this post


Link to post
Share on other sites

Thanks Celtic88,

works very well!

If I press the button where calls up the CLASS:Mozilla,
the application disappears from the desktop,
It is possible to do something about this?

I tried to have two CLASS: Mozzilla and IE with the same key
:

Global $windows[2] = ["[CLASS:MozillaWindowClass]","[CLASS:ExplorerWindowClass]"]

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
           _zoom1 ("microsoft word")
    Case $Button2
           _zoom2 ("microsoft word")
    Case $Button3
           _zoom3($windows)
    Case $Button4
           _zoom4 ($windows)

    Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
 WEnd

but I believe it was wrong to call the variable $windows, and it does not work,
it is possible to correct my mistake?

thanks

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("WinTitleMatchMode", -2)
Global $windows[2] = ["internet explorer", "mozilla firefox"]

$Form1 = GUICreate("", @DesktopWidth - 50, 50, 20, 0, BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
$Label1 = GUICtrlCreateLabel("ZOOM", 16, 20, 62, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("+", 96, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("-", 141, 10, 33, 33)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
           _zoom("+")
    Case $Button2
           _zoom("NUMPADSUB")
    Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
 WEnd

Func _zoom($key)
   For $i = 0 to UBound($windows)-1
      $state = WinGetState($windows[$i])
      ; if enabled and not minimized
      If BitAND($state, 7) and not BitAND($state, 16) Then 
            WinActivate($windows[$i])
            Send("^{" & $key & "}")
            Return
     EndIf
   Next
EndFunc

;)

Share this post


Link to post
Share on other sites

many thanks Mikell,

works very well.

I have noticed that I can not add to browsers other applications like MS Word,
so I had to make a new global variable

Global $test[3] = ["microsoft word", "microsoft excel" , "notepad"]
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
           _zoom("+")
    Case $Button2
           _zoom("-"); "NUMPADSUB"
   Case $Button3
           _zoom1 ($test)
    Case $Button4
           _zoom2 ($test)
    Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
 WEnd
Func _zoom1($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("up", 1)
   Send("{CTRLUP}")
EndFunc

Func _zoom2($hWnd)
   WinActivate($hWnd)
   Send("{CTRLDOWN}")
   MouseWheel("down", 1)
   Send("{CTRLUP}")
EndFunc

but I can not understand how to be inserted

in
_zoom1 (.........................)

    _zoom2 (.........................)

thanks

Share this post


Link to post
Share on other sites

gius,

You now have ALL the necessary samples to build the script you want

For some applications you will need to use Ctrl+{+} and for others Ctrl+Wheel

So you can use previous sample scripts and combine them

Just be careful when dealing with arrays :

Global $windows[2] = ["internet explorer", "mozilla firefox"]  ; $windows is an array
; ...
For $i = 0 to UBound($windows)-1
   ; some code using  $windows[$i]  which is an array element
Next

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