Author Topic: Remove last char  (Read 2454 times)

ragdog

  • Member
  • ****
  • Posts: 610
Remove last char
« on: September 08, 2012, 06:42:15 PM »
 Hello

I try to remove the last char in a Editcontrol with EM_xxx Messages
Withou good result.


Code: [Select]
;set the cursor in the end of the rich edit text
invoke    SendMessage,hWnd,WM_GETTEXTLENGTH,0,0

mov chrg.cpMin, eax
mov chrg.cpMax, eax

invoke SendMessage, hWnd, EM_EXSETSEL, 0, addr chrg
invoke SendMessage, hWnd, EM_REPLACESEL, FALSE,0

Any idea?

Greets,


MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Remove last char
« Reply #1 on: September 08, 2012, 08:15:21 PM »
You're one off on the value of chrg.cpMin.
Code: [Select]
;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================
IDC_RE equ 100
;==============================================================================

  ;----------------------------------------------------------------------
  ; This is a general-purpose control definition macro that adds support
  ; for controls of any type to the MASM32 In-Memory Dialogs. For this
  ; macro the control class is specified as a quoted string, instead of
  ; being hard coded.
  ;----------------------------------------------------------------------

    DlgControl MACRO quoted_caption,quoted_class,dstyle,tx,ty,wd,ht,ctlID
      align_4 edi
      mov DWORD PTR [edi+0],  WS_VISIBLE or WS_CHILD or dstyle
      mov WORD  PTR [edi+8],  tx
      mov WORD  PTR [edi+10], ty
      mov WORD  PTR [edi+12], wd
      mov WORD  PTR [edi+14], ht
      mov WORD  PTR [edi+16], ctlID
      add edi, 18
      ustring quoted_class
      ustring quoted_caption
      ;-------------------------------------------
      ; Advance edi past the creation data array.
      ;-------------------------------------------
      add edi, 2
    ENDM

;==============================================================================
    .data
      hInst   dd 0
      hwndRE  dd 0
      chrg    CHARRANGE <>
    .code
;==============================================================================

DlgProc proc hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    LOCAL rc:RECT

    SWITCH uMsg

        CASE WM_INITDIALOG

            invoke GetClientRect, hwndDlg, ADDR rc
            invoke GetDlgItem, hwndDlg, IDC_RE
            mov hwndRE, eax

            invoke SendMessage, hwndRE, EM_EXLIMITTEXT, 1000000, 0

        CASE WM_SYSCOMMAND

            ;-----------------------------------------------------------------
            ; Clicking the title bar will send WM_SYSCOMMAND every 2nd click.
            ;-----------------------------------------------------------------

            invoke SendMessage, hwndRE, WM_GETTEXTLENGTH, 0, 0

             mov chrg.cpMax, eax
             dec eax
             mov chrg.cpMin, eax

            invoke SendMessage, hwndRE, EM_EXSETSEL, 0, ADDR chrg
            invoke SendMessage, hwndRE, EM_REPLACESEL, FALSE, 0

        CASE WM_SIZE

            invoke GetClientRect, hwndDlg, ADDR rc
            invoke MoveWindow, hwndRE, 0, 0, rc.right, rc.bottom, TRUE

        CASE WM_COMMAND

            SWITCH wParam
                Case IDCANCEL
                    invoke EndDialog, hwndDlg, NULL
            ENDSW

        CASE WM_CLOSE

            invoke EndDialog, hwndDlg, NULL

    EndSw

    return 0

DlgProc endp

;==============================================================================
start:
;==============================================================================

    invoke LoadLibrary, chr$("RICHED20.DLL")

    invoke GetModuleHandle, NULL
    mov hInst, eax

    Dialog  0, \
            "Courier New",8, \
            WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
            1, \
            0,0,200,150, \
            1024

    DlgControl 0, \
               "RichEdit20A", \
               WS_VSCROLL or \
               WS_HSCROLL or \
               ES_SUNKEN or \
               ES_MULTILINE or \
               ES_AUTOVSCROLL or \
               ES_AUTOHSCROLL or \
               ES_NOHIDESEL or \
               ES_WANTRETURN, \
               0,0,0,0,IDC_RE

    CallModalDialog hInst, 0, DlgProc, NULL
    exit

;==============================================================================
end start
Well Microsoft, here’s another nice mess you’ve gotten us into.

ragdog

  • Member
  • ****
  • Posts: 610
Re: Remove last char
« Reply #2 on: September 09, 2012, 12:50:59 AM »
Thanks Michael

Your example works fine but i add this code in my app works not.

I have a normal edit control not richedit

Code: [Select]
.data?

.code
..
.

.if uMsg==WM_INITDIALOG
invoke    GetDlgItem,hWnd,1001
       mov    hEdit,eax
    .elseif uMsg==WM_COMMAND
           .if wParam==1002
           invoke SendMessage, hEdit, WM_GETTEXTLENGTH, 0, 0
                  mov chrg.cpMax, eax
                  dec eax
                  mov chrg.cpMin, eax

               invoke SendMessage,hEdit, EM_EXSETSEL, 0, ADDR chrg
               invoke SendMessage,hEdit, EM_REPLACESEL, FALSE, 0
           .endif

Or work this only with a richedit?


ragdog

  • Member
  • ****
  • Posts: 610
Re: Remove last char
« Reply #3 on: September 09, 2012, 01:18:15 AM »
Found this mistake

EM_SETSEL for a edit control
EM_EXSETSEL for a rich edit control.