Solved

API to Put text into a window

Posted on 2000-04-09
9
231 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 54
VB error "Type mismatch" 2 49
passing a value with stream reader AFTER a ";" 3 58
fso.FolderExists("\\server\HiddenFolder$") 4 46
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

929 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

13 Experts available now in Live!

Get 1:1 Help Now