Author Topic: how to get current line in a RichEdit control?  (Read 972 times)

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
how to get current line in a RichEdit control?
« on: November 25, 2020, 03:52:37 AM »
   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

HSE

  • Member
  • *****
  • Posts: 1808
  • AMD 7-32 / i3 10-64
Re: how to get current line in a RichEdit control?
« Reply #1 on: November 25, 2020, 04:45:43 AM »
Reading the manual?  :biggrin:

quarantined

  • Regular Member
  • *
  • Posts: 22
Re: how to get current line in a RichEdit control?
« Reply #2 on: November 25, 2020, 05:38:31 AM »
from win32.hlp

Code: [Select]
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.
« Last Edit: November 25, 2020, 07:46:02 AM by quarantined »

jj2007

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: how to get current line in a RichEdit control?
« Reply #3 on: November 25, 2020, 08:25:31 AM »
Reading the manual?  :biggrin:

Always a good idea ;-)

mov currentLine, rv(SendMessage hRE, EM_LINEINDEX, -1, 0)

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: how to get current line in a RichEdit control?
« Reply #4 on: November 25, 2020, 08:29:54 AM »
   ty guys.  :thumbsup:

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: how to get current line in a RichEdit control?
« Reply #5 on: November 25, 2020, 08:51:16 AM »
   i had been looking into MSDN for an appropriate message bu missed EM_LININDEX message. Thanks

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: how to get current line in a RichEdit control?
« Reply #6 on: October 18, 2021, 07:52:54 PM »
    On which conditions would EM_LINEINDEX returning ERROR_SUCCESS would not return the caret line number?

jj2007

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: how to get current line in a RichEdit control?
« Reply #7 on: October 18, 2021, 08:00:03 PM »
If EM_LINEINDEX returns ERROR_SUCCESS, then your cursor is in line ERROR_SUCCESS (the value is defined in Windows.inc)

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: how to get current line in a RichEdit control?
« Reply #8 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.

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: how to get current line in a RichEdit control?
« Reply #9 on: October 18, 2021, 09:01:49 PM »
   The following code isn't working.
Code: [Select]
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   

jj2007

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: how to get current line in a RichEdit control?
« Reply #10 on: October 19, 2021, 01:14:12 AM »
   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.

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: how to get current line in a RichEdit control?
« Reply #11 on: October 19, 2021, 03:08:12 AM »
    So, ok. Here Goes an integral version of my malfunctioning app. The EditControlProc Stands as this
Code: [Select]
EditProc       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.

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: how to get current line in a RichEdit control?
« Reply #12 on: October 19, 2021, 05:19:28 AM »
    Hi. I was able to overcome my difficulties and came up with the following working code:
Code: [Select]
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