|
-
Mar 12th, 2001, 07:53 PM
#1
Thread Starter
New Member
How do I use the sendmessage function to copy text from a textbox to another windows program?
-
Mar 12th, 2001, 09:02 PM
#2
This will copy the selected text from another program. Open notepad, type some text and then select it, then add this code to a form with a command button, click the command button, you will see that it is copied to the clipboard.
Code:
Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As _
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, lParam As Any) _
As Long
Private Const WM_COPY = &H301
Private Sub Command1_Click()
Dim notepad As Long, editx As Long
notepad = FindWindowEx(0, 0, "notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
SendMessage editx, WM_COPY, 0, 0
End Sub
-
Mar 12th, 2001, 10:36 PM
#3
If you want to copy all the text, use the EM_SETSEL constant also used with the SendMessage API function.
Code:
Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As _
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, lParam As Any) _
As Long
Private Const WM_COPY = &H301
Private Const EM_SETSEL = &HB1
Private Sub Command1_Click()
Dim notepad As Long, editx As Long
notepad = FindWindowEx(0, 0, "notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
SendMessage editx, EM_SETSEL, 0, 0
SendMessage editx, WM_COPY, 0, 0
End Sub
And thanks to trr042, Lee M. for sharing with me the constants of the SendMessage API function, ...and to Chris, for being interested in the same topic as well .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|