Jesusing Posted July 23, 2013 Share Posted July 23, 2013 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. Link to comment Share on other sites More sharing options...
michaelslamet Posted July 23, 2013 Share Posted July 23, 2013 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 Link to comment Share on other sites More sharing options...
Jesusing Posted July 23, 2013 Author Share Posted July 23, 2013 (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 July 23, 2013 by Jesusing Link to comment Share on other sites More sharing options...
michaelslamet Posted July 23, 2013 Share Posted July 23, 2013 You need to know the window handle, so you need a function that get the window handle by passing the PID. See this: Link to comment Share on other sites More sharing options...
Jesusing Posted July 23, 2013 Author Share Posted July 23, 2013 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. Link to comment Share on other sites More sharing options...
michaelslamet Posted July 23, 2013 Share Posted July 23, 2013 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 kylomas 1 Link to comment Share on other sites More sharing options...
BrewManNH Posted July 23, 2013 Share Posted July 23, 2013 (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 NextEDIT: Forgot to mention, this might only work with the latest beta version. Edited July 23, 2013 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 GudeHow 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 Link to comment Share on other sites More sharing options...
Solution Jesusing Posted July 23, 2013 Author Solution Share Posted July 23, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now