Jump to content

Question with WinSetState and restoring a minimized window.


Go to solution Solved by ioa747,

Recommended Posts

I have a application run  on the system with minimized window state,

and I want to restoring it then minimized when execute the AutoIt script, 

but I had try it WinSetState restore but not works, (please check the Example2() function)

I also try Notepad.exe the default application in windows, and it works well,   (please check the Example() function)

Is it the application limitation?

or does there any suggestion

thanks in advance for any reply.

Func Example()
        WinActivate("[TITLE:Notepad]")
        Local $hWndNote = WinWait("[CLASS:Notepad]", "", 3)
        Sleep(500)
        
        Local $state = WinGetState("MPTool")
        If BitAND($state, 4) Then
            ConsoleWrite("MPTool is SW_MINIMIZE" & @CRLF)
        Else
            ConsoleWrite("MPTool is not SW_MINIMIZE" & @CRLF)
        EndIf
    
        WinSetState($hWndNote, "", @SW_RESTORE)
        ConsoleWrite("Notepad SW_RESTORE" & @CRLF)
        Sleep(500)
        
        WinSetState($hWndNote, "", @SW_MINIMIZE)
        ConsoleWrite("Notepad SW_MINIMIZE" & @CRLF)
        Sleep(500)
    EndFunc 
    
    Func Example2()
        WinActivate("[TITLE:MyTool]")
        Local $hWndTool = WinWait("[TITLE:MyTool]", "", 3)
        Sleep(500)
        
        Local $state = WinGetState("MyTool")
        If BitAND($state, 4) Then
            ConsoleWrite("MyTool is SW_MINIMIZE" & @CRLF)
            WinSetState($hWndTool, "", @SW_RESTORE)
        Else
            ConsoleWrite("MyTool is not SW_MINIMIZE" & @CRLF)
        EndIf
        
        Local $windowHandle = WinGetHandle("MyTool")
        If $windowHandle <> "" Then
            WinSetState($windowHandle, "", @SW_RESTORE)
            ConsoleWrite("MyTool SW_RESTORE >>>" & @CRLF)
        Else
            ConsoleWrite("MyTool does not exist")
        EndIf
        
        WinSetState($hWndTool, "", @SW_RESTORE)
        ConsoleWrite("MPTool SW_RESTORE" & @CRLF)
        Sleep(500)

        WinSetState($hWndTool, "", @SW_MINIMIZE)
        ConsoleWrite("MyTool SW_MINIMIZE" & @CRLF)
        Sleep(500)
    EndFunc 
    
    Example()
    Example2()

 

Link to comment
Share on other sites

Example()

Func Example()

    Local $hWndNote = WinWait("[CLASS:Notepad]", "", 3)

    WinActivate($hWndNote)
    ConsoleWrite("- Notepad WinActivate" & @CRLF)
    _WinShowState($hWndNote)
    Sleep(3000)

    WinSetState($hWndNote, "", @SW_MINIMIZE)
    ConsoleWrite("- Notepad SW_MINIMIZE" & @CRLF)
    _WinShowState($hWndNote)
    Sleep(3000)

    WinActivate($hWndNote)
    ConsoleWrite("- Notepad WinActivate" & @CRLF)

;~  WinSetState($hWndNote, "", @SW_RESTORE)
;~  ConsoleWrite("- Notepad  @SW_RESTORE" & @CRLF)

    _WinShowState($hWndNote)
    Sleep(3000)
EndFunc   ;==>Example

Func _WinShowState($hWnd)
    $state = WinGetState($hWnd)
    ConsoleWrite("$state=" & $state)
    If BitAND($state, 16) Then
        ConsoleWrite(" is minimized" & @CRLF)
    Else
        ConsoleWrite(" not minimized" & @CRLF)
    EndIf
    ConsoleWrite("" & @CRLF)
EndFunc

;~ $WIN_STATE_EXISTS (1) = Window exists
;~ $WIN_STATE_VISIBLE (2) = Window is visible
;~ $WIN_STATE_ENABLED (4) = Window is enabled
;~ $WIN_STATE_ACTIVE (8) = Window is active
;~ $WIN_STATE_MINIMIZED (16) = Window is minimized
;~ $WIN_STATE_MAXIMIZED (32) = Window is maximized

Edit:
use WinActivate($hWndNote) to restore

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

yes, I tried it as well, 

If BitAND($state, 16) Then
            ConsoleWrite("MPTool is SW_MINIMIZE >>>" & @CRLF)
            WinSetState($hWndTool, "", @SW_RESTORE)
            
            Local $hWndNote = WinWait("[TITLE:MPTool]", "", 3)
            WinActivate($hWndNote)
            
            ConsoleWrite("MPTool is SW_MINIMIZE <<<" & @CRLF)
        Else
            ConsoleWrite("MPTool is not SW_MINIMIZE" & @CRLF)
        EndIf

doesn't work on my tool, its wired ..

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