ok is there any way i can grab the text from a link,text,or a button caption from any app by click the mouse middle button and sending that text to textbox1 in my form?
ok is there any way i can grab the text from a link,text,or a button caption from any app by click the mouse middle button and sending that text to textbox1 in my form?
Here's a little code...
That's just to capture the middle mouse click...VB Code:
Private Sub Form_MouseDown(sender As Object, e As System.WinForms.MouseEventArgs) Select Case e.Button Case MouseButtons.Middle 'code here End Select End Sub
well i know how to make the middle button, my question is how would i be able to grab the text under the mouse curser?
That would depend.. what kind of text are we talking about?? textboxes?? labels? Actually, the form mousedown wouldnt work for that, you would essentially have to code a mousedown for every control.. or find some global way of capturing a mouse click.. Are you wanting just one word in particular?? Or just the entire text of the control you click on?
if you are talking about grabbing the text from control in OTHER applications, then that would not be possible (not easily anyway, if at all). There are APIs that can hook you into windows to get information similar to what you are talking about, but it would be a pretty extensive set of API calls to do what you are talking about
i made it easer,
is there a way (globaly - out of my app) to grab a singel highlighted word from any text and copy it to my textbox1 with my middle mouse click
Just Copy to the clipboard, thats all I know... although thats not what you're wanting...
*** ADDED - seems to be needing just a global way of capturing the mouse click in his app..
just moved from vb6 to .net ..... can you explain how?Quote:
Originally Posted by gigemboy
lol.. umm.. Cntrl+C .... (thats why i said, its not what youre wanting :) )Quote:
Originally Posted by wiz126
well LOL not like that but thats the idea :DQuote:
Originally Posted by gigemboy
How about this... is this text all contained in the same control???
huh? i don't understand?
The text that you are selecting.. you said you are highlighting it, so its selectable. Well is the text that you are able to highlight all contained inside the same control? Like the same richtextbox, or textbox, webbrowsercontrol, .. etc etc?
If it is, what control is it?? or what are the controls that are having the text that you are selecting?
yes, but the the highlighted text is in internet explorer or in word
is there a way to sendkeys.send CONTRL C while pressing the middle buton on the mouse?
Ohh so this text is outside your app?? If that's the case, then you will need API calls... even then its going to be hard getting the text.. and the text returned is going to be the entire text for the window, not the highlighted text that you want...
calls.................................what? example?Quote:
Originally Posted by gigemboy
Its a set of api calls.. like ... FindWindowEX to get window handle of outside application, then EnumChildWindows to enumerate the windows down to get the handle of the control that contains the text, then GetWindowText to retrieve the window text of the control.. not to mention grabbing just the selected text.. not sure how to go about doing that.. Theres info in the API section of this forum, but take note.. if its VB6 function delclarations, you have to change "Long" to "Integer" (what i learned from using them)
Here is the background (Thanks Joacim):
http://www.vbforums.com/showthread.php?t=359886
And here is what I ended up with:
VB Code:
Public Class frmMain ' ' SysTray SpellChecker ' Inherits System.Windows.Forms.Form Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Int32) As Int32 Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32 Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Int32, ByVal wFlag As Int32) As Int32 Const GW_HWNDNEXT As Long = 2 Const WM_COPY As Long = &H301 Const WM_PASTE As Long = &H302 Const wdDialogToolsSpellingAndGrammar As Long = &H33C Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' End Sub Private Sub NotifyIcon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon.Click Dim objWord As Object Dim objDoc As Object Dim strResult As String Dim intRetVal As Integer 'Regain the App in use (as the focus was lost comming here) SetForegroundWindow(Me.Handle.ToInt32) Dim int32GNhWnd As Int32 = GetNextWindow(Me.Handle.ToInt32, GW_HWNDNEXT) SetForegroundWindow(int32GNhWnd) 'Copy the selected text from the App in use PostMessage(int32GNhWnd, WM_COPY, vbNull, vbNull) 'Check for valid Pasted data If Not Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then MessageBox.Show("Please select some text first.", "No Text Selected", MessageBoxButtons.OK, MessageBoxIcon.Information) GC.Collect() Exit Sub End If Try 'Create a new instance of Word objWord = CreateObject("Word.Application") Select Case objWord.Version Case "9.0", "10.0", "11.0" objDoc = objWord.Documents.Add(, , 1, True) Case "8.0" objDoc = objWord.Documents.Add Case Else MessageBox.Show("Your version of Word is not supported.", "Later Version Required", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) objWord.Application.Quit(True) objWord = Nothing Exit Sub End Select 'Place the Slected text into the new Word Document objDoc.Content.Text = Trim$(Clipboard.GetDataObject.GetData("System.String", True)) 'Check for missspelling If objDoc.SpellingErrors.Count <> 0 Then intRetVal = objWord.Dialogs.Item(wdDialogToolsSpellingAndGrammar).Display If intRetVal = -1 Then 'Return the result to the Clipboard strResult = objDoc.content.text strResult = strResult.Substring(0, Len(strResult) - 1) Clipboard.SetDataObject(strResult, True) ElseIf intRetVal = 0 Then 'Do nothing as User selected Cancel End If Else 'Spelling was correct MessageBox.Show("Spelling for '" & Clipboard.GetDataObject.GetData("System.String", True) & "' is correct.", "Correct", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) End If 'Clean up objDoc.Close(False) objDoc = Nothing objWord.Application.Quit(True) objWord = Nothing GC.Collect() Catch 'Handle Errors Catch ex As Exception objDoc.Close(False) objDoc = Nothing objWord.Application.Quit(True) If Not (objWord Is Nothing) Then objWord = Nothing MessageBox.Show(ex.ToString) GC.Collect() End Try End Sub Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click Dim frmObjAbout As New frmAbout frmObjAbout.ShowDialog() frmObjAbout.Dispose() frmObjAbout = Nothing End Sub Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click Me.NotifyIcon.Visible = False GC.Collect() Application.Exit() End Sub End Class
I think its still works.... The idea was highlight a word, and click the SysTray Icon, and it would provide a list of words, or tell you it was correct!
Worked with Access, and Excel.
can you attach an example please? i can't seem to get it to work . i will much apprichiate it
Cant at the moment - sorry. All I had was a Menu on a Form. PM an I can get back to you tommorow if required.
Best of luck,
Bruce.