Results 1 to 22 of 22

Thread: grab a text from any place by clicking on middle mouse click? hook of some kinds?

  1. #1

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    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?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?

    Here's a little code...
    VB Code:
    1. Private Sub Form_MouseDown(sender As Object, e As System.WinForms.MouseEventArgs)
    2.    Select Case e.Button
    3.       Case MouseButtons.Middle
    4.       'code here
    5.    End Select
    6. End Sub
    That's just to capture the middle mouse click...

  3. #3

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    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?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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.

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  6. #6

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    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
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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..

  8. #8

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?

    Quote 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?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  9. #9
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?

    Quote Originally Posted by wiz126
    can you explain how?
    lol.. umm.. Cntrl+C .... (thats why i said, its not what youre wanting )

  10. #10

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?

    Quote 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
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  11. #11
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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???

  12. #12

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?

    huh? i don't understand?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  13. #13
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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?

  14. #14

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    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
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  15. #15

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    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?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  16. #16
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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...

  17. #17

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: grab a text from any place by clicking on middle mouse click? hook of some kinds?

    Quote 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?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  18. #18
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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)

  19. #19
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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:
    1. Public Class frmMain
    2. '
    3. '   SysTray SpellChecker
    4. '
    5.     Inherits System.Windows.Forms.Form
    6.  
    7.     Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Int32) As Int32
    8.     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
    9.     Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Int32, ByVal wFlag As Int32) As Int32
    10.  
    11.     Const GW_HWNDNEXT As Long = 2
    12.     Const WM_COPY As Long = &H301
    13.     Const WM_PASTE As Long = &H302
    14.  
    15.     Const wdDialogToolsSpellingAndGrammar As Long = &H33C
    16.  
    17.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    18.         '
    19.     End Sub
    20.  
    21.     Private Sub NotifyIcon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon.Click
    22.         Dim objWord As Object
    23.         Dim objDoc As Object
    24.         Dim strResult As String
    25.         Dim intRetVal As Integer
    26.  
    27.         'Regain the App in use (as the focus was lost comming here)
    28.         SetForegroundWindow(Me.Handle.ToInt32)
    29.         Dim int32GNhWnd As Int32 = GetNextWindow(Me.Handle.ToInt32, GW_HWNDNEXT)
    30.         SetForegroundWindow(int32GNhWnd)
    31.  
    32.         'Copy the selected text from the App in use
    33.         PostMessage(int32GNhWnd, WM_COPY, vbNull, vbNull)
    34.  
    35.         'Check for valid Pasted data
    36.         If Not Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then
    37.             MessageBox.Show("Please select some text first.", "No Text Selected", MessageBoxButtons.OK, MessageBoxIcon.Information)
    38.             GC.Collect()
    39.             Exit Sub
    40.         End If
    41.  
    42.         Try
    43.  
    44.             'Create a new instance of Word
    45.             objWord = CreateObject("Word.Application")
    46.  
    47.             Select Case objWord.Version
    48.                 Case "9.0", "10.0", "11.0"
    49.                     objDoc = objWord.Documents.Add(, , 1, True)
    50.                 Case "8.0"
    51.                     objDoc = objWord.Documents.Add
    52.                 Case Else
    53.                     MessageBox.Show("Your version of Word is not supported.", "Later Version Required", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
    54.                     objWord.Application.Quit(True)
    55.                     objWord = Nothing
    56.                     Exit Sub
    57.             End Select
    58.  
    59.             'Place the Slected text into the new Word Document
    60.             objDoc.Content.Text = Trim$(Clipboard.GetDataObject.GetData("System.String", True))
    61.  
    62.             'Check for missspelling
    63.             If objDoc.SpellingErrors.Count <> 0 Then
    64.  
    65.                 intRetVal = objWord.Dialogs.Item(wdDialogToolsSpellingAndGrammar).Display
    66.  
    67.                 If intRetVal = -1 Then
    68.                     'Return the result to the Clipboard
    69.                     strResult = objDoc.content.text
    70.                     strResult = strResult.Substring(0, Len(strResult) - 1)
    71.                     Clipboard.SetDataObject(strResult, True)
    72.                 ElseIf intRetVal = 0 Then
    73.                     'Do nothing as User selected Cancel
    74.                 End If
    75.  
    76.             Else
    77.                 'Spelling was correct
    78.                 MessageBox.Show("Spelling for '" & Clipboard.GetDataObject.GetData("System.String", True) & "' is correct.", "Correct", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
    79.             End If
    80.  
    81.             'Clean up
    82.             objDoc.Close(False)
    83.             objDoc = Nothing
    84.             objWord.Application.Quit(True)
    85.             objWord = Nothing
    86.  
    87.             GC.Collect()
    88.  
    89.         Catch
    90.  
    91.             'Handle Errors
    92.         Catch ex As Exception
    93.             objDoc.Close(False)
    94.             objDoc = Nothing
    95.             objWord.Application.Quit(True)
    96.             If Not (objWord Is Nothing) Then objWord = Nothing
    97.  
    98.             MessageBox.Show(ex.ToString)
    99.  
    100.             GC.Collect()
    101.  
    102.         End Try
    103.  
    104.     End Sub
    105.  
    106.     Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
    107.         Dim frmObjAbout As New frmAbout
    108.  
    109.         frmObjAbout.ShowDialog()
    110.  
    111.         frmObjAbout.Dispose()
    112.         frmObjAbout = Nothing
    113.  
    114.     End Sub
    115.  
    116.     Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    117.  
    118.         Me.NotifyIcon.Visible = False
    119.  
    120.         GC.Collect()
    121.  
    122.         Application.Exit()
    123.  
    124.     End Sub
    125.  
    126. End Class

  20. #20
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  21. #21

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    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
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  22. #22
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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
  •  



Click Here to Expand Forum to Full Width