Sign in to follow this  
Followers 0
8879899714

switching window using PID

7 posts in this topic

hi guys,

need some help here. ok i have a short program that can run and scan for the active window's PID. And from there, i can know the PID for the individual window. So now i am wondering how do i switch window using the PID? What commands to use? I have tried using Winactivate() but then it does not seems to work. Can someone enlighten me?

thanks.

Share this post


Link to post
Share on other sites



hi guys,

need some help here. ok i have a short program that can run and scan for the active window's PID. And from there, i can know the PID for the individual window. So now i am wondering how do i switch window using the PID? What commands to use? I have tried using Winactivate() but then it does not seems to work. Can someone enlighten me?

thanks.

If you show us your code, we can help you fix it.

Share this post


Link to post
Share on other sites

here is the short code ...

Global $xy, $start, $windows, $i, $win

$WinList=WinList()
for $i=1 to $WinList[0][0]
    If $WinList[$i][0] <> "" AND IsVisible($WinList[$i][1]) Then
        $win = WinGetTitle($WinList[$i][1])
        $win1 = WinGetProcess($WinList[$i][1])
        Sleep(2000)
        msgbox(4096, "Test",$WinList[$i][1] & @LF & $win & @LF & $win1,5)
    ;Sleep(2000)
        WinActivate($win)
        Sleep(2000)
        
    EndIf
Next

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Share this post


Link to post
Share on other sites

Seems to work for me. I simplified the IsVisible() func. Don't think that made a difference though.

Global $xy, $start, $windows, $i, $win

$WinList=WinList()
for $i=1 to $WinList[0][0]
    If $WinList[$i][0] <> "" AND IsVisible($WinList[$i][1]) Then
        $win = WinGetTitle($WinList[$i][1])
        $win1 = WinGetProcess($WinList[$i][1])
        Sleep(2000)
        msgbox(4096, "Test",$WinList[$i][1] & @LF & $win & @LF & $win1,5)
    ;Sleep(2000)
        WinActivate($win)
        Sleep(2000)
        
    EndIf
Next

Func IsVisible($handle)
  Return BitAnd( WinGetState($handle), 2 )
EndFunc

Share this post


Link to post
Share on other sites

A similar question was asked recently- wanting to know how to get a window handle from a PID. I posted this-

$handle=_GetPIDWindows(4072)
if IsHWnd($handle) then
    WinKill($handle)
EndIf

func _GetPIDWindows($PID)
    $WinList=WinList()
    for $i=1 to $WinList[0][0]
        if WinGetProcess($WinList[$i][1])=$PID then 
            Return $WinList[$i][1]
        EndIf
    Next
    Return 0
EndFunc

You can change WinKill() to WinActivate() and 4072 to the PID in question.

Share this post


Link to post
Share on other sites

hi guys,

the program will work. It will switch the window because i use "winactivate(the window title)". i want it to switch using the PID instead. like for example if i found that both similar name window PID is 2060 n 2828 respectivitly, how do i write it to switch to 2060 when i want it instead of 2828? i tried using "winactivate(2060)". it doesn't seems to work. hope you guys can understand. thanks.

Share this post


Link to post
Share on other sites

hi guys,

i have found the solution. thanks :D

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