AutoHotkey Community

It is currently May 27th, 2012, 12:43 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 27th, 2010, 7:28 pm 
I am using a program that generally has about 9 windows open inside of it. I have created this very simple script using winactivate that will ensure the main window (Aegis MSP) will be active, and it works just fine.

Code:
IfWinExist, Aegis MSP
{
  WinActivate
  return
}


But the problem I'm having is, I can't get it to activate a sub window. In this picture below you will see the sub window name I want to have active called "Command Line".

Image

I have probably created a dozen different scripts with various commands to try and make this happen to no avail. It seems like it should be something really simple. I've searched quite abit on the net and this forum but can't seem to find any working solutions.[/img][/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2010, 10:44 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Ok I 1st created this to find a given sub window in an application. It looks more complicated than it is.
Actually its an example of how to find the windows hwnd so it can be used in a normal WinActivate.

I've used a sub window in MSVC++ as an example.
Image
You can see the name of the sub window as Text2.

To make this work in your app, just change the winName to the visual text (Command Line) and the appName to the Window Title name
(both found in in AU3_Spy).

Once it's found the corresponding name, you will be prompted to click on the sub window.
Code:
winName = Text2 ; Change the name to the visible text title of the sub window.
appName = test - Microsoft Visual C++ ; Change the name to your main application.

WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
    curHwnd := A_Loopfield
    WinGetTitle, curWin, ahk_id %curHwnd%
    CoordMode, Tooltip, Screen
    tooltip % "Current Hwnd: " curHwnd "`nCurrent Window: " curWin, 10, 10
        if (curWin = winName)
        {
                CoordMode, Tooltip, Screen
                winHwnd := curHwnd
                tooltip % "FOUND THE WINDOW!`n`nCurrent Hwnd: " winHwnd "`nCurrent Window: " curWin, 10, 10
                sleep, 2000
                Break
        }
    Sleep, 50
}

tooltip
Msgbox % "The hwnd is " winHwnd "`nNow use ahk_id `%winHwnd`% in WinActivate.`n`nPress Ok to select the window."
WinActivate, % appName
WinActivate, ahk_id %winHwnd%
Hopefully if that all works out, we've discovered how to find and select the window.
The reason its reliable is because most applications (if not all) create a new HWND (ahk_id) each time the application is open or the sub window is closed and reopened.
For this reason, you must find the HWND name before trying to select the window. Trying to use one single HWND will not work 99.9% of the time.

Now, this method can be condensed into:
Code:
winName = Text2 ; Change the name to the visible text title of the sub window.
appName = test - Microsoft Visual C++ ; Change the name to your main application.

WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
    curHwnd := A_Loopfield
    WinGetTitle, curWin, ahk_id %curHwnd%
    CoordMode, Tooltip, Screen
        if (curWin = winName)
                Break
}

WinActivate, % appName
WinActivate, ahk_id %curHwnd%
This will act like a single winactive for the sub window and should be quite fast if not instant.

NOTE: You may not have to activate the main application window before selecting the sub window, I just did this for my own reference ;).

hth

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2010, 11:10 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Also, if it all goes well, everything can be wrapped in a function.
Code:
winName = Text2
appName = test - Microsoft Visual C++

SelectSubWin(winName,appName) ; Call the function dynamically to select the sub window.
; or
SelectSubWin("Text2","test - Microsoft Visual C++") ; Static call.


SelectSubWin(wN,aN){
    global ; This is optional if you need the window names, hwnd etc externally.
    WinGet, conList, ControlListHwnd, % aN
    Loop, Parse, conList, `n
    {
        curHwnd := A_Loopfield
        WinGetTitle, cW, ahk_id %curHwnd%
        CoordMode, Tooltip, Screen
            if (cW = wN)
                    Break
    }
    WinActivate, % aN
    WinActivate % "ahk_id " curHwnd
}
Now if you have to select the sub window or another one more than once, simply use the function SelectSubWin(wN,aN) call instead.

Again, feel free to mod the last WinActive commands in the function to taste.

Have fun..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2010, 12:46 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6074
Location: San Diego, California
TLM wrote:
Ok I 1st created this to find a given sub window in an application. It looks more complicated than it is.
Actually its an example of how to find the windows hwnd so it can be used in a normal WinActivate.

:!: :!: FANTASTIC :!: :!:

Gracious TLM,

Would you please code a version that uses the control's name (ClassNN) as retrieved by
MouseGetPos, [OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 1|2|3]

I tried and failed miserably. Thank you.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2010, 1:00 am 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
:oops:

Trying to think of a non redundant approach :lol:.

Customer here picking up their computer.. Will report back soon..

edit:

This will 'store' the window/control HWND in 2 arrays on Left Click (hope you don't need the ClassNN 100%).
When the hotkey (F1) is triggered, the window/control is selected.
Code:
; Compatible with v 1.0.48.+
~LButton::
cnt++
    MouseGetPos,,, mPosWin%cnt%, mPosCtrl%cnt%, 2
return

F1::
    WinActivate, % "ahk_id " mPosWin1
    WinActivate, % "ahk_id " mPosCtrl1
    ; cnt= ; Reset if needed.
return
Hope it all makes sense..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2010, 4:35 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6074
Location: San Diego, California
No joy :cry:

I tried your original script and it works when I change the winname parameter to "Debug" :D
I could use my right/left arrow keys to switch between tabs like "Ram", "Rom" and all the rest

When I tried your Lbutton / F1 script it, I didn't get the same results, the arrow keys no longer worked the same/ ddin't seem to work at all.

I used Window Spy to get the names of the controls and
found that amoung all the other controls were the following
I have no idea how to tell what's going on. :(

a)
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
PCW
ahk_class Tfpcwmain

b)
Debug

c)
>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: TPanel7
Text:

d)
>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: TToolBar1
Text:

f)
>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: TPageControl1
Text:


Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2010, 3:24 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Leef_me wrote:
No joy :cry:

I tried your original script and it works when I change the winname parameter to "Debug" :D
I could use my right/left arrow keys to switch between tabs like "Ram", "Rom" and all the rest
Please post it..

It should be as simple as replacing arrows with mouse hotkeys no :?:

At any rate you should probably be using postmessage with constants for that 'big boy' approach ;)..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject: At first attempt
PostPosted: February 28th, 2010, 4:56 pm 
Success! I changed the two things you mentioned to change in the top 2 lines (in your 1st reply) and it worked! I haven't experimented yet with implimenting it with the rest of my scripts, but I don't see any reason why it shouldn't work. Very excited, thanks for the help.

Also, (I'm only a couple weeks old with autohotkey, so forgive me), what did you mean to include this script in a function as you posted in your 3rd example?


Report this post
Top
  
Reply with quote  
 Post subject: Perhaps I spoke to soon
PostPosted: February 28th, 2010, 5:02 pm 
Perhaps I spoke to soon. This is kinda weird, but it successfully activates the main title window, and it puts the cursor in the correct command line window, but it leaves it grey'd out so that it's not actually active. The cursor is blinking in the window like it's active, but the command line title bar is still grey instead of blue, and one of the other sub windows remains active.


Report this post
Top
  
Reply with quote  
 Post subject: weird
PostPosted: February 28th, 2010, 5:06 pm 
Ya it's weird I can type in the field as I could only do so before if the window was active, but I cannot hit enter which enters the command. I can type the command, I can backspace and delete the command, but I cannot hit enter is it shows another sub window active and recognizes me hitting enter on that window.


Report this post
Top
  
Reply with quote  
 Post subject: Re: At first attempt
PostPosted: February 28th, 2010, 8:16 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Strickt1 wrote:
...what did you mean to include this script in a function as you posted in your 3rd example?
You can call the function with the examples I posted, yes..
Strickt1 wrote:
..I cannot hit enter is it shows another sub window active...
Map a hothey to press any control button, use AU3_Spy to find control name. You can also use post messsage. Look here for Rajat example..

This small mod selects the window just not the title bar.
Code:
winName = Text7
appName = Microsoft Visual C++

SelectSubWin(winName,appName) ; Call the function dynamically to select the sub window.

SelectSubWin(wN,aN){
    global ; This is optional if you need the window names, hwnd etc externally.
    WinGet, conList, ControlListHwnd, % aN
    Loop, Parse, conList, `n
    {
        curHwnd := A_Loopfield
        WinGetTitle, cW, ahk_id %curHwnd%
        CoordMode, Tooltip, Screen
            if (cW = wN)
                    Break
    }
    WinSet, Top,, % "ahk_id " curHwnd
    WinActivate, % aN
    WinActivate % "ahk_id " curHwnd
}

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject: tried
PostPosted: February 28th, 2010, 9:47 pm 
You'll have to forgive me, I am still just a couple weeks old using AHK. I've been researching the post message like you suggested and viewing Rajat's example it makes sense, however the windows-spy.com link no longer works, and I searched for winspector spy on google and can't find a valid download anywhere.

My next question is, I understand how to map hotkey's, but what is a control button? Is that the same thing I would be trying to find using winspector spy that was mentioned in using postmessage such as Postmessage, 0x111, 12345 (in this case could 12345 be the control button?). Also using AU3_Spy I didn't see anywhere listed something as a Control Name. Unless, as in my 1st example a control name would be "Command Line" as I have an arrow pointing too.

The sub window I want to have active looks like this:

Image

What happens when I run any of the first 3 scripts, and even this last recent one is it puts the cursor in the command line as you can see in the below picture, but doesn't activate the window as to make the title bar blue. Here is the pic of that:

Image

As you can see the cursor is in the correct sub window being the command line window, but the window below it remains active.[/img]


Report this post
Top
  
Reply with quote  
 Post subject: Thx
PostPosted: February 28th, 2010, 9:49 pm 
Thanks again for all your help


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 4:18 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
TLM wrote:
At any rate you should probably be using postmessage with constants for that 'big boy' approach ;)..


Image
These 2 buttons should have ClassNN and Text names. Use AU3_spy.exe and mouse over the buttons and see what you get ;).

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Ah
PostPosted: March 1st, 2010, 4:34 pm 
Ah, ic :)

Here is the Au3 Spy Text I get when hovering over the first button with the green triangle on it. I notice it shows a ClassNN, but next to Text it's blank. When I hover over the button in the program a tooltip prompts up saying Execute Command. The other button is for looking up a list of commands. Here is the "Execute Command" button's AU3 Spy information:
Quote:

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Aegis MSP CAD 8.1 SP4 - User ******** (**** Hi-Res RC **** **** - ****** Hi-Res #2 **** ****) connected to nv1062
ahk_class ThunderRT6MDIForm

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 1202, 274 (less often used)
In Active Window: 2483, 275

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: ThunderRT6CommandButton2
Text:
Color: 0x00FF00 (Blue=00 Green=FF Red=00)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: -1281 top: -1 width: 3843 height: 1025

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
Command Line
Error Viewer
Unit Status Control Panel [Rows returned: 2]
Call Control Panel [Rows returned: 1]
Call Control Panel [Rows returned: 1]
Unit Status Control Panel [Rows returned: 1]
Unit Status Control Panel [Rows returned: 8]
Unit Status Control Panel [Rows returned: 7]


Here is the text from the 2nd button, I'm not sure if it's needed but I don't want to hinder ur excellence from using whatever might be needed :)

Quote:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Aegis MSP CAD 8.1 SP4 - User ******** (**** Hi-Res RC **** **** - County Hi-Res #2 **** ****) connected to nv1062
ahk_class ThunderRT6MDIForm

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 1233, 275 (less often used)
In Active Window: 2514, 276

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: ThunderRT6CommandButton1
Text:
Color: 0x00FF00 (Blue=00 Green=FF Red=00)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: -1281 top: -1 width: 3843 height: 1025

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
Command Line
Error Viewer
Unit Status Control Panel [Rows returned: 2]
Call Control Panel [Rows returned: 1]
Call Control Panel [Rows returned: 1]
Unit Status Control Panel [Rows returned: 1]
Unit Status Control Panel [Rows returned: 8]
Unit Status Control Panel [Rows returned: 7]


I didn't copy and paste the entire thing as it would make this post very long. If needed I can.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, jrav and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group