Sign in to follow this  
Followers 0
Algotek

SetControlText with windows handle ?

8 posts in this topic

#1 ·  Posted (edited)

Hi, first use of AutoIt.

I have the following info:

-the main application handle (hwnd1)

-the dialog handle (hwnd2) (the dialog is already opened and belongs to hwnd1)

-the dialog text control (hwnd3) (this is where I want to write)

How can I call SetControlText with this information ?

Edited by Algotek

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Put your code.

did you mean GUICtrlSetData?

Edited by Danyfirex

Share this post


Link to post
Share on other sites

Sorry, the exact name is

ControlSetText ( "title", "text", controlID, "new text" [, flag] )

I would like to directly take advantage of the windows handles (which are easily available from my program),

instead of specifying class, titles, or controlid.

Or translte the handles to whatever parameter this ControlSetText takes.

Share this post


Link to post
Share on other sites

did you look into help file?

A good example

Run("notepad.exe")
WinWait("[CLASS:Notepad]")
ControlSetText("[CLASS:Notepad]", "", "Edit1", "New Text Here")

Share this post


Link to post
Share on other sites

Sure, I did look to documentation.

I would like to directly take advantage of the windows handles (which are easily available from my program),

instead of specifying class, titles, or controlid.

Or translate somehow the handles to whatever parameter this ControlSetText takes.

The following does not work, although every single variable is OK according to the AutoIt Window Info

sub settext(hwnd2 as long,hwnd3 as long, stext as string)

Dim theclass As String

theclass = getmywindowclass(hwnd2) 'some routine that returns the class based on hwnd2

Dim thetitle As String

thetitle = getwindowtext(hwnd2) 'some routine that returns the caption of hwnd2

Dim ctrl_id As Long

ctrl_id = GetDlgCtrlID(hwnd3) .some Win api routine that return the ctrl id

Dim bsuccess As Boolean

'first try, as documented

bsuccess = (ai.ControlSetText("[CLASS:" + theclass + "]", thetitle, ctrl_id, stext) = 1)

'no success !!

'second try (usage not documented, and does not work)

bsuccess = (ai.ControlSetText(hwnd2, "", hwnd3, stext) = 1)

'no success !!

Share this post


Link to post
Share on other sites

Can you show your whole code?

Share this post


Link to post
Share on other sites

Your script isn't in the AutoIt language format, so it's not going to work with AutoIt.


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

@brewman: I'm using the AutoIt com object (ai) my code is in vb

In documentation, I found the following helpful topic

Window Titles and Text (Advanced)

At the end, it says

When you use a window handle for the title parameter then the text parameter is completely ignored.

The problem was that the hwnd2 I was using was a long.

AutoIt expects a pointer to the window (a variant)

Still not clear if ControlSetText 3rd parameter can be a hwnd.

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