Hello
I try to remove the last char in a Editcontrol with EM_xxx Messages
Withou good result.
;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,
You're one off on the value of chrg.cpMin.
;==============================================================================
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
Thanks Michael
Your example works fine but i add this code in my app works not.
I have a normal edit control not richedit
.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?
Found this mistake
EM_SETSEL for a edit control
EM_EXSETSEL for a rich edit control.