Hi guys ! I'm trying to call EndDialog function when the Escape key is pressed in my dialogbox. Here is a part of my code : .IF uMsg == WM_KEYDOWN .IF wParam == VK_ESCAPE invoke EndDialog,hWin,0 It doesn't work, but it works well with VK_F1... _o I tried many things (handling WM_CHAR, etc...) but it doesn't work too... Please help... Thanks a lot :).
Posted on 2001-03-05 18:27:00 by Youpa
Youpa, Do you have a Cancel Button? If you do make it's id IDCANCEL and it should do this for you. The escape key has the functionality of cancel anyway, so I'm not sure why this isn't working for you. If you can post the dialog proc here I can help more. umbongo
Posted on 2001-03-06 04:36:00 by umbongo
Hi. Thank you for your help. I tried your tip and it doesn't work too... ;_; I'm still interested in your trick because it makes code (and exe) lighter :) even if i would like to understand the WM_KEYDOWN problem too :). I discovered something else : my previous code only works if there is no controls on the dialog (how annoying). Here's my code and my rsrc file. Please help : i can't figure this problem out :( ;######################################################################### .386 .model flat, stdcall option casemap :none ; case sensitive ; ######################################################################### include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib ; ######################################################################### WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD .data dlgname db "DLG",0 hInstance dd 0 .code start: ; ######################################################################### invoke GetModuleHandle, NULL mov hInstance, eax invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR WndProc,0 invoke ExitProcess,eax ; ######################################################################### WndProc proc hWin :DWORD, uMsg :DWORD, wParam :DWORD, lParam :DWORD .if uMsg == WM_CLOSE invoke EndDialog,hWin,0 .ELSEIF uMsg == WM_KEYDOWN .IF wParam == VK_ESCAPE ; but works with VK_F2 invoke EndDialog,hWin,0 .ENDIF .ENDIF xor eax, eax ret WndProc endp ; ######################################################################## end start --------------------- rsrc file : --------------------- #include "\masm32\include\resource.h" DLG DIALOG DISCARDABLE 10, 10, 205, 122 STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Dialog" FONT 8, "MS Sans Serif" BEGIN // PUSHBUTTON "Button1",IDCANCEL,83,54,97,13 // Doesn't work END --------------------- Thanks a lot :).
Posted on 2001-03-06 06:44:00 by Youpa
Youpa, This is quite facinating actually, I've build your code, and you're right, the escape key doesn't work. However if you place an edit control on your dialog. Set the focus to it (click in it) then hit escape - it works! I'm going to try to find out what the edit box is doing.... umbongo
Posted on 2001-03-06 07:28:00 by umbongo
ok I've got it now, when the user hits escape, they get a WM_COMMAND with a value of IDCANCEL, if they hit return they get IDOK, you have to intercept these:-

.ELSEIF uMsg == WM_COMMAND
	.if wParam ==IDOK
		invoke EndDialog,hWin,1
	.elseif wParam==IDCANCEL
		invoke EndDialog,hWin,0
	.endif
I still don't know how the edit box caused this, but maybe you need at least one control for it to work properly. (this code will work as is, no controls needed) umbongo
Posted on 2001-03-06 07:39:00 by umbongo
It works perfectly ! Thank you very much :). Youpa...
Posted on 2001-03-06 08:43:00 by Youpa