After reading iczellion's tutorial on dialog boxes I still can't
work out why this dosen't work. In this program the dialog procedure
is never called and DialogBoxParam returns -1 (error) but GetLastError
returns 0 wich is ERROR_SUCESS.
rsrc.rc
test.asm
work out why this dosen't work. In this program the dialog procedure
is never called and DialogBoxParam returns -1 (error) but GetLastError
returns 0 wich is ERROR_SUCESS.
rsrc.rc
#define DS_MODALFRAME 0080h
#define WS_POPUP 80000000h
#define WS_VISIBLE 10000000h
#define WS_CAPTION 0C00000h
#define WS_CLIPSIBLINGS 4000000h
#define IDCANCEL 2
TestDialog DIALOG 6, 18, 231, 79
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Test Dialog"
FONT 8, "MS Sans Serif"
BEGIN
PUSHBUTTON "Cancel", IDCANCEL, 185, 59, 40, 14
LTEXT "Test", 501, 6, 24, 83, 12
END
test.asm
.386
.model flat,stdcall
option casemap:none
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
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
DlgProc proto :DWORD, :DWORD, :DWORD, :DWORD
DS_MODALFRAME EQU 0080h
WS_POPUP EQU 80000000h
WS_VISIBLE EQU 10000000h
WS_CAPTION EQU 0C00000h
WS_CLIPSIBLINGS EQU 4000000h
IDCANCEL EQU 2
.data
DlgName db "TestDialog",0
formatstring db "%X",0
.data?
hInstance HINSTANCE ?
Buffer db 10 dup(?)
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke DialogBoxParam, hInstance, offset DlgName,NULL,offset DlgProc,NULL
.if eax==-1
invoke GetLastError
invoke wsprintf, addr Buffer, addr formatstring, eax
invoke MessageBox, NULL, addr Buffer, NULL, MB_OK
.endif
invoke ExitProcess,eax
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_INITDIALOG
mov eax, TRUE
ret
.ELSE
mov eax,FALSE
ret
.ENDIF
DlgProc endp
end start
Actually you shouldn't get a return value for DialogBoxParam because
it only returns when the dialog is closed.
Is the window ever displayed ?
it only returns when the dialog is closed.
Is the window ever displayed ?
No the dialog is never displayed and I put a MessageBox ast the start of the dialog proc to show when it is called but it isn't, DialogBoxParam returns imediatly. I tried with a message loop but still the same.
Did you link the correct resource file? Is the ID of your dialog box defined as 'TestDialog' in .RC file?
I decompiled the resulting .exe file and found that the correct resource was in it. This has been buggin me for a while now I am just missing something so simple
Did you try?:
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_INITDIALOG
mov eax, TRUE
ret
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
DlgProc endp
end start
I had the same type of thing happen to me alot when I first started coding dialogs... from what I remember the problem was how you let windows know you processed a message... from the code above it doesn't look like your ending your DlgProc properly...
try this... (untested)
Hope that helps
JamesE
ahh CodeLover, ya beat me to it :)
try this... (untested)
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_INITDIALOG
mov eax, TRUE
ret
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax, TRUE
ret
DlgProc endp
Hope that helps
JamesE
ahh CodeLover, ya beat me to it :)
Track down the problem: use
invoke FindResource , hInstance, addr DlgName, RT_DIALOG
to see if your dialog resource can be found, then use LoadResource and DialogBoxIndirectParam.
invoke FindResource , hInstance, addr DlgName, RT_DIALOG
to see if your dialog resource can be found, then use LoadResource and DialogBoxIndirectParam.
many thanks japheth
havn't tested yet but that looks like it's going to work (or at least find out if the resource is being loaded)
havn't tested yet but that looks like it's going to work (or at least find out if the resource is being loaded)
James and CodeLover:
When and why will these two lines ever execute? :grin:
When and why will these two lines ever execute? :grin:
...
mov eax, TRUE
ret
DlgProc endp
Hi bomb01,
Your right actually, there is no point in adding that code me and CodeLover just mentioned as kudos has placed it after the code that handles the message. But to make the code a little easier to read and prevent typing redundant code, we normally have the
at the end of the proc, that way you don't have to keep typing it over and over as once the .if statement is processed (provided it doesn't go through .else) the execution will fall through.
Your question actually reminded me what I had problems with... it wasn't this ret thing, I think it's the way he has used a string to name his dialog resource.
Kudos, you might want to try this:
rsrc.rc
then...
Or if you don't want to convert you resource name to an equate style like above, you might want to try inclosing TestDialog in brackets like so:
I think the resource compiler might be thinking TestDialog is an equate when without the brackets and not an actual string like you are trying.
Anyways, I think this should clear it up for sure this time. heh
James
Your right actually, there is no point in adding that code me and CodeLover just mentioned as kudos has placed it after the code that handles the message. But to make the code a little easier to read and prevent typing redundant code, we normally have the
mov eax, TRUE
ret
at the end of the proc, that way you don't have to keep typing it over and over as once the .if statement is processed (provided it doesn't go through .else) the execution will fall through.
Your question actually reminded me what I had problems with... it wasn't this ret thing, I think it's the way he has used a string to name his dialog resource.
Kudos, you might want to try this:
rsrc.rc
#define DS_MODALFRAME 0080h
#define WS_POPUP 80000000h
#define WS_VISIBLE 10000000h
#define WS_CAPTION 0C00000h
#define WS_CLIPSIBLINGS 4000000h
#define IDCANCEL 2
#define IDD_TESTDIALOG 1000
IDD_TESTDIALOG DIALOG 6, 18, 231, 79
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Test Dialog"
FONT 8, "MS Sans Serif"
BEGIN
PUSHBUTTON "Cancel", IDCANCEL, 185, 59, 40, 14
LTEXT "Test", 501, 6, 24, 83, 12
END
then...
.386
.model flat,stdcall
option casemap:none
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
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
DlgProc proto :DWORD, :DWORD, :DWORD, :DWORD
DS_MODALFRAME EQU 0080h
WS_POPUP EQU 80000000h
WS_VISIBLE EQU 10000000h
WS_CAPTION EQU 0C00000h
WS_CLIPSIBLINGS EQU 4000000h
IDCANCEL EQU 2
IDD_TESTDIALOG 1000
.data
formatstring db "%X",0
.data?
hInstance HINSTANCE ?
Buffer db 10 dup(?)
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke DialogBoxParam, hInstance, IDD_TESTDIALOG, NULL,offset DlgProc,NULL
.if eax==-1
invoke GetLastError
invoke wsprintf, addr Buffer, addr formatstring, eax
invoke MessageBox, NULL, addr Buffer, NULL, MB_OK
.endif
invoke ExitProcess,eax
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_INITDIALOG
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax, TRUE
ret
DlgProc endp
end start
Or if you don't want to convert you resource name to an equate style like above, you might want to try inclosing TestDialog in brackets like so:
"TestDialog" DIALOG 6, 18, 231, 79
I think the resource compiler might be thinking TestDialog is an equate when without the brackets and not an actual string like you are trying.
Anyways, I think this should clear it up for sure this time. heh
James
After all that it works when I used a different resource file. The origonal one was made by lcc and seams to have got the DS_MODELFRAME equate wrong.