Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

API to Put text into a window

Posted on 2000-04-09
9
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

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

Public Const WM_SETTEXT = &HC
0
 
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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

610 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