Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


EM_GETSEL, WM_COPY brings no effect ?!

Posted on 1999-08-01
Medium Priority
Last Modified: 2013-12-03
After I hook mouse events, I need to get selected text
in the active window.
hActive = GetActiveWindow();
  if ( hActive ) {
    msgResult = SendMessage ( hActive, WM_COPY , 0, 0 );
    .... // tried to copy selection to clipboard
or this way :
    result = SendMessage ( hActive, EM_GETSEL , NULL, NULL);
    ... // tried to get selection without envolving
        // a clipboard
Both of them do nothing ! :((
WM_COPY   doesn't change clipboard's content
EM_GETSEL brings 32 bits full of 0's
On the other hand
      SendMessage ( hActive, WM_CLOSE , 0, 0 );
closes the active window immediately (as it should)

What's the reason that active windows listen's to WM_CLOSE,
but ignores WM_COPY and EM_GETSEL ?
Thank you !
Question by:geniek
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Author Comment

ID: 1404221
Btw : of course, there is some selected text in the active window ..
LVL 14

Expert Comment

ID: 1404222
This depends from Apps. Can be some Apps simple ignore
such message, or , more bad , by message as WM_COPY
delete OS from PC! But WM_CLOSE it is system message
and all Windows application (not DOS!) reacts in same
manner to it(but you can simple write Apps, that
ignore this message, too!).

Author Comment

ID: 1404223
That what I thought :(( Very possible reason.
They just don't have to react and they don't ...
How can I slove the problem in the other way ?
LVL 11

Accepted Solution

alexo earned 200 total points
ID: 1404224
WM_COPY and EM_GETSEL are specific to edit boxes.  The following explains:

An application sends the WM_COPY message to an edit control or combo box to copy the current selection to the clipboard in CF_TEXT format.  When sent to a combo box, the WM_COPY message is handled by its edit control.  This message has no effect when sent to a combo box with the CBS_DROPDOWNLIST style.

An application sends an EM_GETSEL message to get the starting and ending character positions of the current selection in an edit control.  In a rich edit control, if the selection is not entirely contained in the first 64K, use the message EM_EXGETSEL.

The EM_GETSELTEXT message retrieves the currently selected text in a rich edit control.

Other contols (windows, whatever) implement their own methods of copying data to the clipboard.  Usually by means of WM_COMMAND messages.  You can see it using a tool like Spy++.

The bad news are: there is no UNIVERSAL way of asking a an application to copy data from a window to the clipboard.

Author Comment

ID: 1404225

Thank's a lot !

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question