Sign in to follow this  
Followers 0
Jesusing

Winsetstate by process

8 posts in this topic

Hi,

I tried searching but nothing helps, I would like someone to write a simple function for me to be able to change the windows state by giving in the process ID, not the title. 

Thanks.

Share this post


Link to post
Share on other sites



Hi,

Use this function by Smoke_N:

;Smoke_N's WinGetByPID
Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds
    If IsString($iPID) Then $iPID = ProcessExists($iPID)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            If $nArray Then Return $aWList[$iCC][0]
            $sHold &= $aWList[$iCC][0] & Chr(1)
        EndIf
    Next
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(1, 0, 0)
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't need it to return a window title by PID, since I have multiple windows so it can't work for me. I specifically asked for a function that would change the state of a window by parsing in the PID of a process.

Edited by Jesusing

Share this post


Link to post
Share on other sites

You need to know the window handle, so you need a function that get the window handle by passing the PID.

See this:

Share this post


Link to post
Share on other sites

That includes a check to see if the windows is visible or not. Here's what I need specifically.

I parse in the pid, and the gui flag and it changes the pid's window (it's only one) to the flag I provided. None of the above shit.

Share this post


Link to post
Share on other sites

Above shit is a good foundation for what you're trying to accomplish and I think that thread can expand our knowledge further about how to handle process and window with AutoIT.

Or you might want to hire a freelancer :)

1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Try this, it first gets all windows open, then compares the PID that is connected to it to the PID you have, and then grabs the handle for the WinSetState function.

#include <WINAPI.au3>
$RunPID = Run("notepad.exe")
Sleep(2000)
Global $sThreadID = ""
$array = _WinAPI_EnumWindows()
For $I = 1 to $array[0][0]
    _WinAPI_GetWindowThreadProcessId($array[$i][0], $sThreadID)
    If $sThreadID = $RunPID Then
        WinSetState($array[$i][0], "", @SW_MAXIMIZE)
        ExitLoop
    EndIf
Next

EDIT: Forgot to mention, this might only work with the latest beta version.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Above shit is a good foundation for what you're trying to accomplish and I think that thread can expand our knowledge further about how to handle process and window with AutoIT.

Or you might want to hire a freelancer :)

 

I didn't ask for an expanding of my knowledge I asked for a damn function.

Try this, it first gets all windows open, then compares the PID that is connected to it to the PID you have, and then grabs the handle for the WinSetState function.

#include <WINAPI.au3>
$RunPID = Run("notepad.exe")
Sleep(2000)
Global $sThreadID = ""
$array = _WinAPI_EnumWindows()
For $I = 1 to $array[0][0]
    _WinAPI_GetWindowThreadProcessId($array[$i][0], $sThreadID)
    If $sThreadID = $RunPID Then
        WinSetState($array[$i][0], "", @SW_MAXIMIZE)
        ExitLoop
    EndIf
Next
EDIT: Forgot to mention, this might only work with the latest beta version.

 

Oh damn, I don't like betas, it's kind of messy but it'll do the job. If something better doesn't come up I'll like and mark as solved. Thanks.

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