Dear Forum
I am experimenting with a dialog box using the code in Iczelion's tutorial
No. 11. I enlarged the edit box and made it multiline then tried to use the
WM_KEYDOWN function just to see how it worked. Unfortunately it didn't work.
I looked for the message in the DlgProc PROC but it never arrived. When the window
is in focus I get the message in WndProc proc but when the dialog box is active
I get nothing. The DlgProc PROC code follows. I am using vkdebug to try and get
a reading from wParam.
DlgProc PROC hWnd:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM
.if iMsg==WM_INITDIALOG
invoke GetDlgItem,hWnd,IDC_EDIT
invoke SetFocus,eax
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;My bit of code follows
.ELSEIF iMsg==WM_KEYDOWN
mov eax,wParam
PrintDec eax
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.elseif iMsg==WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif iMsg==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
.if dx==BN_CLICKED
.if eax==IDC_EXIT
invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
.elseif eax==IDC_BUTTON
invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR TestString
.endif
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
Can anyone please tell me how to get WM_KEYDOWN to work in the dialog box?
Regards,
seaview
I don't lknow if it is the right way, I have been fighting with the same issue today. Finially got it working.
You have to subclass the edit window and write your own window process to handle messages to that window, I think I said that right.
ex.
.data
.data?
hInstance dd ?
OldEdit dd ?
.code
start:
invoke GetModuleHandle,0
mov hInstance,eax
invoke DialogBoxParam,hInstance, Dlg_Main, 0, ADDR DlgProc, 0
invoke ExitProcess,00
DlgProc proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg == WM_INITDIALOG
invoke GetDlgItem,hWnd,IDC_EDIT1
invoke SetWindowLong,eax,GWL_WNDPROC,offset NewEdit
mov OldEdit,eax
.endif
.if uMsg == WM_COMMAND
mov eax,wParam
.endif
xor eax,eax
ret
DlgProc endp
NewEdit proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg == WM_KEYDOWN
invoke MESSAGEBEEP,64
.endif
invoke CallWindowProc,OldEdit,hWnd,uMsg,wParam,lParam
ret
NewEdit endp
end start
something like that....works for me anyway if someone knows a better way I would love to know..
DrPepUR
Here is a skeleton. Win32.hlp has something on the sequence key down - char - keyup, both for system and normal keys.
invoke SetWindowLong, hEdit, ; use just behind the line
GWL_WNDPROC, SubEdit ; where you create your control
mov opEdit, eax ; the old pointer, see below
SubEdit PROTO:DWORD,:DWORD,:DWORD,:DWORD ; move to proto section
opEdit dd ? ; move to data? section
SubEdit proc hwnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
SWITCH uMsg
CASE WM_KEYDOWN
; return 0
CASE WM_CHAR
; return 0
CASE WM_KEYUP
; return 0
DEFAULT
; xor eax, eax
ENDSW
invoke CallWindowProc, opEdit, hwnd, uMsg, wParam, lParam
ret
SubEdit endp