Thank you for an answer.
Antonio Donato
Hope it helped,
~Fission
You can use the WinAPI EM_CHARFROMPOS and EM_POSFROMCHAR messages to
determine where, within the RE, a particular character position is
displayed. You can use this in combination with the SelStart position
to get the caret location and with the client window coordinates to get
the character offset of the topmost visible character. Is this what you
are looking for? If not, you might want to check out
http://home.att.net/~robertdunn/Yacs.html and see if the answer is
there.
robert
Thank you.
Antonio Donato
Doctor Fission ha scritto:
thank you for your answer. I want to know the Screen Coordinates of the
SelStart in order to allow another form to open over the Rich Edit without
cover the SelStart position. The CaretPos gives the position of Caret on the
document, and not on the screen. I did not understand how it is possible to be
done from your explanation. Thank you for your attention.
Antonio Donato
Robert Dunn ha scritto:
Ok, I think that I understand. You want to get the screen coordinates
(in device units = pixels) of the starting position of the currently
selected text. I do not use TRichEdit::CaretPos, so I will offer the
following that *should* work (untested, of course).
POINT pt;
// get coordinates in client units (relative to client window)
::SendMessage(re->Handle, EM_POSFROMCHAR, (WPARAM) &pt, (LPARAM)
re->SelStart);
// convert to screen coordinates
::ClientToScreen(re->Handle, &pt);
// pt now contains screen coordinates (use pt.x & pt.y to get each)
Of course, keep in mind that the selected text may not be visible on the
screen. That is, it may be scrolled out of view in the Rich Edit
window. I *think* that, in this case, you still get valid values
relative to the client window (0, 0), but they may be completely outside
of the visible screen range.
HTH.
robert
I tried to do what you taught me, but I verified that the method ClientToScreen has
still the same problem that in previous messages. It really does not gives the
absolute position of the cursor on the screen, but the position of the cursor in the
RichEdit document added to the position of the beggining of the RichEditDocument.
Thus, if you have an A in a RichEdit scrolling near the MainMenu and its y position
converted to Screen is, for example, 304, and you scroll the document till this same
A reaches the bottom of the screen, its y position continues to be 304, the height
of the Menu plus the length of the RichEdit from its beggining to the A. What I
would like to know is if this A is the selected character, where it lies know, if it
is on the top of the screen, on the middle or on the bottom, in order that when a
new form opens over the Rich Edit, it may be opened in a y position that does not
cover the selected text. It can be easily done with horizontal coordinates, but I
would like to know how to manage it on their vertical coordinates.
If there is an answer to this question, I thank very much the attention given to it.
espvida wrote:
>
> Mr. Dunn,
>
> I tried to do what you taught me, but I verified that the method ClientToScreen has
> still the same problem that in previous messages. It really does not gives the
> absolute position of the cursor on the screen, but the position of the cursor in the
> RichEdit document added to the position of the beggining of the RichEditDocument.
> Thus, if you have an A in a RichEdit scrolling near the MainMenu and its y position
> converted to Screen is, for example, 304, and you scroll the document till this same
> A reaches the bottom of the screen, its y position continues to be 304, the height
> of the Menu plus the length of the RichEdit from its beggining to the A. What I
> would like to know is if this A is the selected character, where it lies know, if it
> is on the top of the screen, on the middle or on the bottom, in order that when a
> new form opens over the Rich Edit, it may be opened in a y position that does not
> cover the selected text. It can be easily done with horizontal coordinates, but I
> would like to know how to manage it on their vertical coordinates.
>
> If there is an answer to this question, I thank very much the attention given to it.
Oh, now I understand. The coordinates are always relative to the
"virtual RE text space." (For clarity, the "caret" is the insertion
point in the RE; "cursor" usually means the mouse cursor.)
Not a problem. Simply use EM_GETFIRSTVISIBLELINE to get the character
offset of the line at the top of the visible window. Use EM_POSFROMCHAR
to get the virtual offset of this line. Subtract this value from the
value you already have for the caret position. If negative, the is
scrolled above the window. If positive, the caret is on/below the top
line (but possibly not visible, i.e., scrolled below the bottom of the
visible window).
Whatever the value, add it to the RE Top property (this gives client
coordinates). Use ClientToScreen() to convert this value to screen
coordinates. This should give what you want (keeping in mind that the
result may be offscreen).
Does that solve it?
robert
thank you very much for the time you have spend with my questions. I think that your
answer now is what I needed, but only in two days I will bi able to try it to verify. I
would like meanwhile to ask you were I may see a list of Windows Messages? I have some
books about C, C++ and C++Builder, and in them there are comments about how to use these
messages, but there is not a list of the available ones.
Robert Dunn ha scritto:
espvida wrote:
>
> thank you very much for the time you have spend with my questions. I think that your
> answer now is what I needed, but only in two days I will bi able to try it to verify. I
> would like meanwhile to ask you were I may see a list of Windows Messages? I have some
> books about C, C++ and C++Builder, and in them there are comments about how to use these
> messages, but there is not a list of the available ones.
There are hundreds, if not thousands, of messages. It is usually easier
to look up a control (such as Rich Edit) in the WinAPI help that ships
with BCB. Usually the help about the control will list messages
specific to the control. If you really want to look at a list of
messages, you can open the WinAPI help and type "WM_" into the index.
This will show you general windows messages. Other messages for
specific types of controls are prefixed with different characters, e.g.,
EM_ for edit messages (for Edit and Rich Edit controls).
HTH.
robert
I was out this lastweek, for that the delay on answer. Unhappily I did not find any section on
the C++Builder Help with the Messages of Windows API. Perhaps they are not on my copy, or I
must know something more to find them. If there is another place to find them and you know
where, I'd like to see them. About the message EM_GETFIRSTVISIBLELINE that you mentioned in a
past letter, are there not some parameters to send with it? I think that it was on that help I
do not find where they would be found. Thank you very much again.
Antonio Donato
Robert Dunn ha scritto:
> Hi, Antonio.
espvida wrote:
>
> Mr. Robert Dunn,
>
> I was out this lastweek, for that the delay on answer. Unhappily I did not find any section on
> the C++Builder Help with the Messages of Windows API. Perhaps they are not on my copy, or I
> must know something more to find them. If there is another place to find them and you know
> where, I'd like to see them. About the message EM_GETFIRSTVISIBLELINE that you mentioned in a
> past letter, are there not some parameters to send with it? I think that it was on that help I
> do not find where they would be found. Thank you very much again.
Sorry, I should have mentioned that the WinAPI help is in a separate
help file. Mine is in "C:\Program Files\Common Files\Borland
Shared\MSHelp\win32.hlp". If you do not find it there, search your
drive for win32.hlp. Also, the MS developer support site has the
information online. Go to www.microsoft.com. In the toolbar on the
left, under Information For, select developer. Then select MSDN
library. Then use the search feature on the left.
And, no, this message has no parameters (or, more accurately, the
parameters are 0's). The return value is the zero-based line number.
HTH.
robert
thank you again for your answer. I found the Windows help where you mentioned it and am going to
examine it very carefully.
Antonio Donato
Robert Dunn ha scritto:
> Hi, Antonio.