Jump to content

Sometimes WinActivate() doesn't activate a minimized window


Noob
 Share

Recommended Posts

Sometimes, when a window is minimized, WinActivate() doesn't seem to activate it. This is so infrequent, that I haven't yet found a way to reproduce it. But I noticed that when it happens, I can either click anywhere on empty space on the desktop, and after that WinActivate() will function. I may even click on empty space on the Windows Taskbar, and after that WinActivate() works, too.

Link to comment
Share on other sites

i got the same expirience

I used the WinGetState() function when that happen. According to that function the window existed, was visible, was enabled, was active;), and it was minimized. Yet, the WinActivate() didn't work, and nor did @SW_MAXIMIZE, @SW_RESTORE, @SW_SHOW, or @SW_ENABLE do anything.

Interestingly, I noticed that when it happens the window 'button' on the Windows Taskbar is pushed-in (indicating the window is in fact active(?), yet the windows is minimized (or at least I cannot see it on the desktop.

Link to comment
Share on other sites

...Interestingly, I noticed that when it happens the window 'button' on the Windows Taskbar is pushed-in (indicating the window is in fact active(?), yet the windows is minimized (or at least I cannot see it on the desktop.

I have seen this - but not while running a script. I have never run a WinGetState on the missing window... I wonder what WinGetPos shows?

Anyway, I have also seen windows that are partially visible behind other windows, but will not come to the foreground and will not minimize - until you minimize all of the windows that were on top of it and then it will minimize.

I just write this off to the OS and all of the things that I do to it.

Do you have WinWaitDelay set to 0?

Is WinMinimizeAll in your script?

Mind posting a script that you seen this happen with?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Doesn't this goto the bug section of the forums?

More than likely it is an OS issue that has nothing to do with AutoIt... other than the fact that AutoIt can be used to demostrate the MS flaw by pushing some operations to the limits.

...but i could be wrong...

If it turns out to be an AutoIt issue, the thread can be moved at that time.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I found a way to reproduce the problem, but I've tested this only on one machine so far (WinXP).

While 1
HotKeySet("{F2}", "activate_notepad")
Sleep(100)
WEnd

Func activate_notepad()
WinActivate("Untitled - Notepad")
EndFunc

The <F2> shortcut is unable to activate the window when I do the following:

1. Open, and then minimize Notepad

2. Open a few other applications (I tried three: Word, Excel, FrontPage)

3. Minimize them all

4. Leave Notepad minimized, and restore the others one-by-one

3. Close these applications without using your mouse. Do Alt+F4 to close them

4. When all is closed, and only the Notepad is running (minimized), try the <F2> shortcut to activate the notepad window. In my case the window stays minimized, and WinActivate() doesnt seem to have a visible effect.

Link to comment
Share on other sites

I had something like this happen when trying to use the send function. What happens when you try to repeat the command several times to get the window to show up?

Nothing happens even if I try repeatedly.

Link to comment
Share on other sites

It might not change anything, but try this code instead:

HotKeySet("{F2}", "activate_notepad")

While 1
    Sleep(100)
WEnd

Func activate_notepad()
    $ret1 = WinWait("Untitled - Notepad")
    $ret2 = WinActivate("Untitled - Notepad")
    $ret3 = WinWaitActive("Untitled - Notepad")
    
    Sleep(200)
    $pos = WinGetPos("Untitled - Notepad")
    TrayTip("Window Position", _
            "x = " & $pos[0] & @LF & _
            "y = " & $pos[1] & @LF & _
            "Width = " & $pos[2] & @LF & _
            "Height = " & $pos[3] & @LF & @LF & _
            "WinWait Returned " & $ret1 & @LF & _
            "WinActivate Returned " & $ret2 & @LF & _
            "WinWaitActive Returned " & $ret3, 1)
EndFunc   ;==>activate_notepad
Edit: You can add your WinGetState lines...

I wonder if the TrayTip will even work in that OS state.

Edit2: I have not been able to reproduce this issue via your steps, but my OS build is only a few weeks old - I've not messed it up enough yet :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

herewasplato, thanks much. Here's what the tray tool tip showed:

Window Position

x = -32000

y = -32000

Width = 160

Height = 31

WinWait Returned 1

WinActivate Returned 1

WinWaitActive Returned 1

In the meantime I managed to come up with a satisfactory workaround for my situation. Knowing that by activating another window, (or focusing on something else), fixes my problem, I just added WinActivate("Program Manager") before the WinActivate("Untitled - Notepad").

But more importantly I'm glad that you were unable to reproduce the problem. It may just be this machine.

Link to comment
Share on other sites

Can you duplicate your problem via this code:

(and play with the WinSetState line in your function named activate_notepad)

Requires the beta version of AutoIt.

AutoItSetOption("WinWaitDelay", 100)
AutoItSetOption("WinTitleMatchMode", 2)


HotKeySet("{F2}", "activate_notepad")
AdlibEnable("TrTp")
$speed = 3000


$tip = "Open, and then minimize Notepad"
Sleep($speed)
Run("notepad")
WinWait("Notepad")
Sleep($speed)
WinSetState("Notepad", "", @SW_MINIMIZE)


$tip = "Open a few other applications"
Sleep($speed)
FileClose(FileOpen("deleteme.doc", 2))
ShellExecute(@ScriptDir & "\deleteme.doc")
WinWait("Word")
Sleep($speed)

FileClose(FileOpen("deleteme.xls", 2))
ShellExecute(@ScriptDir & "\deleteme.xls")
WinWait("Excel")
Sleep($speed)

Run("calc")
WinWait("Calcul")
Sleep($speed)


$tip = "Minimize them all"
Sleep($speed)
WinSetState("Calcul", "", @SW_MINIMIZE)
Sleep($speed)
WinSetState("Excel", "", @SW_MINIMIZE)
Sleep($speed)
WinSetState("Word", "", @SW_MINIMIZE)
Sleep($speed)
;WinMinimizeAll()


$tip = "Leave Notepad minimized and restore the others one-by-one"
Sleep($speed)
WinSetState("Word", "", @SW_RESTORE)
Sleep($speed)
WinSetState("Excel", "", @SW_RESTORE)
Sleep($speed)
WinSetState("Calcul", "", @SW_RESTORE)
Sleep($speed)


; Do Alt+F4 to close them - I used WinClose instead
$tip = "Close these applications"
Sleep($speed)
WinClose("Calcul")
Sleep($speed)
WinClose("Excel")
Sleep($speed)
WinClose("Word")
Sleep($speed)


;4. When all is closed,
;   and only the Notepad is running (minimized),
;   try the <F2> shortcut to activate the notepad window.
$tip = "...Notepad is running (minimized)"
Sleep($speed)

$tip = "Attempt to restore the Notepad window via WinActivate"
Sleep($speed)
AdlibDisable()
Send("{F2}")


While 1
    Sleep($speed)
WEnd


Func TrTp()
    TrayTip("", $tip, 1)
EndFunc   ;==>TrTp


Func activate_notepad()

    ;WinSetState("Untitled - Notepad", "", @SW_RESTORE)

    $ret1 = WinWait("Untitled - Notepad")
    $ret2 = WinActivate("Untitled - Notepad")
    $ret3 = WinWaitActive("Untitled - Notepad")

    Sleep(200)
    $pos = WinGetPos("Untitled - Notepad")
    TrayTip("Notepad's Window Position", _
            "The Notepad window should be active." & @LF & @LF & _
            "x = " & $pos[0] & @LF & _
            "y = " & $pos[1] & @LF & _
            "Width = " & $pos[2] & @LF & _
            "Height = " & $pos[3] & @LF & @LF & _
            "WinWait Returned " & $ret1 & @LF & _
            "WinActivate Returned " & $ret2 & @LF & _
            "WinWaitActive Returned " & $ret3, 10)
EndFunc   ;==>activate_notepad

Func OnAutoItExit()
    WinClose("Notepad")
    FileDelete("deleteme.doc")
    FileDelete("deleteme.xls")
EndFunc   ;==>OnAutoItExit
Edit: fixed copy/paste error Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Wow, nice work! That's exactly step-by-step how I could reproduce the issue! Now, however, I don't have access to the same machine. I think that WinXP machine didn't have Sevice Pack 2 installed. Now I tried your script on a different (WinXP SP2) machine. I cannot reproduce the problem with or without your script. I will try your script tomorrow on the non-SP2 machine. I'll let you know. Tnx!

Link to comment
Share on other sites

You are welcome.

You can remark out or delete that WinWaitDelay line. It does very little once I decided to add all of those sleeps instead. I was going for the "simulated human" and it can be done with forcing a long delay after each Window function via that WinWaitDelay setting... but it caused the activate_notepad func to be too slow with those 3 Win... funcs in a row.

Anyway, I prefer a script when it comes to chasing down things like this. Happy hunting.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

it's kinda like an OS issue, commonly happens when involving 2 windows and 1 gets closed.

Just a example scenario:

1) Open Notepad

2) Minimize Notepad window

3) Open any other window, eg My Computer

4) Close the new window by clicking the 'x' on the top right corner

At this point, you should see the Notepad icon on the Taskbar is depressed, indicating it's activated.

I did this on WinXP(32bit w/ SP2) by the way.

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

I tried the script by herewasplato on the PC I originally experienced the problem. Still the issue is there, but that's okay. Now I have my 'workaround', and I'm glad to know it's an (older) OS issue rather than AutoIt issue.

Thanks all who responded in this thread.

Link to comment
Share on other sites

  • 12 years later...
  • Developers

@WIHedgehog,

You have made 3 posts in 3 thread which are already dead and berried for many years. In this case 13 years!

Great when you want to help people in our forums, but please stick to the recent ones. ;) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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