Minimal Dialog based program example without resources ?#define WIN32_LEAN_AND_MEAN
#include <windows.h>
INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
typedef struct {
DLGTEMPLATE lpDlg;
WORD fill[3]; // menu class title
} MINDLGTEMPLATE, *PMINDLGTEMPLATE;
int __cdecl WinMainCRTStartup(void)
{
int rc;
static MINDLGTEMPLATE Dlg = {{WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE | DS_3DLOOK | DS_CENTER,0,0,0,0,200,100}};
rc = DialogBoxIndirectParam(GetModuleHandle(NULL), (LPDLGTEMPLATE)&Dlg, 0, MainDlgProc, 0);
ExitProcess(rc);
return rc;
}
INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_INITDIALOG:
return TRUE;
}
return FALSE;
}
With POAsm too:.386
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
WM_CLOSE equ 10h
WM_INITDIALOG equ 110h
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
;align 4
Dlg dd 90C80804h ; style 90C80804h WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE | DS_3DLOOK | DS_CENTER
dd 0 ; dwExtendedStyle
dw 0 ; cdit
dw 0 ; x
dw 0 ; y
dw 200 ; cx
dw 100 ; cy
dw 0 ; empty menu
dw 0 ; empty class
dw 0 ; empty title
.code
start PROC
push 0
call GetModuleHandleA@4
push 0
push DlgProc
push 0
push ADDR Dlg
push eax
call DialogBoxIndirectParamA@20
push eax
call ExitProcess@4
start ENDP
DlgProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax, uMsg
cmp eax, WM_CLOSE
jne @1
push 0
push hWnd
call EndDialog@8
jmp @3
@1:
cmp eax, WM_INITDIALOG
jne @2
je @3
@2:
xor eax,eax ; FALSE
ret
@3:
mov eax,1 ; TRUE
ret
DlgProc ENDP
END start
.386
.model flat,stdcall
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
WM_CLOSE equ 10h
WM_INITDIALOG equ 110h
;-----
GetModuleHandleW PROTO :DWORD
DialogBoxIndirectParamW PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ExitProcess PROTO :DWORD
EndDialog PROTO :DWORD,:DWORD
;-----
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
;align 4
Dlg dd 90C80804h ; style 90C80804h WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE | DS_3DLOOK | DS_CENTER
dd 0 ; dwExtendedStyle
dw 0 ; cdit
dw 0 ; x
dw 0 ; y
dw 200 ; cx
dw 100 ; cy
dw 0 ; empty menu
dw 0 ; empty class
dw "Test",0 ; title
.code
start PROC
INVOKE GetModuleHandleW,0
INVOKE DialogBoxIndirectParamW,eax,ADDR Dlg,0,DlgProc,0
INVOKE ExitProcess,eax
start ENDP
DlgProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax, uMsg
.if eax == WM_CLOSE
INVOKE EndDialog,hWnd,0
.elseif eax == WM_INITDIALOG
mov eax,1
.else
xor eax,eax
.endif
ret
DlgProc ENDP
END start
Win64.model flat,fastcall
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
WM_DESTROY equ 2
WM_CLOSE equ 10h
WM_INITDIALOG equ 110h
GetModuleHandleW PROTO :QWORD
ExitProcess PROTO :QWORD
DialogBoxIndirectParamW PROTO :QWORD,:QWORD,:QWORD,:QWORD,:QWORD
EndDialog PROTO :QWORD,:QWORD
PostQuitMessage PROTO :QWORD
MessageBoxW PROTO :QWORD,:QWORD,:QWORD,:QWORD
;----------------------
DlgProc PROTO :QWORD,:QWORD,:QWORD,:QWORD
WMInitdialog PROTO :QWORD
WMDestroy PROTO
WMClose PROTO :QWORD
.drectve segment
db '/subsystem:windows '
.drectve ends
.data
;align 4
DlgBox dw 1 ; dlgVer
dw 0FFFF ; signature
dd 0 ; helpID
dd 0 ; exStyle
dd 10CA0800h ; style
dw 0 ; cDlgItems
dw 0 ; x
dw 0 ; y
dw 200 ; cx
dw 100 ; cy
dw 0 ; empty menu
dw 0 ; empty windowClass
dw "Test",0 ; title POAsm
;dw 'T','e','s','t',0 ; title
sMsg dw "OK to close",0
;sMsg dw 'O','K',' ','t','o',' ','c','l','o','s','e',0
.code
; parameters RCX, RDX, R8 and R9
start PROC PARMAREA=5*QWORD
INVOKE GetModuleHandleW,0
mov rcx,rax
INVOKE DialogBoxIndirectParamW,rcx,ADDR DlgBox,0,ADDR DlgProc,0
INVOKE ExitProcess, rax
start ENDP
DlgProc PROC hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD PARMAREA=4*QWORD
;mov hWnd, rcx ; ?
mov QWORD PTR [rsp+30h],rcx
;mov uMsg, rdx
mov DWORD PTR [rsp+38h],edx
;mov wParam, r8
mov QWORD PTR [rsp+40h],r8
;mov lParam, r9
mov QWORD PTR [rsp+48h],r9
mov rax,uMsg
.if uMsg==WM_INITDIALOG
INVOKE WMInitdialog, hWnd
.elseif uMsg==WM_CLOSE
INVOKE WMClose, hWnd
.elseif uMsg==WM_DESTROY
INVOKE WMDestroy
.else
@@: xor rax,rax
.endif
ret
DlgProc ENDP
WMInitdialog PROC hWnd:QWORD PARMAREA=4*QWORD
;mov hWnd,rcx
;mov qword ptr [rsp+30h],rcx
mov rax,1
WMInitdialog ENDP
WMDestroy PROC
INVOKE PostQuitMessage,0
mov rax,1
WMDestroy ENDP
WMClose PROC hWnd:QWORD PARMAREA=4*QWORD
;mov hWnd,rcx
mov QWORD PTR [rsp+30h],rcx
INVOKE MessageBoxW,hWnd,ADDR sMsg, 0, 21h
.if rax == 1
;mov rcx,hWnd
mov rcx,QWORD PTR [rsp+30h]
INVOKE EndDialog,hWnd,0
.endif
WMClose ENDP
END start