Why doesn't hWnd work at the function: GetDlgItemInt ?


.386

.model flat,stdcall
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\windows.inc

includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
ClassName db "DLGCLASS",0
MenuName db "MyMenu",0

; -------------------------------------
; IMPORTANT that your DlgName is THE
; SAME as the AppName in your RESOURCE
; FILE !!!
; Otherwise your window WON?T SHOW !!!
; Here we write: DlgName db "Convert",0
; -------------------------------------
DlgName db "Convert",0
AppName db "Convert v1.0 by Ib Larsen",0
Caption db "Exit Program",0
Text db "Really want to quit ?",0



.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
lpSuccessorFailure db ?
DEC_Buffer db 32 dup (?)
ASCII_Buffer db 32 dup (?)


.const
IDC_EDIT_1 equ 4001
IDC_EDIT_2 equ 4002
IDC_EXIT equ 3014
IDC_DEC equ 3001

.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 GetDlgItem,hDlg,IDC_EDIT_1
invoke SetFocus,eax
invoke ShowWindow, hDlg,SW_SHOWNORMAL
invoke UpdateWindow, hDlg
.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

cmp uMsg,WM_COMMAND
jnz @F
mov eax,wParam
cmp ax,IDC_EXIT
jnz @F
CALL ExitProc
ret
@@: cmp ax,IDC_DEC
jnz @F
CALL InputProc
CALL OutputProc
ret

@@: invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret

WndProc endp



ExitProc proc

invoke MessageBox,NULL,addr Text,addr Caption,MB_YESNO OR MB_SYSTEMMODAL
cmp eax,IDNO
je NO
invoke ExitProcess,eax
NO: ret

ExitProc endp





;This procedure determines which button is pushed,
;and pass the value accordingly to the Convert_proc.
InputProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
cmp ax,IDC_DEC
jnz DefaultProc
invoke GetDlgItemInt,hWnd,IDC_EDIT_1,addr lpSuccessorFailure,TRUE
cmp lpSuccessorFailure,TRUE
jnz DefaultProc
mov dword ptr [DEC_Buffer],eax
ret

; cmp ax,IDC_HEX
; jnz Default_Proc
; invoke GetDlgItemInt,hWnd,IDC_EDIT_2,addr lpSuccessorFailure,TRUE
; cmp lpSuccessorFailure,TRUE
; jnz Default_Proc
; mov dword ptr [HEX_Buffer],eax
; ret

; cmp ax,IDC_BIN
; jnz Default_Proc
; invoke GetDlgItemInt,hWnd,IDC_EDIT_3,addr lpSuccessorFailure,TRUE
; cmp lpSuccessorFailure,TRUE
; jnz Default_Proc
; mov dword ptr [BIN_Buffer],eax
; ret

; cmp ax,IDC_ASCII
; jnz Default_Proc
; invoke GetDlgItemInt,hWnd,IDC_EDIT_4,addr lpSuccessorFailure,TRUE
; cmp lpSuccessorFailure,TRUE
; jnz Default_Proc
; mov dword ptr [ASCII_Buffer],eax

DefaultProc: invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret

InputProc endp






; This procedure converts input from a buffer, and pass this value
; to the Output_proc.

;Convert_Proc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
;DEC_to_HEX:
;DEC_to_Bin:
;DEC_to_ASCII:
; invoke GetDlgItemInt,hWnd,IDC_EDIT_1,addr lpSuccessorFailure,TRUE
; cmp lpSuccessorFailure,TRUE
; jnz DefWndPr
; mov dword ptr [ASCII_Buffer],eax

;DefWndPr: invoke DefWindowProc,hWnd,uMsg,wParam,lParam
; ret


;HEX_to_DEC:
;HEX_to_BIN:
;HEX_to_ASCII:


;BIN_to_DEC:
;BIN_to_HEX:
;BIN_to_ASCII:


;ASCII_to_DEC:
;ASCII_to_HEX:
;ASCII_to_BIN:

;Convert_Proc endp







OutputProc proc

ret

;IDC_EDIT_1:

;IDC_EDIT_2:

;IDC_EDIT_3:

;IDC_EDIT_4:

OutputProc endp







;Default_Proc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

; invoke DefWindowProc,hWnd,uMsg,wParam,lParam
; ret

;Default_Proc endp


end start
Posted on 2004-12-02 07:44:58 by The SharK
little hint ...CALL InputProc
but the definition of InputProc in ur source is
proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
Posted on 2004-12-02 08:07:31 by Allanon
Hi Allanon


okay


This works:
InputProc proto :DWORD,:DWORD,:DWORD,:DWORD

            invoke InputProc,hWnd,IDC_EDIT_1,addr lpSuccessorFailure,TRUE



But if I want to use CALL instead of invoke, how do I do that, like:

            push hWnd

push IDC_EDIT_1
push addr lpSuccesorFailure
push TRUE
CALL InputProc


regards,

The SharK
Posted on 2004-12-02 09:06:38 by The SharK
You have reversed the parameters.
Posted on 2004-12-02 09:08:22 by Sephiroth3
Thanks Sephiroth3


That sure helped ;-)
Posted on 2004-12-02 11:51:54 by The SharK
From the Win32 Programmer's Reference:

HWND CreateDialogParam(


HINSTANCE hInstance, // handle to application instance
LPCTSTR lpTemplateName, // identifies dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc, // pointer to dialog box procedure
LPARAM dwInitParam // initialization value
);


You will notice that the 4th parameter must be a pointer to the dialog box procedure. You used NULL when you called the function. The WndProc used when you registered your "window class" may never see the messages generated for the dialog box, which is in a class of its own.

Furthermore, if the dialog box is the only "window" you are using, there is no need to register a separate window class.

Raymond
Posted on 2004-12-02 19:55:14 by Raymond
Hi Raymond !


Thanks for the advice about the fourth parameter,
I have overlooked that.


Furthermore, if the dialog box is the only "window" you are using, there is no need to register a separate window class. 



If I remove all the wc stuff, then the Dialog won't show :-(
It's the only "window" for the program, except for a MessageBox ;-)

regards,

The SharK
Posted on 2004-12-04 06:58:59 by The SharK