Jump to content
Sign in to follow this  
kjpolker

WinActivate will not work

Recommended Posts

I am having the hardest time getting a window to activate. When I troubleshoot I get the right title but there appears to be no active window immediately following the WinActivate.

WinActivate($hWnd)
Send(1)
MsgBox(0, "", $hWnd) ;Used to immediately pass on the title to ensure it is correct

Using this line I am getting the correct Title as if it were copy and pasted. However the window will not activate, so I used WinGetTitle to check the active window and it is blank as if nothing is active.

I am obtaining the Title via:

Func checkproc()
    $winproc = WinGetProcess("[CLASS:Chrome_WidgetWin_1]")
    Global $hWnd = _GetWinTitleFromProcName($winproc)
    MsgBox(1, "", "Process ID is: " & $winproc & @CRLF & "Window Title is: " & $hWnd)
    If $hWnd = "" Then
        If @Compiled = 1 Then
            Run( FileGetShortName(@ScriptFullPath))
        Else
            Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
        EndIf
            DllClose($dll)
            Exit
    Else
        Sleep(10)
    EndIf
EndFunc

Func _GetWinTitleFromProcName($s_ProcName)
    $pid = ProcessExists($s_ProcName)
    $a_list = WinList()
    For $i = 1 To $a_list[0][0]
        If $a_list[$i][0] <> "" Then
            $pid2 = WinGetProcess($a_list[$i][0])
            If $pid = $pid2 Then Return $a_list[$i][0]
        EndIf
    Next
EndFunc   ;==>_GetWinTitleFromProcName

I'm guessing this can't really even be solved because to my understanding there is no issues with the syntax... I have never had an issue with this. The only clue I can pass on is that WinGetTitle returns a blank value.

Edited by kjpolker
typo

Share this post


Link to post
Share on other sites

The handle you get is most likely the handle of a child window and not the main window. Try to find the parent window with _WinAPI_GetAncestor() and activate that.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...