Jump to content
Sign in to follow this  
Silvinho

How to catch the ID of an object dynamically?

Recommended Posts

Silvinho

How to catch the ID of a Tedit object dynamically, store in a variable and to pass as argument in function

ControlClick ("My Window", "", 254)

thanks

Share this post


Link to post
Share on other sites
zfisherdrums

Hello Silvinho,

Someone gave me this a while back:

Func GetControlID( $hwnd)
    Local $ID = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hwnd)
    if IsArray ($ID) Then Return $ID[0]
    Return 0    
EndFunc

Is that what you need?

Zach...

Share this post


Link to post
Share on other sites
Silvinho

How to catch the iD of a Tedit Object and to pass as argument in the function

ControlClick ("My Window", "", 254)

This ID always changes, I need take it and to pass in the function above in a variable.

Hello Silvinho,

Someone gave me this a while back:

Func GetControlID( $hwnd)
    Local $ID = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hwnd)
    if IsArray ($ID) Then Return $ID[0]
    Return 0    
EndFunc

Is that what you need?

Zach...

Share this post


Link to post
Share on other sites
zfisherdrums

Here's how to use it:

Func GetControlID( $hwnd)
    Local $ID = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hwnd)
    if IsArray ($ID) Then Return $ID[0]
    Return 0    
EndFunc

Run ("calc.exe" )
WinWait( "Calculator" )

$hwnd = ControlGetHandle( "Calculator", "", "[TEXT:2]" )
$id = GetControlID( $hwnd );    <---- this gets the control ID of the "2" button
ControlClick ("Calculator", "", $id )

Share this post


Link to post
Share on other sites
Silvinho

Brother, you are the best

Thank you very much

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  

×