Jump to content

Minimize an active window - (Moved)


rix
 Share

Recommended Posts

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

rix,

Welcome to the AutoIt forums. I would suggest looking at WinSetState in the Help file.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

This is actually a bit complicated. Minimizing the window is the easy part. Being on the correct window will take a bit of coding.
WinList will show the open windows. Then you'll have to compare to see if the window you're looking for is open.
If so make it the active window then minimize it. OR ... if you know the windows exact name you could just try to make it active.
If that works then you can minimize it. If not the window couldn't be found. There is a tool called: AutoIt v3 Window Information.
You can use that to find the exact window text you can use (It's basically the name of the window and/or any text you added).

Raw commands would be: WinActivate ( "title" [, "text"] ) and WinSetState ( "title", "text", @SW_MINIMIZE)

Without anymore context in your question this is just a generic answer for you.

Link to comment
Share on other sites

Here is an example with notepad. 

OpenNotepad ()

Func OpenNotepad ()
    Local $iNotePad = Run("notepad.exe", "", @SW_MAXIMIZE)
    WinWait("[CLASS:Notepad]", "", 5)
    Sleep(5000) 
    WinSetState($iNotePad,"",@SW_MINIMIZE)
    ProcessClose($iNotePad)
EndFunc

 

Edited by SkysLastChance

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

3 hours ago, rix said:

i need a script to minimize an active windows Can you teach/help me? Thanks in advance...

To get the title or handle of the active window :

HotKeySet("{ESC}", "_Terminate")
HotKeySet("+!1", "_ActiveWindow") ; Shift-Alt-1

Global $sTitleActive, $hHandleActive ; Title or Handle

While True
    Sleep(100)
WEnd

Func _ActiveWindow()
    $sTitleActive = WinGetTitle("[active]")
    $hHandleActive = WinGetHandle("[active]")
    MsgBox(BitOR(4096, 64), "Minimize :", "Title  : " & @CRLF & $sTitleActive & @CRLF & _
                                          "Handle : " & @CRLF & $hHandleActive & @CRLF)
EndFunc

Func _Terminate()
    MsgBox(BitOR(4096, 64), "Message :", "Script terminated" & @CRLF)
    Exit
EndFunc

Use WinSetState  (with title or handle) to minimize the active window for example.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

On 11/19/2021 at 11:31 PM, Musashi said:

To get the title or handle of the active window :

HotKeySet("{ESC}", "_Terminate")
HotKeySet("+!1", "_ActiveWindow") ; Shift-Alt-1

Global $sTitleActive, $hHandleActive ; Title or Handle

While True
    Sleep(100)
WEnd

Func _ActiveWindow()
    $sTitleActive = WinGetTitle("[active]")
    $hHandleActive = WinGetHandle("[active]")
    MsgBox(BitOR(4096, 64), "Minimize :", "Title  : " & @CRLF & $sTitleActive & @CRLF & _
                                          "Handle : " & @CRLF & $hHandleActive & @CRLF)
EndFunc

Func _Terminate()
    MsgBox(BitOR(4096, 64), "Message :", "Script terminated" & @CRLF)
    Exit
EndFunc

Use WinSetState  (with title or handle) to minimize the active window for example.

I've got a doubt: but is the script uncomplete? or do I have to change it? if I run it I get nothing. I apologize for the obvious, but I am not an expert. I tried to simulate win +down but it closes all the windows .... if I really press the keys it closes the active window


 
Link to comment
Share on other sites

54 minutes ago, rix said:

I've got a doubt: but is the script uncomplete? or do I have to change it? if I run it I get nothing.

The script runs in the background (until you press ESC). It does not minimize anything, but shows you the title and handle of the currently active window. You can use this information to e.g. minimize the active window.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

45 minutes ago, rix said:

Yeap but i don't obtain a title, just the message script terminated when i press esc...

Please perform a test :

#include <MsgBoxConstants.au3>
HotKeySet("{ESC}", "_Terminate")
HotKeySet("+!1", "_ContolHasFocus") ; Shift-Alt-1

Run("notepad.exe")
Global $sControl, $hHandle, $sTitle
Global $hWnd = WinWait("[CLASS:Notepad]", "", 10)

While True
    Sleep(100)
WEnd

Func _ContolHasFocus()
    $hHandle  = WinGetHandle("[active]")
    $sTitle   = WinGetTitle("[active]")
    $sControl = ControlGetFocus($hWnd)
    MsgBox(BitOR(4096, 64), "Focus :", _
                            "Handle : " & @CRLF & $hHandle & @CRLF & _
                            "Titel  : " & @CRLF & $sTitle  & @CRLF & _
                            "Focus  : " & @CRLF & $sControl  & @CRLF)
EndFunc

Func _Terminate()
    MsgBox(BitOR(4096, 64), "Message :", "Script terminated" & @CRLF)
    Exit
EndFunc


Run the script. After Notepad is launched, then open whatever text file you want. Now press Shift Alt 1

Use the 1 from the keyboard, not the 1 from the Numpad. What happens now?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

52 minutes ago, rix said:

This one, it works fine...i've got handle and title

OK !

Another test :
Start your application (may not be minimized). Now run the following script within the SciTE editor (F5).

(from @Subz : getting-list-of-all-normal-windows )

#include <Array.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hWindow, $vWinStyle, $aWinNormal[1][2]
Local $aWinList = WinList("[REGEXPTITLE:(?i)(.+)]")
For $i = $aWinList[0][0] To 1 Step -1
    If $aWinList[$i][0] = "" Then ContinueLoop
    $hWindow = WinGetHandle($aWinList[$i][1], "")
    If Not $hWindow Then ContinueLoop
    $vWinStyle = _WinAPI_GetWindowLong($hWindow, $GWL_STYLE)
    If BitAND(WinGetState($aWinList[$i][1]), 4) = 4 _
            And BitAND($vWinStyle, $WS_VISIBLE) = $WS_VISIBLE _
            And BitAND($vWinStyle, $WS_MINIMIZE) <> $WS_MINIMIZE _
            And BitAND($vWinStyle, $WS_MINIMIZEBOX) = $WS_MINIMIZEBOX _
            And BitAND($vWinStyle, $WS_MAXIMIZEBOX) = $WS_MAXIMIZEBOX Then _ArrayAdd($aWinNormal, $aWinList[$i][0] & "|" & $aWinList[$i][1])
Next
$aWinNormal[0][0] = UBound($aWinNormal) - 1
_ArrayDisplay($aWinNormal)

Does your application appear in the list?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
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
 Share

  • Recently Browsing   0 members

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