These two macros go well together and simplify things alot.
.end macro _start, _args:vararg

;; When creating a top-level window (hparent = 0), store the hwnd in g_hwnd
;; Store the haccel (if any) in g_haccel. Multi window pgms can process the
;; WM_SETFOCUS/WM_ACTIVATE message(s) to keep these values updated!
;; ** the next macro 'waitquitmsg' requires these values to be set!

;; Do the same for modeless dialogs but store the hwnd in g_hdlg!

.data?
cmdlin dd ? ; ptr to coomand tail - NO path/name
exename dd ? ; ptr to full name of exec file
g_haccel dd ? ; HACCEL of active window
g_hdlg dd ? ; HDLG of active modeless dialog
g_hinst dd ? ; HINSTANCE of module
g_hwnd dd ? ; HWND of active window

includelib shlwapi

.code
_start0:
invoke GetModuleHandle, 0
mov g_hinst, eax
invoke GetCommandLine
mov exename, eax
push eax
call PathGetArgs
mov cmdlin, eax
push exename
call PathRemoveArgs

$start equ _start
ifb <_start>
ifdef WinMain
$start equ <WinMain> ;; gui
elseifdef main
$start equ <main> ;; console
else
.err "Must define main or WinMain"
endif
endif

ifb <_args>
call $start
else
invoke $start, _args
endif

invok ExitProcess, eax
end _start0
endm


waitquitmsg macro
.data?
msg0 MSG {}
.code
.while 1
invoke GetMessage, @ msg0, 0, 0, 0
.break .if eax == 0
invoke IsDialogMessage, g_hdlg, @ msg0
.cont .if eax
invoke TranslateAccelerator, msg0.hwnd, g_haccel, @ msg0
.cont .if eax
invoke TranslateMessage, @ msg0
switch msg0.wParam
case VK_SHIFT, VK_CTRL
.if msg0.message == WM_KEYDOWN
or KEY_SHFT[eax - VK_SHIFT], 1
.elseif msg0.message == WM_KEYUP
and KEY_SHFT[eax - VK_SHIFT], 0
.endif
endsw
invoke DispatchMessage, @ msg0
.endw
return msg0.wParam
endm

Usage:

WinMain:
; do you're initialization ...
; create windows whatever ...
waitquitmsg
; 'waitquitmsg' has a built in return

.end


Greg,

Just fixed a spelling mistake in the title.
Posted on 2002-07-12 15:06:26 by gfalen
Update:
Moved msg0 to the .end macro. Added default struct - wc0:WNDCLASSEX
Deleted some legacy code copied by mistake
Added public declarations to be added to masm32.inc.



; macro to make public declarations easier.
global macro _typ, _lst:vararg ;; global type, var1, var2...
irp $v, <_lst>
externdef $v:_typ
endm
endm

; ** These 2 lines should go in masm32.inc.
; Note: This will make them visible to library modules too!
global dword, cmdlin, exename, g_haccel, g_hdlg, g_hinst, g_hwnd
externdef msg0:MSG: wc0:WNDCLASSEX


; When creating a top-level window (hparent = 0), store the hwnd in g_hwnd
; Store the haccel (if any) in g_haccel. Multi window pgms can process the
; WM_SETFOCUS/WM_ACTIVATE message(s) to keep these values updated!

; Do the same for modeless dialogs but store the hwnd in g_hdlg!

.end macro _start, _args:vararg
.data?
cmdlin dd ? ; ptr to coomand tail - NO path/name
exename dd ? ; ptr to full name of exec file
g_haccel dd ? ; HACCEL of active window
g_hdlg dd ? ; HDLG of active modeless dialog
g_hinst dd ? ; HINSTANCE of module
g_hwnd dd ? ; HWND of active window
; 2 new globals - handy to have
msg0 MSG {} ; used by 'waitquitmsg' macro
wc0 WNDCLASSEX{} ; used by 'regclass' macro

includelib shlwapi

.code
_start0:
invoke GetModuleHandle, 0
mov g_hinst, eax
invoke GetCommandLine
mov exename, eax
push eax
call PathGetArgs
mov cmdlin, eax
push exename
call PathRemoveArgs

call _startup
ifdef WndProc
mov wc0.lpfnWndProc, o WndProc
endif

$start equ _start
ifb <_start>
ifdef WinMain
$start equ <WinMain> ;; gui
elseifdef main
$start equ <main> ;; console
else
.err "Must define main or WinMain"
endif
endif

ifb <_args>
call $start
else
invoke $start, _args
endif

invok ExitProcess, eax
end _start0
endm


waitquitmsg macro
.code
.while 1
invoke GetMessage, @ msg0, 0, 0, 0
.break .if eax == 0
invoke IsDialogMessage, g_hdlg, @ msg0
.cont .if eax
invoke TranslateAccelerator, msg0.hwnd, g_haccel, @ msg0
.cont .if eax
invoke TranslateMessage, @ msg0
switch msg0.wParam
case VK_SHIFT, VK_CTRL
.if msg0.message == WM_KEYDOWN
or KEY_SHFT[eax - VK_SHIFT], 1
.elseif msg0.message == WM_KEYUP
and KEY_SHFT[eax - VK_SHIFT], 0
.endif
endsw
invoke DispatchMessage, @ msg0
.endw
return msg0.wParam
endm


; Usage:

WinMain: ; no need for args - they're already defined by .end macro

; do you're initialization ...
; create main window (store result in g_hwnd)
; whatever ...

waitquitmsg ; has a built in return

.end
Posted on 2002-07-12 17:47:51 by gfalen
Has anyone tried these? How about some feedback?
Posted on 2002-07-14 08:54:35 by gfalen