|
-
Oct 19th, 2005, 06:11 PM
#1
Thread Starter
Frenzied Member
grab a text from any place by clicking on middle mouse click? hook of some kinds?
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?
-
Oct 19th, 2005, 06:20 PM
#2
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
Here's a little code...
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
That's just to capture the middle mouse click...
-
Oct 19th, 2005, 06:41 PM
#3
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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?
-
Oct 19th, 2005, 06:48 PM
#4
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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?
Last edited by gigemboy; Oct 19th, 2005 at 06:51 PM.
-
Oct 19th, 2005, 06:53 PM
#5
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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
-
Oct 19th, 2005, 06:54 PM
#6
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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
-
Oct 19th, 2005, 07:00 PM
#7
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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..
-
Oct 19th, 2005, 07:02 PM
#8
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
 Originally Posted by gigemboy
Just Copy to the clipboard, thats all I know... although thats not what you're wanting...
just moved from vb6 to .net ..... can you explain how?
-
Oct 19th, 2005, 07:10 PM
#9
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
 Originally Posted by wiz126
can you explain how?
lol.. umm.. Cntrl+C .... (thats why i said, its not what youre wanting )
-
Oct 19th, 2005, 07:19 PM
#10
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
 Originally Posted by gigemboy
lol.. umm.. Cntrl+C .... (thats why i said, its not what youre wanting  )
well LOL not like that but thats the idea
-
Oct 19th, 2005, 07:21 PM
#11
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
How about this... is this text all contained in the same control???
-
Oct 19th, 2005, 07:27 PM
#12
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
-
Oct 19th, 2005, 07:42 PM
#13
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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?
-
Oct 19th, 2005, 07:49 PM
#14
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
yes, but the the highlighted text is in internet explorer or in word
-
Oct 19th, 2005, 08:03 PM
#15
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
is there a way to sendkeys.send CONTRL C while pressing the middle buton on the mouse?
-
Oct 19th, 2005, 08:09 PM
#16
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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...
-
Oct 19th, 2005, 08:10 PM
#17
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
 Originally Posted by gigemboy
Ohh so this text is outside your app?? If that's the case, then you will need API calls...
calls.................................what? example?
-
Oct 19th, 2005, 08:14 PM
#18
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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)
-
Oct 19th, 2005, 09:21 PM
#19
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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
-
Oct 19th, 2005, 09:24 PM
#20
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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.
-
Oct 19th, 2005, 09:32 PM
#21
Thread Starter
Frenzied Member
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
can you attach an example please? i can't seem to get it to work . i will much apprichiate it
-
Oct 19th, 2005, 09:50 PM
#22
Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?
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.
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
|