News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Change default dblclick in richedit with this code.

Started by hutch--, November 02, 2006, 02:35:39 AM

Previous topic - Next topic

hutch--

Something that has pissed me off for a long time is the change in default behaviour in rich edit controls when you select a word by double clicking on it. Under win9x you got the word only but on later systems you get the word and any trailing spaces up to the next word. Following is code to be used in a rich edit control subclass that defeats the default behaviour so you only get the word and you have control of the characters in the word so that you can select combinations like "WM_COMMAND" and structure members like "this.that.member".



  ; the LOCAL code needed for the following code

    LOCAL ln    :DWORD
    LOCAL ll    :DWORD
    LOCAL ci    :DWORD
    LOCAL os    :DWORD
    LOCAL mn    :DWORD
    LOCAL mx    :DWORD
    LOCAL cr    :CHARRANGE
    LOCAL buf[4096]:BYTE

  ; the double click processing

    .elseif uMsg == WM_LBUTTONDBLCLK
      ; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤

        invoke SendMessage,hEdit,EM_EXGETSEL,0,ADDR cr              ; get current selection
        mov eax, cr.cpMin
        mov mn, eax

        mov ln, rv(SendMessage,hEdit,EM_EXLINEFROMCHAR,0,cr.cpMin)  ; zero-based index of the line
        mov ll, rv(SendMessage,hEdit,EM_LINELENGTH,cr.cpMin,0)      ; get the line length
        mov ci, rv(SendMessage,hEdit,EM_LINEINDEX,ln,0)             ; get 1st char offset from beginning

        mov eax, cr.cpMin                                           ; offset on line of current caret location
        sub eax, ci
        mov os, eax
        mov eax, ci
        mov cr.cpMin, eax
        add eax, ll
        mov cr.cpMax, eax

        invoke SendMessage,hEdit,EM_HIDESELECTION,1,0
        invoke SendMessage,hEdit,EM_EXSETSEL,0,ADDR cr              ; set selection
        invoke SendMessage,hEdit,EM_GETSELTEXT,0,ADDR buf           ; get selected text

        xor ecx, ecx                                                ; zero ECX + EDX
        xor edx, edx

        push esi
        lea esi, buf                                                ; load buffer address
        add esi, os                                                 ; add offset to ESI
      lbl0:
        movzx eax, BYTE PTR [esi]                                   ; scan backwards
        cmp BYTE PTR [chtbl+eax], 1                                 ; testing if acceptable character
        jne lbl1
        add ecx, 1                                                  ; count characters read backwards
        sub esi, 1
        jmp lbl0

      lbl1:
        add esi, 1                                                  ; correct for last char being non acceptable

      lbl2:
        movzx eax, BYTE PTR [esi]                                   ; scan forwards until next unacceptable character
        cmp BYTE PTR [chtbl+eax], 1
        jne lbl3
        add edx, 1                                                  ; count characters read forward
        add esi, 1
        jmp lbl2

      lbl3:
        pop esi

        sub ecx, 1
        sub mn, ecx
        mov eax, mn
        mov cr.cpMin, eax
        mov cr.cpMax, eax
        add cr.cpMax, edx

        invoke SendMessage,hEdit,EM_HIDESELECTION,0,0
        invoke SendMessage,hEdit,EM_EXSETSEL,0,ADDR cr             ; set selection

        xor eax, eax
        ret

    chtbl:
    ; -----------------------------------------
    ; upper and lower case, numbers and "_" "."
    ; -----------------------------------------
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0
      db 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
      db 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
      db 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1
      db 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
      db 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

      ; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php