How can I receive the line and the column, in which the cursor is ? Is there there a certain message, which one has to be send to the RichEditControl ? And if it's like that, which message is that ? :confused:
Posted on 2002-06-17 01:20:41 by Marwin
if i am not wrong,
it is SendMessage to the richedit with the meassge EM_GETLINGCOUNT
Posted on 2002-06-17 02:47:41 by roticv
This is the code I use to handle the line count diusplay in one of my editors.
; ###########################################################################


Update_Line_Count proc

LOCAL Cr:CHARRANGE
LOCAL lp:DWORD
LOCAL ci:DWORD
LOCAL lcnt[16]:BYTE
LOCAL colc[16]:BYTE
LOCAL rslt[32]:BYTE

invoke SendMessage,hEdit,EM_EXGETSEL,0,ADDR Cr
invoke SendMessage,hEdit,EM_EXLINEFROMCHAR,0,Cr.cpMin
inc eax
mov lp, eax
invoke SendMessage,hEdit,EM_LINEINDEX,-1,0
mov ci, eax

.data
ulcLN db "ln ",0
ulcCOL db ". col ",0
.code

invoke dwtoa,lp,ADDR lcnt
mov eax, ci
sub Cr.cpMax, eax
invoke dwtoa,Cr.cpMax,ADDR colc

mov rslt[0], 0
invoke szMultiCat,4,ADDR rslt,ADDR ulcLN,ADDR lcnt,ADDR ulcCOL,ADDR colc
invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR rslt

ret

Update_Line_Count endp

; ##########################################################################


Regards,

hutch@movsd.com
Posted on 2002-06-17 05:37:52 by hutch--
Thank you very very much for sending me this example !! :alright: After including your code in my program, I tested it (of course :tongue: ). During this I maked the point that the proc displayes wrong culomn-number when you marked a text section. Test it, and you'll see I am right. I improved this procedure and posted it here. The important thing is, that you have to transmit the received value of EM_EXLINEFORMCHAR as the wParam in the EM_LINEINDEX-message.
Explanation
Although I think that you understand this, I would explain it (maybe it can be usefull). Actually it's simple:
(1)
CR.cpMin : index of where the caret is (it's bad english, I know, sorry)
CR.cpMax : uninteresting
CursorPos : line number in which the caret is (again bad english ??)
(2)
CR.cpMin : zero-based index of the column where the caret is
To receive the column you first have to get the character-index of the line specified in eax (= CursorPos-1). Now you subtract this index from CR.cpMin (which contains the character-index where the caret is). I hope you understood it ????? Whatever! It runs and that's the main-thing.

EditWindow_UpdateLineCount PROC

LOCAL CR :CHARRANGE
LOCAL CursorPos :DWORD
LOCAL Zeile[16] :BYTE
LOCAL Spalte[16] :BYTE
LOCAL Ergebnis[32] :BYTE

pushad

;(1)
invoke SendMessage, hActiveWindow, EM_EXGETSEL, NULL, ADDR CR
invoke SendMessage, hActiveWindow, EM_EXLINEFROMCHAR, NULL, CR.cpMin
mov CursorPos, eax
inc CursorPos
;(2)
invoke SendMessage, hActiveWindow, EM_LINEINDEX, eax, NULL
sub CR.cpMin, eax

.data
Pos db "Pos: ", 0
Slash db "/", 0
.code

invoke dwtoa, CursorPos, ADDR Zeile
invoke dwtoa, CR.cpMin, ADDR Spalte

mov Ergebnis[0], 0
invoke szMultiCat, 4, ADDR Ergebnis, ADDR Pos, ADDR Zeile, ADDR Slash, ADDR Spalte
invoke SendMessage, hStatusBar, SB_SETTEXT, 0, ADDR Ergebnis

popad

RET
EditWindow_UpdateLineCount ENDP

Yours faithfully, Marwin
Posted on 2002-06-19 03:35:57 by Marwin


[...]
Yours faithfully, Marwin


To Marwin:

Wo hast du denn das rauskopiert? *gggg*
Musst nicht gleich auf den Knien for ihm rumrutschen :)

mfG,
bAZiK
Posted on 2002-06-19 03:46:42 by bazik
Ha ha ha ha :cool:
Posted on 2002-06-19 03:59:57 by Marwin
Strange you had problems with it, it works in the asm editor I wrote it in perfectly. I set the column count when the caret is at the left side of the window to zero, top line is always one.

The normal position when the editor is opened in line 1, column zero.

Regards,

hutch@movsd.com
Posted on 2002-06-19 08:45:40 by hutch--
Ok, but mark a text and you'll see that a bad column-count is printed in the statusbar
Posted on 2002-06-20 05:04:59 by Marwin
I have never had a problem with this code but there is a trick in how you update the count. If you directly trap the key strokes, you get a 1 character lag so the position is always the last one before the position the caret is in.

What I do is set a flag and handle the call to update the line count in the main message loop if the flag is set.


; -------------------------------
; if flag set, update line count
; -------------------------------
cmp lcFlag, 1
jne @F
invoke Update_Line_Count
mov lcFlag, 0
@@:

You set the flag whereever you need to update the line count from in places like the subclass for the edit control with both keystrokes and mouse clicks. ALso set it on file open, save and other actions that will change the edit controls content.

Regards,

hutch@movsd.com
Posted on 2002-06-20 09:27:10 by hutch--
I am creating an editor that uses MDI. Can anyone tell me which message do you interpet, so as to update the details in the status bar when the selection changed. Thank you
Posted on 2002-06-21 08:54:58 by roticv
In my program I use the messages WM_CHAR (selecting with the keyboard) and WM_MOUSEMOVE (selecting with the mouse). If it receives this messages, it calls the procedure to update the line-count (or in your program to update the selection range.:tongue:
Posted on 2002-06-24 02:29:28 by Marwin