Sign in to follow this  
Followers 0
jiglei

Control send with process instead of window?

6 posts in this topic

#1 ·  Posted (edited)

Hi there, i'm having a problem, which stops me of getting finished my program, which is the following: I want autoit to run a program, wait for the process, then wait for the window (I know the name of the window that will open) but here comes a little obstacle: Sometimes there's a need to have already opened an instance of the program that auto it will run, but i know the Process id of them are different, though, if I do like this:

$process=Run("My program")
Processwait("$process")
WinWait("Myprogram's window")
Actions(with the window)

Like that, the auto it won't do actions with the window he did opened, instead will do them with the windows thats opened for the longest time, i need to know a way to make it interact with the window that he opened, some way to turn it a variable? Please give me some tips :)

Thanks in advance.

Edited by jiglei

Share this post


Link to post
Share on other sites



So I understand, you have two windows open with the same name?

Window 1 "Foo" with a pid of 123

Window 2 "Foo" with a pid of 456

Have a look at WinTitleMatchMode, WinList and WinActive.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

So I understand, you have two windows open with the same name?

Window 1 "Foo" with a pid of 123

Window 2 "Foo" with a pid of 456

Have a look at WinTitleMatchMode, WinList and WinActive.

You understood me right. But i can't see how WinTitleMatchMode can help me in this, nor WinActive, since the Title of both windows are the same, but I think there's a solution in WinList, but i don't understand how it really works, im gonna read the help file a bit more, thanks for the tips.

Share this post


Link to post
Share on other sites

; ===============================================================================
; Retrieves the Handle of GUI/Application the mouse is over.
; Similar to WinGetHandle except it used the current mouse position (Client Coords)
; Taken from http://www.autoitscript.com/forum/index.php?showtopic=444962
; ===============================================================================
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(), "long", MouseGetPos())
    If IsArray($iRet) Then
        Return HWnd($iRet[0])
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>GetHoveredHwnd


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

One you get a handle from the given code or WinList, look at GetWindowThreadProcessId()

http://msdn.microsoft.com/en-us/library/ms633522(VS.85).aspx. You will need to do a DLL Call.

Found:

; Get the Process ID of a window.  It will be stored in the output-parameter PID.
$result3 = DllCall("user32.dll","int","GetWindowThreadProcessId","hwnd",$HWND,"int_ptr", $PID)
$PID = $result3[2]
if (@error OR NOT $PID) Then
   MsgBox (0,"","GetWindowThreadProcessId failed.")
   Exit
EndIf
and

That's Brett solution, as follows. But is hard to believe that If I'm starting a process, I can't have all information about it, as for example WinList and other does...

Func _GetHwndFromPID($PID)
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc;==>_GetHwndFromPID
Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Thanks, now I've found the way to do it right ^^ works perfectly, your help was precious :) .

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
Sign in to follow this  
Followers 0