How to Textbox Pick "Text" From Another application When i Highlight its text
My Project have a Timer And textbox (Multiline)
My Question is How to Textbox1 Pick Text From Any where , When i Highlight it LIKE :
Highlight text of Any Open textfile SHOW IN PIC:
I m Using this COde: (Please any one Modified it)
Public Class Form1 Dim results As String Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TopMost = True Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick results = TextBox1.SelectedText TextBox1.Text = GetAsyncKeyState(results) End Sub
End Class
Todas las respuestas
- shariq , you will have to copy the text to set it to the clipboard for this to work ..
if you do apply this to an app to distribute, i would add a small "help" file, to include that the user will have to copy text after highlighting, and also, that it can be done by using the keyboard shortcut keys, by pressing CTRL + C .
--------------
1 timer, 1 textbox.
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim copytext As IDataObject = Clipboard.GetDataObject() If copytext.GetDataPresent(DataFormats.Text) Then TextBox1.Text = copytext.GetData(DataFormats.Text) End If End Sub End Class
i live here and this is my reason.. trujade. - Hi Trujade !
Your Givin Help is UseFul But..................
Please Cosider On my Question! Just Import Text When I highlight It ... - ANy One have a solution My Solution
I need it
Thanx alot
Can any one help me Can any one Help!?
Can any one Help!?
how do you highlight the text? changing the colour?
if so just use the same method to copy the hilighlited text to be copyed....
look for what text is highlihted ans select it and copy it
Don't judge me, just Upgrade me. Thanks!- i want to Highlight text With Using Mouse Left Button
any type of text From any where ! if i highlight it , my application Pick it... Thank you All for your friendly help.
Hi ShariqDON,
trujade's idea "pass text among windows via clipboard" is good.
Here is another idea via P/Invoke APIs.
Step 1: Using Hook to get current point coordinate no matter where you point Cursor to.
Check the 5th post in this thread for code sample:
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/02e33bbf-1668-42e2-bef3-f03ad8792b23/
Step 2: P/Invoke WindowFromPoint API to get a handle to the window that contains the specified point.
WindowFromPoint Function http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx
Check the 3th post in this thread for code sample:
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/02e33bbf-1668-42e2-bef3-f03ad8792b23/
Step 3: P/Invoke SendMessage API to send WM_GETTEXT message to copy/get the text that corresponds to the window.
WM_GETTEXT messagehttp://msdn.microsoft.com/en-us/library/ms632627(VS.85).aspx
An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller.lResult = SendMessage( hWndControl, WM_GETTEXT, wParam, lParam);
ParameterswParam
Specifies the maximum number of TCHARs to be copied, including the terminating null character.
Windows NT/2000/XP:ANSI applications may have the string in the buffer reduced in size (to a minimum of half that of the wParam value) due to conversion from ANSI to Unicode.
lParam
Pointer to the buffer that is to receive the text.
Return Value
The return value is the number of TCHARs copied, not including the terminating null character.
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- The Trujade idea Is Best But One Problem if i copy text From Any Where , My Application Cannot pic Its text Autometicly
if i click any where in my Application Then Clipboard past Text Again And Again non stop
So How My Application Pic it Auto & how to it past it Only one Time
But i m only focus of my Thread...................
Thanx And Love you Sir Martin - I think you have already highlighted the problem you are facing with your original example code . That problem is: How are you going to indicate to your application that some text has been highlighted and should now be copied into your text box?
You original solution of using a timer won't work properly, because your application has no way of knowing that the text that it now sees as highlighted was already copied the last time the timer ticked. Unless you can implement some very complex checking for repeats, you will be continually processing the same highlighted text for as long as it stays highlighted.
But when you solve that problem, you will face your second problem, which involves determining which applications you are going to look at to find if any highlighted text is available. Will you be looking at all open applications? If so, that is going to take a lot of processing at each tick of the timer. So you need frequent ticks to ensure that you don't miss something, you need to look at all applications because you don't know which ones can have text or not, and you need to do process everything you find because you can't easily tell whether or not you've already seen it.
And that still leaves the problem of identifying the text that you are interested in. How are you going to identify user-entered text (which I presume is what you want) compared with dialogs, menus, help pages, etc (which can be permanently 'highlighted')? And having done that, you need to work out what 'highlighted' mens. Different applications use different techniques for highlighting, such as 'Selected' (in Windows terminology) or simply colored or underlined or reversed.
And all the above problems come after you have worked out how to:
1. Identify what applications are running
2. Locate the display components of those applications (the windows)
3. Extract the text from teh window
Those last three steps are possible, but not for all applications, and with a lot of complexity. The rest of your problem is a lot more difficult. In fact, I do not think it is doable without changing the design so that the user somehow indicates that some text has been highlighted and should now be copied.
My preferred approach would be to install a keyboard hook so that you can intercept a speciifc key combination, which the user will use to indicate that something has been highlighted and should be copied. When that happens, find the window that currently has the focus and scrape it for any highlighted text. I think you have already highlighted the problem you are facing with your original example code . That problem is: How are you going to indicate to your application that some text has been highlighted and should now be copied into your text box?
Yes !You original solution of using a timer won't work properly, because your application has no way of knowing that the text that it now sees as highlighted was already copied the last time the timer ticked. Unless you can implement some very complex checking for repeats, you will be continually processing the same highlighted text for as long as it stays highlighted.
But when you solve that problem, you will face your second problem, which involves determining which applications you are going to look at to find if any highlighted text is available. Will you be looking at all open applications? If so, that is going to take a lot of processing at each tick of the timer. So you need frequent ticks to ensure that you don't miss something, you need to look at all applications because you don't know which ones can have text or not, and you need to do process everything you find because you can't easily tell whether or not you've already seen it.
And that still leaves the problem of identifying the text that you are interested in. How are you going to identify user-entered text (which I presume is what you want) compared with dialogs, menus, help pages, etc (which can be permanently 'highlighted')? And having done that, you need to work out what 'highlighted' mens. Different applications use different techniques for highlighting, such as 'Selected' (in Windows terminology) or simply colored or underlined or reversed.
And all the above problems come after you have worked out how to:
1. Identify what applications are running
2. Locate the display components of those applications (the windows)
3. Extract the text from teh window
Those last three steps are possible, but not for all applications, and with a lot of complexity. The rest of your problem is a lot more difficult. In fact, I do not think it is doable without changing the design so that the user somehow indicates that some text has been highlighted and should now be copied.
My preferred approach would be to install a keyboard hook so that you can intercept a speciifc key combination, which the user will use to indicate that something has been highlighted and should be copied. When that happens, find the window that currently has the focus and scrape it for any highlighted text.
But how to make it PossibleMy preferred approach would be to install a keyboard hook so that you can intercept a speciifc key combination , which the user will use to indicate that something has been highlighted and should be copied. When that happens, find the window that currently has the focus and scrape it for any highlighted text.
But how to make it Possible
Basically, don't do what you're doing now, do it that way.- Hi KFrostILEM !
i want to make a Dictionary In the Future, so i m collect data obout every thing Possible.
So during visit any website, Chating Whatever Any word if i cant understand then i m make
Highlight it then My Application pick it autmeticly And search the meaning of word autometicly,
after this it show the meaning......
i m explain you again , if you want to focus my Thread or Question
if you have instal Internet Explorer 8
in this Explorer You Highlight any Text Its give SOme Option to translate it...
check it out.....- That requires use action to initiate the translation. Your application has to operate without user action.
That requires use action to initiate the translation. Your application has to operate without user action.
yes OfcourceCan any One guide Me ! WHAT is Windows API.
Can ANy one Tech me ABout Windows API With Code Example (tutorial Project Example)
Please Include !!!!! Few Project Example As Tutorial...
Thanks- Do you mean accessing windows API functions from a Visual Basic .Net application?
If so, try this:
http://msdn.microsoft.com/en-us/library/172wfck9.aspx
Visual Basic Programming GuideWalkthrough: Calling Windows APIs - Make Any Application With Using API Function !
Make any Application Where we Using it
www.shariqdon.media.officelive.com

