Jump to content

switching window using PID


Recommended Posts

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.

Link to comment
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.

Link to comment
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
Link to comment
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
Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
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.

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...