Solved

API to Put text into a window

Posted on 2000-04-09
9
221 Views
Last Modified: 2010-05-02
Is there an API that can put text into a window? SetWindowText is close to what I want but it only puts the text into windows caption of the title bar. I want to put the text into the window.
Right now I'm using SendKeys to do the job but if there's a cleaner way I'd sure like to know it.  Thanks
0
Comment
Question by:royster
9 Comments
 
LVL 3

Expert Comment

by:wpsjr1
ID: 2697817
Not sure what kind of window to which you want to set the text.  In any case you will need FindWindow to get the top level window handle (hWnd) and FindWindowEx to the the hWnd of any child controls on the top level.  In most cases you will use SendMessage and some window message to set the text.  If it were a textbox you would use WM_SETTEXT.  For instance:

Dim lTophWnd&, lChildhWnd&, lRet&

lTophWnd = FindWindow("classname", "caption") <- substitute vbNullString for an unknown

lChildhWnd = FindWindowEx(lTophWnd, 0&, "classname", vbNullString)

lRet = SendMessage(lChildhWnd, WM_SETTEXT, 0&, ByVal "foo")

If its some other type of control let me know.  
0
 
LVL 1

Author Comment

by:royster
ID: 2698259
It is a text box. I have the handle for it but haven't been able to get this to work.  I don't know the proper value to use for WM_SETTEXT and the order of the SendMessage function I found appears different than the one in your example. Below is the function I have:
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
0
 

Expert Comment

by:Conniver
ID: 2698307
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long

Public Const WM_SETTEXT = &HC

Call SendMessageByString(textbox_handle, WM_SETTEXT, 0, "what said")

try that...
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2698320
you need to declare it as such:

Public Const WM_SETTEXT = &HC
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Expert Comment

by:AzraSound
ID: 2698323
oops...little late on my post
0
 
LVL 1

Author Comment

by:royster
ID: 2698570
It is a text box. I have the handle for it but haven't been able to get this to work.  I don't know the proper value to use for WM_SETTEXT and the order of the SendMessage function I found appears different than the one in your example. Below is the function I have:
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
0
 
LVL 1

Author Comment

by:royster
ID: 2698582
When I refreshed this screen it automatically rejected connivers answer and reposted my last comment... sorry. I'll test the answer a bit later and comment again what I find out. Thanks
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 2698584
there is no value for WM_SETEXT, it is a constant value that you declare as pointed out above.  It is the message being sent using the SendMessage api call.  SendMessage using the message WM_SETEXT takes as the paramaters:

hWnd:  handle to the destination window
Msg:  WM_SETTEXT (message to send)
wParam: (not used, set to 0)
lParam:  string that you want to send

notice lParam is declared As Any so you can make it whatever you want.  Declare it as a string

Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As String) As Long



And implement it:


Call SendMessageByString(textbox_handle, WM_SETTEXT, 0, "text to send")



0
 
LVL 1

Author Comment

by:royster
ID: 2699104
I had to fool with it some to get it to work. This did the trick:
SendMessage(EditHwnd, WM_SETTEXT, 0, ByVal "mystring")

It needed the ByVal. Thanks everyone for helping and if anyone else would like some points for helping let me know.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now