?
Solved

How to grab selected text in a window

Posted on 2004-04-21
6
Medium Priority
?
235 Views
Last Modified: 2010-04-05
Is it possible to get selected text from a window without sending it to the clipboard using the keystrokes Ctrl + C?

What I do at the moment, is that I react on the mouse event WM_LBUTTONUP in windows/controls with classnames that I list in my Delphi program. At the moment of the Mouse Up Event, I also know the handle of that window/control. I send Ctrl + C to that window, but my question is: Is there another way, can the selected text be acquired with for instance the Windows messaging methods, or by other means, not including the clipboard?
0
Comment
Question by:haab
[X]
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
  • 2
6 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10882727
You could program a HotKey to get the current focused controls text, is this what your interested in?

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 1050 total points
ID: 10882800
Hotkeys:

Uses Messages;

In the main forms OnCreate handler assign the hotkey:

  If not RegisterHotkey( Handle, 1, MOD_ALT or MOD_SHIFT, VK_F9 ) Then
    ShowMessage('Unable to assign Alt-Shift-F9 as hotkey.');

In the main forms OnClose event remove the handler:

  UnRegisterHotkey( Handle, 1 );

Add a handler for the WM_HOTKEY message to the form:

  private // form declaration
    Procedure WMHotkey( Var msg: TWMHotkey );
      message WM_HOTKEY;

Procedure TForm1.WMHotkey( Var msg: TWMHotkey );
  Begin
   // If msg.hotkey =
  End;


OR

You can also use Form's onShortCut event.

procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
case msg.CharCode of
  120 : begin { F9 pressed }; Handled := true; end;
  121 : begin { F10 pressed }; Handled := true; end;
end;
end;


Current Focused control

 Form1.ActiveControl


You could simple test the control for type

 if Form1.ActiveControl is TEdit


 MyText:= TEdit(Form1.ActiveControl).Text;


Hope this helps!

Shane
0
 

Author Comment

by:haab
ID: 10882821
Well, it is only the selected text that I want. I already know how to get the entire text of controls; the problem is to grab only the selected text, and the question whether it is possible to do so without involving the clipboard.

Thank you for your kind response, both on this issue and my other question from today regarding the maintaining of clipboard formats!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:haab
ID: 10882844
I see that you have given some code as well. Thank you! I will try it out!
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10882897
Again, test for the type of focused control, then use the

 SelText property of the control

MyText:= TEdit(Form1.ActiveControl).SelText;


Shane
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 450 total points
ID: 10886683
you could use the wm_gettext-message,
this will return you the whole text of course,
not only the selection

alternativly you could try the EM_GETSELTEXT-message
(but i guess this works only for richtext-controls)

meikl ;-)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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