I'm haveing this trouble.How do i hget count of lines and the current line beign edited in a richedit control. thaks in advance for the support
Reading the manual? :biggrin:
from win32.hlp
CHARRANGE
-----------------------------------------------------------
The CHARRANGE structure specifies a range of characters in a rich edit control. This structure is used with the EM_EXGETSEL and EM_EXSETSEL messages.
If the cpMin and cpMax members are equal, the range is empty. The range includes everything if cpMin is 0 and cpMax is - 1.
typedef struct _charrange {
LONG cpMin;
LONG cpMax;
} CHARRANGE;
Members
cpMin
Index of first intercharacter position.
cpMax
Index of last intercharacter position.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EM_GETLINECOUNT
-------------------------------------------------------------
An application sends an EM_GETLINECOUNT message to retrieve the number of lines in a multiline edit control.
EM_GETLINECOUNT
wParam = 0; // not used; must be zero
lParam = 0; // not used; must be zero
Parameters
This message has no parameters.
Return Values
The return value is an integer specifying the number of lines in the multiline edit control. If no text is in the edit control, the return value is 1.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EM_EXGETSEL
-------------------------------------------------------------------
The EM_EXGETSEL message retrieves the starting and ending character positions of the selection in a rich edit control.
EM_EXGETSEL
wParam = 0;
lParam = (LPARAM) (CHARRANGE FAR *) lpchr;
Parameters
lpchr
Pointer to a CHARRANGE structure that receives the selection range.
Return Values
No return value.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EM_GETSELTEXT
---------------------------------------------------------------
The EM_GETSELTEXT message retrieves the currently selected text in a rich edit control.
EM_GETSELTEXT
wParam = 0;
lParam = (LPARAM) (LPSTR) lpBuf;
Parameters
lpBuf
Pointer to a buffer that receives the selected text. The calling application must ensure that the buffer is large enough to hold the selected text.
Return Values
Returns the number of characters copied, not including the terminating null character.
Quote from: HSE on November 25, 2020, 04:45:43 AM
Reading the manual? :biggrin:
Always a good idea ;-)
mov currentLine, rv(SendMessage hRE, EM_LINEINDEX, -1, 0)
ty guys. :thumbsup:
i had been looking into MSDN for an appropriate message bu missed EM_LININDEX message. Thanks
On which conditions would EM_LINEINDEX returning ERROR_SUCCESS would not return the caret line number?
If EM_LINEINDEX returns ERROR_SUCCESS, then your cursor is in line ERROR_SUCCESS (the value is defined in Windows.inc)
yeah jj. It's just that the line number never changes from1 no matter where i am in text.
The following code isn't working.EditProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg==WM_KEYDOWN
invoke SendMessage,hMdi,WM_MDIGETACTIVE,0,0
invoke GetWindowLong,eax,GWL_USERDATA
push eax
mov eax,rv(SendMessage,[eax.MdiStruct.hEdit],EM_LINEINDEX,-1,0)
mov word ptr [Buffer],0
mov lpBuffer,offset Buffer
mov lpBuffer,cat$(offset Buffer,"ln ",str$(eax))
pop eax
invoke SetWindowText,[eax.MdiStruct.hStatic],addr Buffer
jmp cwp
.else
cwp:
invoke CallWindowProc,lpOldEditProc,hWnd,uMsg,wParam,lParam
.endif
mov eax,1
ret
EditProc endp
Quote from: xandaz on October 18, 2021, 08:14:30 PM
yeah jj. It's just that the line number never changes from1 no matter where i am in text.
That's really mysterious. If you post a full working example, I'll have a look.
So, ok. Here Goes an integral version of my malfunctioning app. The EditControlProc Stands as thisEditProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg==WM_KEYDOWN
show_line:
invoke SendMessage,hMdi,WM_MDIGETACTIVE,0,0
invoke GetWindowLong,eax,GWL_USERDATA
mov edi,eax
mov eax,rv(SendMessage,hWnd,EM_LINEINDEX,-1,0)
invoke SendMessage,hWnd,EM_EXLINEFROMCHAR,0,eax
inc eax
mov word ptr [Buffer],0
mov lpBuffer,offset Buffer
mov lpBuffer,cat$(lpBuffer,"ln ",ustr$(eax))
invoke SetWindowText,[edi.MdiStruct.hStatic],addr szEmptyString
invoke SetWindowText,[edi.MdiStruct.hStatic],lpBuffer
jmp cwp
.elseif uMsg==WM_LBUTTONDOWN
jmp show_line
.else
cwp:
invoke CallWindowProc,lpOldEditProc,hWnd,uMsg,wParam,lParam
ret
.endif
mov eax,1
ret
EditProc endp
It skips some lines and also, when i get cursor one line up it still increases.
Hi. I was able to overcome my difficulties and came up with the following working code:EditProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg==WM_KEYDOWN
show_line:
invoke CallWindowProc,lpOldEditProc,hWnd,uMsg,wParam,lParam
invoke SendMessage,hMdi,WM_MDIGETACTIVE,0,0
invoke GetWindowLong,eax,GWL_USERDATA
mov edi,eax
mov eax,rv(SendMessage,hWnd,EM_LINEINDEX,-1,0)
mov eax,rv(SendMessage,hWnd,EM_EXLINEFROMCHAR,0,eax)
inc eax
mov word ptr [Buffer],0
mov lpBuffer,offset Buffer
mov lpBuffer,cat$(lpBuffer,"ln ",ustr$(eax))
invoke SetWindowText,[edi.MdiStruct.hStatic],addr szEmptyString
invoke SetWindowText,[edi.MdiStruct.hStatic],lpBuffer
ret
.elseif uMsg==WM_LBUTTONDOWN
jmp show_line
.else
cwp:
invoke CallWindowProc,lpOldEditProc,hWnd,uMsg,wParam,lParam
ret
.endif
mov eax,1
ret
EditProc endp