moriman
Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
|
Hi,
The following code creates a richedit control and fills it with some lines of text.
When the left mouse button is clicked in the control the main window text should be set to the 0 based text line number of the click.
It crashes on the SendMessage -> EM_CHARFROMPOS
I have tried setting the handle for the message as the edit control, as I assume is correct, it crashes. I have tried setting the handle for the message as the main window; it crashes.
I have also found that the FASM user32.inc for EM_CHARFROMPOS=0x00D7 in accordance with the SDK WinUser.h...
but...
the SDK RichEdit.h has EM_CHARFROMPOS defined as WM_USER+39 which translates to 0x0427
I tried sending the message with this WM_USER+39 value. When I use the handle of the main window it doesn't crash but always returns 0, no matter what position is clicked. Again, using the edit control's handle the app crashes.
A search here for EM_CHARFROMPOS gives no results so any help would be greatly appreciated
format PE GUI 4.0
entry start
include '%fasminc%\win32a.inc'
include '%fasminc%\Riched32.inc'
section '.code' code readable executable
start:
invoke LoadLibrary, RichEditDllName
invoke GetModuleHandle,0
mov [wc.hInstance],eax
invoke RegisterClass, wc
invoke CreateWindowEx,0,myClass,myTitle,WS_VISIBLE+WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 700, 400, NULL, NULL, [wc.hInstance],NULL
mov [hWndMain], eax
invoke InitCommonControls
invoke GetCurrentProcess
mov [hProcess], eax
msg_loop:
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateAccelerator, [hWndMain], [hAccel], msg
or eax, eax
jnz msg_loop
invoke IsDialogMessage, [hWndMain], msg
or eax, eax
jnz msg_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop
end_loop:
invoke ExitProcess,[msg.wParam]
proc wndProc hwnd,wmsg,wparam,lparam
push ebx esi edi
cmp [wmsg],WM_DESTROY
je .wmDESTROY
cmp [wmsg],WM_CREATE
je .wmCREATE
cmp [wmsg], WM_NOTIFY
je .wmNOTIFY
.wmDEFAULT:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .wmBYE
.wmNOTIFY:
mov eax, [lparam]
cmp [eax+MSGFILTER.msg], WM_LBUTTONDOWN
je .wmNwmLBD
jmp .wmDEFAULT
;************** PROBLEM AREA **********************
.wmNwmLBD:
int3 ; the four alternatives I've tried.
invoke SendMessage, [editHnd], EM_CHARFROMPOS, 0, [eax+MSGFILTER.lparam]
; invoke SendMessage, [hWndMain], EM_CHARFROMPOS, 0, [eax+MSGFILTER.lparam]
; invoke SendMessage, [editHnd], reEM_CHARFROMPOS, 0, [eax+MSGFILTER.lparam]
; invoke SendMessage, [hWndMain], reEM_CHARFROMPOS, 0, [eax+MSGFILTER.lparam]
;***************************************************
shr eax, 16 ;0 based line No. should now be in eax
stdcall Word2Asc, eax, tmpBuff
invoke SetWindowText, [hWndMain], tmpBuff
jmp .wmDEFAULT
.wmCREATE:
invoke GetClientRect, [hwnd], rect
invoke CreateWindowEx, WS_EX_CLIENTEDGE, RichEditClass, NULL, WS_CHILD+WS_VISIBLE+WS_VSCROLL+WS_HSCROLL+ES_AUTOVSCROLL+ES_AUTOHSCROLL+ES_MULTILINE+ES_WANTRETURN, [rect.left], [rect.top], [rect.right], [rect.bottom], [hwnd], NULL, [wc.hInstance], NULL
mov [editHnd], eax
invoke SendMessage,[editHnd],EM_SETEVENTMASK,0,ENM_MOUSEEVENTS ;capture mouse events in edit control
invoke SetWindowText, [editHnd], tmpStr
jmp .wmBYE
.wmDESTROY:
invoke PostQuitMessage,0
xor eax,eax
.wmBYE:
pop edi esi ebx
ret
endp
proc Word2Asc HexVal, buff
push eax ebx ecx edx edi
mov eax, [HexVal]
mov ebx, 0x0A
mov ecx, 5
@@:
xor edx, edx
div ebx
add edx, 0x30
push edx
loop @b
mov edi, [buff]
mov ecx, 5
@@:
pop eax
stosb
loop @b
pop edi edx ecx ebx eax
ret
endp
section '.data' data readable writeable
reEM_CHARFROMPOS = WM_USER+39
tmpBuff db 5 dup 'X', 0
editHnd dd ?
hWndMain dd ?
hProcess dd ?
hAccel dd ?
msg MSG
rect RECT
wc WNDCLASS 0, wndProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE+1, NULL, myClass
RichEditDllName db 'riched20.DLL', 0
RichEditClass db 'RICHEDIT20A', 0
myTitle db 'Test', 0
myClass db 'Test', 0
ENM_MOUSEEVENTS = 0x00020000
tmpStr db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A
db 'A line of text in the window', 0x0D, 0x0A, 0
struct MSGFILTER
nmhdr NMHDR
msg dd ?
wparam dd ?
lparam dd ?
ends
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
user32, 'USER32.DLL',\
gdi32, 'GDI32.DLL',\
comdlg32,'COMDLG32.DLL',\
advapi32,'ADVAPI32.DLL',\
comctl32,'COMCTL32.DLL'
include '%fasminc%\apia\Kernel32.inc'
include '%fasminc%\apia\User32.inc'
include '%fasminc%\apia\Gdi32.inc'
include '%fasminc%\apia\Comdlg32.inc'
include '%fasminc%\apia\Advapi32.inc'
include '%fasminc%\apia\Comctl32.inc'
|