CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: get text under my mouse

  1. #1
    Join Date
    May 1999
    Location
    Germany
    Posts
    106

    get text under my mouse

    Hi,

    when i do a left click on my mouse, i need to copy the word under my mouse into clipboard.

    I saw this on babylon translater, which allows the user to click on a word (in any application) and then shows a translation of this word.

    How can i do this?

    I use a system wide hook do receive the click message, then i use WindowFromPoint to get the HWND.
    But how do i get the word under my mouse (WM_GETTEXT doesn't work)?


    Thanks
    Peter


  2. #2
    Join Date
    May 2001
    Posts
    185

    Re: get text under my mouse

    Use the hook function on WndProc()
    in this case when you receive the WM_LBUTTONDOWN you know window handle and message GetWindowText()
    for example

    LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    CWPSTRUCT* pWnd = (CWPSTRUCT*)lParam;

    switch(pWnd->message)
    {
    case WM_LBUTTONDOWN:
    {
    int iLen = GetWindowTextLength(pWnd->hwnd) + 1;
    LPTSTR s = (LPTSTR)malloc(iLen);
    GetWindowText(pWnd->hwnd, s, iLen);
    ////......
    free(s);
    }
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
    }

    Good luck.
    constructor@rambler.ru

  3. #3
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: get text under my mouse

    See AccessibleObjectFromPoint

    Rating isn't important...But gurus respect it and keep high

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)