dumdumpop

WinActivate() kinda selective?

21 posts in this topic

Hello everyone! So I'm new to autoit, and loving it! However, stuck on one little issue..
So far WinActivate() Works perfectly for me, however, I'm using it to open up a modified Notepad client, and its failing :(
I can retrieve the PID, Class Name, Handle etc. But for some reason, WinActivate is going on strike against actually setting focus to it lol
When I use it on the normal notepad client, it works like a charm though so I'm a bit puzzled as to why it wont work with the modified version :( Can anyone shed light on to this for me, hopefully a simple little change? :D Thanks in advance!

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Could you please post a screenshot of the AutoIt WIndow Info tool for your modified Notepad.?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Welcome to AutoIt and the forum!

Could you please post a screenshot of the AutoIt WIndow Info tool for your modified Notepad.?

Thanks :D Seems like a nice community!

And sure here it is:

 >>>> Window <<<<

Title: New Accounts - Notepad

Class: Notepad

Position: -8, -8

Size: 1456, 876

Style: 0x15CF0000

ExStyle: 0x00000300

Handle: 0x0000000000530B86

>>>> Control <<<<

Class: 

Instance: 

ClassnameNN: 

Name: 

Advanced (Class): 

ID: 

Text: 

Position: 

Size: 

ControlClick Coords: 

Style: 

ExStyle: 

Handle: 

>>>> Mouse <<<<

Position: 668, 369

Cursor ID: 0

Color: 0xD3CFEE

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

>>>> Hidden Text <<<<

Doesn't return nearly as many values as the original client, but still functions the same

 

Share this post


Link to post
Share on other sites

When I have a problem with winactivate i just move on to locating by title.

Opt("WinTitleMatchMode", 2)
WinActivate("text in the title of the window you are looking for")

Pretty generic but does the trick for the way I use it. Hope it helps.

Share this post


Link to post
Share on other sites

When I have a problem with winactivate i just move on to locating by title.

Opt("WinTitleMatchMode", 2)
WinActivate("text in the title of the window you are looking for")

Pretty generic but does the trick for the way I use it. Hope it helps.

Sorry, should've mentioned in the original post, I've tried locating the title and loading it like that as well, still doesn't work :x its a tricky one lol

Share this post


Link to post
Share on other sites

By the title and not the class? AKA New accounts over Notepad? I noticed it can be particular on that (use it with outlook that way). It wont locate Outlook but it locates the accounts tied to it in the title. >.> Lil strange but effective.

Share this post


Link to post
Share on other sites

By the title and not the class? AKA New accounts over Notepad? I noticed it can be particular on that (use it with outlook that way). It wont locate Outlook but it locates the accounts tied to it in the title. >.> Lil strange but effective.

Yup even with the proper title.  I spent like 6 hours trying every different combination of parameters that are allowed in the WinActivate and still cant get it lol

Only think I haven't successfully done was trying to load it from the PID but I wasn't sure if that was possible :x only things I found from searching was conveting a PID to handle which I didn't need

Share this post


Link to post
Share on other sites

Could you please post the code for the different ways you've tried?

Maybe this helps a bit.

Another question: In which way is this a modified Notepad program? Did you write it yourself or can we download it and play with it?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Could you please post the code for the different ways you've tried?

Maybe this helps a bit.

Another question: In which way is this a modified Notepad program? Did you write it yourself or can we download it and play with it?

$hWnd1 = WinWaitActive("[CLASS:Notepad]")

WinActivate($hWnd1)

Opt("WinTitleMatchMode", 2)

$hWnd2 = WinWaitActive("New Accounts - Notepad")

WinActivate($hWnd2)

WinActivate(988) ;;PID, I know this shouldnt work to begin with, but still tried it lol

$hWnd3 = WinWaitActive("[CLASS:Notepad]")

$hWnd3 = WinGetHandle($hWnd3)

WinActivate($hWnd3)

Those are a few ways that I tried it, <I manually opened up the ones calling for WinWaitActive() and added a msgbox in between as a delay so when I close the box, the program should open, didn't work>

Self modified so that it doesn't update instantly.  So basically every 5 seconds you see what you've typed. Kinda acting like a refreshing framerate.  I'm trying to expand my knowledge on programming, so just messing around with a bunch of things.  I don't necessarily need this for anything, but still fun to see what you can do :D but I do feel as though at some point in my modifications that I'll need to be able to activate the window with autoit :/

 

Share this post


Link to post
Share on other sites

What I don't get is why you first do a WinWaitActive (means: you wait until the window is active) and then try to activate it again using WinActivate.

WinGetHandle after WinWaitActive doesn't make sense because WinWaitActive returns a handle.

In general: Every AutoIt function returns a value to denote success or error of the function. Check the help file to see how to check if a function worked as expected.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

What I don't get is why you first do a WinWaitActive (means: you wait until the window is active) and then try to activate it again using WinActivate.

WinGetHandle after WinWaitActive doesn't make sense because WinWaitActive returns a handle.

In general: Every AutoIt function returns a value to denote success or error of the function. Check the help file to see how to check if a function worked as expected.

The reason I do a WinWaitActive is because I have several different notepads open, so it helps distinguish between which I want to use.  So with my regular notepad, non modified, I use the WinWaitActive, then select the first window.  Then save that as $hWnd1.  I can repeat these steps for as many windows as I'd like and can recall them separately by using WinActive()

So say I want to open up the second window out of 5, an easy way for me to distinguish between them, if their names are the same would be to use WinActivate($hWnd2)

if that makes more sense.

I've been using the help file a ton, but its not helping me with the issue.  The helpfile is the reason for me trying all the different ways to open it though

I also haven't used the WinGetHandle, but added it in so I can show that I was trying to get the handle as a method as well

*EDIT*

This is also my first day with Autoit, so I'm no pro at what gets returned from each function lol

 

Edited by dumdumpop

Share this post


Link to post
Share on other sites

I think we should keep your example as simple as possible.

If there is only a single copy of Notepad running (your modified version) and you run the following code, what do you get?

$hWnd1 = WinWaitActive("New Accounts - Notepad")
MsgBox(0, "Test", $hWnd1)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

 

I think we should keep your example as simple as possible.

If there is only a single copy of Notepad running (your modified version) and you run the following code, what do you get?

$hWnd1 = WinWaitActive("New Accounts - Notepad")
MsgBox(0, "Test", $hWnd1)

Keeping it simple works for me!

By running that, I get the handle: 0x00530B86

 

Share this post


Link to post
Share on other sites

Great!

When does your problem start then? When there is a second Window with the same title?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Great!

When does your problem start then? When there is a second Window with the same title?

The problem starts the second I try to activate the window.  Even if its the only window open, after doing that WinActivate wont open it, just leaves me on the screen that I'm on, and the client minimized.  However, if I hover over the notepad icon, its highlighted around it, as if it is in focus, but its not. 

I've tried adding a Send() function below it to see if it was actually open, just not being displayed for some reason and it doesn't type in the notepad at all

*EDIT*

Just tested running the function Send("Keys") so that it types keys in the notepad, it doesn't even do that so I'll probably just have to admit defeat on this :/

 

Edited by dumdumpop

Share this post


Link to post
Share on other sites

What do you mean by "WinActivate won't open it"? When WinWaitActive has been run successfully then the Notepad window is the active one (the one which has focus).

Please post the script you are running so we both are talking about the same code,


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What do you mean by "WinActivate won't open it"? When WinWaitActive has been run successfully then the Notepad window is the active one (the one which has focus).

Please post the script you are running so we both are talking about the same code,

You're a step behind, I already understand how WinWaitActive works, and it has worked all day.  That was never the issue.  All I'm trying to do is use the function WinActivate on the handle that was returned from the WinWaitActive. It just doesn't bring it into view, meaning its staying minimized.  On top of that, I cannot use the Send function when I manually open up the window.  So I'm just gonna say theres probably no solution and call it quits

I only have 1 post left till tomorrow night anyway

Share this post


Link to post
Share on other sites

This little example works as expected for Notepad.

It waits until the Notepad window is active and stores the handle. If you then minimize the Notepad window it activates it again using the stored handle.

$hWnd1 = WinWaitActive("Unbenannt - Editor") ; <== title needs to be changed
MsgBox(0, "Test", $hWnd1 & @CRLF & "Now minimize the window please!")
$hWnd2 = WinActivate($hWnd1)
MsgBox(0, "Test", "$hWnd1: " & $hWnd1 & @CRLF & "$hWnd1: " & $hWnd2)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

 

This little example works as expected for Notepad.

It waits until the Notepad window is active and stores the handle. If you then minimize the Notepad window it activates it again using the stored handle.

$hWnd1 = WinWaitActive("Unbenannt - Editor") ; <== title needs to be changed
MsgBox(0, "Test", $hWnd1 & @CRLF & "Now minimize the window please!")
$hWnd2 = WinActivate($hWnd1)
MsgBox(0, "Test", "$hWnd1: " & $hWnd1 & @CRLF & "$hWnd1: " & $hWnd2)

This is my last post I'm allowed for today, and that's what I was trying earlier.  I copied you exact code <changed the title> and ran it, when I minimize it displays the Test box, with 2 of the exact same Handles, but doesn't show the window of my notepad :/

Thanks for trying to help though, I appreciate it

Edited by dumdumpop

Share this post


Link to post
Share on other sites

Now we need more information:

Which windows version do you run?

Which version of AutoIt do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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