FreeFry Posted June 16, 2006 Posted June 16, 2006 Hi, I have wondered about this for some time, but now it is kind of critical...In a loop, I use WinList() to get the Handles from every window visible.Then I intend to check if that window handle belongs to a particular window with a particular classname, if it does, Add it to an Array, then add a Child Window to that Window ( using the ANYGUI udf ) then skip that window in the future ( if its not closed that is ).The problem I'm having is the following:I seemingly cant find any way of getting the Classname of a window inside a AutoIt script, I really dont want to check just active windows, cus that would look kind of uggly when a target window is activated. I want it done on-the-fly, but as it seems, I cant. Btw. I feel identifying it by the classname is the most safe way, as Handles changes, and so does the window title ( depending on language of the targeted program and some other stuff).
Valuater Posted June 16, 2006 Posted June 16, 2006 ProcessexistPID is the unique number which identifies a Processfor gui'sWinGetHandleThis function is for use with the advanced WinTitleMatchMode options that allow you to use classnames and handles to specify windows rather than "title" and "text".Once you have obtained the handle you can access the required window even if its title changes.#include <GUIConstants.au3> $PID0 = Run("Notepad.exe", "", @SW_HIDE) $PID = ProcessExists("notepad.exe"); will be the same as above $PID1 = GUICreate("MY GUI", -1, -1, 100, 100) GUISetState() $PID2 = GUICreate("MY GUI") GUISetState() Sleep(2000) GUIDelete($PID1) Sleep(5000) MsgBox(0,"all pids", $PID1 & @CRLF & $PID & @CRLF & $PID0 & @CRLF & $PID2) If $PID Then ProcessClose($PID)8)
Moderators SmOke_N Posted June 16, 2006 Moderators Posted June 16, 2006 Are you talking about the "Class" or the "ClassNName"? I assume it's the class. You can try this:Func _ReturnClass($Hwnd) If IsString($Hwnd) Then $Hwnd = WinGetHandle($Hwnd) $aClass = DllCall('User32.dll', 'int', 'GetClassName', 'hwnd', $Hwnd, 'str', '', 'int', 30000) If Not @error Then Return $aClass[2] EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
FreeFry Posted June 17, 2006 Author Posted June 17, 2006 (edited) Thanks for the fast response, i know all about handles and such, but what I is after is not a control classname, nor a control/window handle, but the window classname.I think i would have to go with Smoke's code. I had a feeling it would have something to do with DllCall. ( which bothers me, because now when i see the code to get teh command, it seams so "easy", so it should be almost originally included. )I would love if this would get implented in autoit, like:WinGetClassName([Title], [Text])Thanks Smokey for decifering my bad explenation, and giving me the exact code to solve this. I think this perhaps should be noted by Jon or any other developer currently in charge of AutoIt's progress - because I think this can be used by many to identify windows/a window in a more reliable way. Sorry if my english is kind of "off", but I've been out partying all night. Thanks again Smokey. Edit #666 (heh)I've modded the code to make it a little more "script friendy" ( because I found it VERY usable ):Func WinGetClassName($w_Title) If IsString($w_Title) Then $w_Title = WinGetHandle($w_Title) $w_aClass = DllCall('User32.dll', 'int', 'GetClassName', 'hwnd', $w_Title, 'str', '', 'int', 30000) If Not @error Then Return $w_aClass[2] EndFuncAll credits goes to Smoke, as I only modified it slighty, so it would ( hopefully ) never interfere with any script everEdit #Random(0, 500, 1)Fixed a small error I made when I modified it. Edited June 17, 2006 by FreeFry
Moderators SmOke_N Posted June 17, 2006 Moderators Posted June 17, 2006 Your script doesn't take into account that someone might actually send the hwnd to the dll call (as I normally do). Your missing a condition statement, if you sent it like:MsgBox(64, 'Info:', WinGetClassName(WinGetHandle($MyWindowTitle)))Then $w_Title2 never has a value so it isn't returned a value. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
FreeFry Posted June 17, 2006 Author Posted June 17, 2006 SmOke_N said: Your script doesn't take into account that someone might actually send the hwnd to the dll call (as I normally do). Your missing a condition statement, if you sent it like:MsgBox(64, 'Info:', WinGetClassName(WinGetHandle($MyWindowTitle)))Then $w_Title2 never has a value so it isn't returned a value. Ah thanks for noting that, I didnt try my modded version out, so I didnt see the error I made. Updated the code above to work as it was made to work.
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