I have been reading Iczelion's tuts and I have come to number 10.

It compiles fine, runs fine, except that when I hit enter...the application closes.

Simple Question....how do I keep it from closing????

I have tried to catch a WM_KEYDOWN and WM_CHAR but this doesn't work either.

I can't figure it out...I've searched this forum for DEFPUSHBUTTON but I haven't found anything.

If this has already been answer please let me know Posted on 2002-08-20 15:00:13 by gorshing
Hi,

after looking at your code I noticed the following:



.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF lParam==0
.IF ax==IDM_GETTEXT
invoke GetDlgItemText,hWnd,IDC_EDIT,ADDR buffer,512
invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK
.ELSEIF ax==IDM_CLEAR
invoke SetDlgItemText,hWnd,IDC_EDIT,NULL
.ELSE <-------------------
invoke DestroyWindow,hWnd <-------------------
.ENDIF




Why is this in there? Comment it out, try again, and you'll see, that your app will stay there :)

HTH

Greets YaWNS
Posted on 2002-08-20 15:09:50 by YaWNS
Ok, cool ... my app stays up( that was pretty stupid on my part ), but the default button still doesn't work.

But what message am I letting get through?

I thought that the 'enter' key would eventually be turned into a BN_CLICKED message with the source being IDC_BUTTON.

But it is acting as though it was a Menu command ( since lParam == 0 ) not the control.

Sorry but I'm still a little confused. But thanks for that help though.

gorshing
Posted on 2002-08-21 09:14:12 by gorshing
Hi,

I have another suggestion for your code.



.ELSE
mov edx,wParam
shr edx,16
.IF dx==BN_CLICKED
<------------------------------------------------->
push eax
invoke MessageBox, hWnd, NULL, NULL, MB_OK
pop eax
<------------------------------------------------->
.IF ax==IDC_BUTTON
invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR TestString
.ELSEIF ax==IDC_EXIT
invoke SendMessage,hWnd,WM_COMMAND,IDM_EXIT,0
.ENDIF
.ENDIF
.ENDIF



If you add push eax and pop eax, then you can keep your messagebox popping up, before entering the text into the edit box. If you don't preserve EAX, then the MessageBox Function will mess up EAX and your code never recognizes, which button has been pushed.

Greets YaWNS
Posted on 2002-08-21 10:50:08 by YaWNS
ok this is what I have now



.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
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
.data
ClassName db "DLGCLASS",0
MenuName db "MyMenu",0
DlgName db "MyDialog",0
AppName db "Our First Dialog Box",0
TestString db "Wow! I'm in an edit box now",0

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
buffer db 512 dup(?)

.const
IDC_EDIT equ 3000
IDC_BUTTON equ 3001
IDC_EXIT equ 3002
IDM_GETTEXT equ 32000
IDM_CLEAR equ 32001
IDM_EXIT equ 32002

.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hDlg:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,DLGWINDOWEXTRA
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateDialogParam,hInstance,ADDR DlgName,NULL,NULL,NULL
mov hDlg,eax
invoke ShowWindow, hDlg,SW_SHOWNORMAL
invoke UpdateWindow, hDlg
invoke GetDlgItem,hDlg,IDC_EDIT
invoke SetFocus,eax
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke IsDialogMessage, hDlg, ADDR msg
.IF eax ==FALSE
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDIF
.ENDW
mov eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF lParam==0
.IF ax==IDM_GETTEXT
invoke GetDlgItemText,hWnd,IDC_EDIT,ADDR buffer,512
invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK
.ELSEIF ax==IDM_CLEAR
invoke SetDlgItemText,hWnd,IDC_EDIT,NULL
.ELSEIF ax==IDM_EXIT
invoke PostQuitMessage, NULL
.ENDIF
.ELSE
mov edx,wParam
shr edx,16
.IF dx==BN_CLICKED
.IF ax==IDC_BUTTON
invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR TestString
.ELSEIF ax==IDC_EXIT
invoke SendMessage,hWnd,WM_COMMAND,IDM_EXIT,0
.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start


I have taken out all those MessageBoxes that were causing confusion. But the default button still doesn't work. I do get a WM_COMMAND but i hit enter, and ax contains 1. This doesn't make sense to me. Anybody else know what I am missing?

Thanks again Yawns,
gorshing
Posted on 2002-08-21 13:07:26 by gorshing
I have found my answer! I don't know if anybody knows this, but since no one has replied .....


From Petzold's book

If no push button in the dialog box is the default push button, Windows sends the dialog box procedure a WM_COMMAND message with the LOWORD of wParam equal to IDOK.

Page 508


IDOK is equal to 1.

But now I have another question, I do have a DEFPUSHBUTTON, so why is this happening?

Later, in search of truth
Posted on 2002-08-23 14:25:42 by gorshing
I believe it's the invoking of IsDialogMessage. This function is supposed to implement the standard dialog keyboard functions, such as tabbing to marked fields and converting ENTERs to IDOK commands.
Posted on 2002-08-26 04:31:17 by tenkey