Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get the physical caret position in a TMemo, TEdit or TRichEdit Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
107
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to get the caret position of a Memo or RichEdit control? I don't mean any 
character position expressed in row and column, I mean it in pixels!

Answer:

You get the caret position in pixels (client relative) from an edit, memo or 
richedit control by sending it a EM_POSFROMCHAR message. The message parameters are 
different for a TRichEdit and TMemo/ TEdit.

1   {TRichEdit}
2   
3   var
4     pt: TPoint;
5   begin
6     with richedit1 do
7     begin
8       Perform(messages.EM_POSFROMCHAR, WPARAM(@pt), selstart);
9       label1.caption := Format('(%d, %d)', [pt.x, pt.y]);
10    end;
11  end;
12  
13  {TMemo and TEdit}
14  
15  var
16    r: LongInt;
17  begin
18    with memo1 do
19    begin
20      r := Perform(messages.EM_POSFROMCHAR, selstart, 0);
21      if r >= 0 then
22      begin
23        label1.caption := IntToStr(HiWord(r));
24        label2.caption := IntToStr(LoWord(r));
25      end;
26    end;
27  end;


The win32.hlp entries for this message are really messed up, on older versions they only showed the memo variant, on newer (e.g. the one that comes with D5) they show only the richedit variant.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC