CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Location
    Madrid - Spain
    Posts
    28

    Sending WM_COPY message to IE.

    Hello gurus,

    In short:
    Sending WM_COPY message from my app to Word, Excel or Notepad works. But sending it to Internet Explorer, Firefox or Outlook Express does not work: the clipboard remains unchanged.

    In long:
    I'm writing the following application:
    - no visible user interface
    - when the user is over any text on any other app (Word, Access, Internet Explorer, Outlook...), he selects a telephone number, he presses F9, and the computer will make the call to that number for him.
    (Image you are browsing a hotel's site, you want to contact it, on the web page you see the phone to call, so you just select it and press F9! I find it nice)

    · There's no problem from the telephony point of view (CTI).
    · I'm also able to "listen" that the user has pressed F9, no matter which application had the focus (I hook the WM_CHAR message of any window using the idea found here: http://www.codeproject.com/system/KeyLogger.asp)
    · And I can also send a WM_COPY message to that window where F9 has been pressed, so that I load the selected text up to the clipboard. (code below)
    · Then I can retrieve the content of the clipboard (code found here: http://www.codeproject.com/clipboard...clipboard1.asp ) and, if it is a phone number, I order the makeCall.

    My problem is, as I said:
    This works fine with MS Word, Excel, Notepad... BUT sending WM_COPY message to Internet Explorer, Firefox & Outlook Express does not work: the clipboard remains unchanged.
    I also tried to send this message recursively not only to the actual focused window, but also to all of its parents. But it still does not work.
    I also tried to PostMessage, instead of SendMessage, but this didn't work either.

    Are these applications somehow "protected" against sending messages to their message-queues?
    Any ideas on how could I solve my problem or a better approach?

    Thank you!

    Ricardo Vázquez.
    Madrid, Spain.

    Code:
    // (as you see most of it is commented out: 
    // I tried so many messages to send...
    // This works fine with: Notepad, MS Word & Excel
    // but it doesn't work with: Internet Explorer, Firefox & Outlook express)
    
      HWND hTemp = m_hWinInFocus;
      do
       {
       sendCtrlCopy(hTemp))
       }
      while(hTemp = ::GetParent(hTemp));
    
    (...)
    
    BOOL CHookF9::sendCtrlCopy(HWND wnd)
    {
     BOOL bRes = FALSE;
    
     /*
     ::SendMessage(wnd, WM_KEYDOWN, 0x11, 0x1D0001);
     ::SendMessage(wnd, WM_KEYDOWN, 0x11, 0x401D0001);
     ::SendMessage(wnd, WM_KEYDOWN, 0x43, 0x2E0001);
     ::SendMessage(wnd, WM_CHAR, 0x3, 0x2E0001);
     ::SendMessage(wnd, WM_KEYUP, 0x43, 0xC02E0001);
     ::SendMessage(wnd, WM_KEYUP, 0x11, 0xC01D0001);
     */
    
     ::SendMessage(wnd, WM_COPY, 0x00, 0x00);
    
     /*
     bRes = ::PostMessage(wnd, WM_KEYDOWN, 0x11, 0x1D0001);
     if (!bRes) return FALSE;
     bRes = ::PostMessage(wnd, WM_KEYDOWN, 0x11, 0x401D0001);
     if (!bRes) return FALSE;
     bRes = ::PostMessage(wnd, WM_KEYDOWN, 0x43, 0x2E0001);
     if (!bRes) return FALSE;
     bRes = ::PostMessage(wnd, WM_CHAR, 0x3, 0x2E0001);
     if (!bRes) return FALSE;
     bRes = ::PostMessage(wnd, WM_KEYUP, 0x43, 0xC02E0001);
     if (!bRes) return FALSE;
     bRes = ::PostMessage(wnd, WM_KEYUP, 0x11, 0xC01D0001);
     if (!bRes) return FALSE;
     bRes = ::PostMessage(wnd, WM_COPY, 0x00, 0x00);
     if (!bRes) return FALSE;
     */
    
     return TRUE;
    }

  2. #2
    Join Date
    Nov 2007
    Posts
    1

    Re: Sending WM_COPY message to IE.

    Hello,
    I've been writing a similar application and I have encountered the same problem. Does anybody know how to solve this issue?

    In my opinion some applications (like IE, FireFox or Outlook) have some special controls (for instance for HTML page rendering) which do not handle the WM_COPY message.

    I have found a post explaining how to solve this problem for IE:
    http://groups.google.com/group/borla...7e166d45e6cddb

    Nevertheless it is not a general solution. Is it even possible to create a general solution of this issue?

    Thanks in advance.

    Mirek Vavruska
    Czech Republic


    PS: here's my code (calling of the Win API from C#)

    Code:
    // Get the top-most window
    IntPtr topWindowHandle = GetForegroundWindow();
    
    // Get the ThreadInfo structure
    GUITHREADINFO threadInfo = new GUITHREADINFO();
    threadInfo.cbSize = (uint)Marshal.SizeOf(threadInfo);
    GetGUIThreadInfo(0, out threadInfo);
    
    // Send WM_COPY message to the control with focus
    SendMessage(threadInfo.hwndFocus, WM_COPY, 0, 0);

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

Featured