Sign in to follow this  
Followers 0
FreeFry

Getting the Classname of a windows from within AutoIt

6 posts in this topic

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. :D

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).

Share this post


Link to post
Share on other sites



Processexist

PID is the unique number which identifies a Process

for gui's

WinGetHandle

This 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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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


[center]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.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (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])

:D

Thanks Smokey for decifering my bad explenation, and giving me the exact code to solve this. :D

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. :P

Sorry if my english is kind of "off", but I've been out partying all night. :evil:

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]
EndFunc

All credits goes to Smoke, as I only modified it slighty, so it would ( hopefully ) never interfere with any script ever

Edit #Random(0, 500, 1)

Fixed a small error I made when I modified it.

Edited by FreeFry

Share this post


Link to post
Share on other sites

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.


[center]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.[/center]

Share this post


Link to post
Share on other sites

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. :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