Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleCopy the selected text in another application
Keywordscopy text, clipboard
CategoriesTips and Tricks, API
 
Use AppActivate to give that application the focus. Use the keybd_event API function to send the application Ctrl-C to copy the selected text. Then use the Clipboard object's GetText method to get the text.
 
' Grab the text highlighted in the other program.
Private Sub Command1_Click()
    ' Activate the other program.
    AppActivate txtCaption.Text, True

    ' Clear the clipboard.
    Clipboard.Clear

    ' Press Control.
    keybd_event VK_CONTROL, 0, 0, 0
    DoEvents

    ' Press C.
    keybd_event VK_C, 1, 0, 0
    DoEvents

    ' Release Control.
    keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
    DoEvents

    ' Get the text from the clipboard.
    Text1.Text = Clipboard.GetText
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated