; Text.asm Iczelion's example FASMW version

format PE GUI 4.0
entry start


include '%include%\win32a.inc'

;--------------------------------------------
macro RGB red, green, blue
{
xor eax, eax
mov ah, blue
shl eax, 8
mov ah, green
mov al, red
}

;---------------------------------------------
section '.data' data readable writeable

_title db 'Our First Window',0
_class db 'SimpleWinClass',0
_OurText db 'Win32 assembly is great and easy!',0
mainhwnd dd ?
hinstance dd ?
msg MSG
wc WNDCLASS
_hdc dd 0
_ps PAINTSTRUCT
_FontName db 'script',0
_hfont dd 0
;---------------------------------------------
section '.code' code readable executable

start:

invoke GetModuleHandle,0
mov [hinstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
mov [wc.style],0
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hinstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],COLOR_WINDOW+1
mov [wc.lpszMenuName],0
mov [wc.lpszClassName],_class
invoke RegisterClass,wc

invoke CreateWindowEx,0,_class,_title, WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT, CW_USEDEFAULT , CW_USEDEFAULT, CW_USEDEFAULT,\
NULL, NULL, [hinstance], NULL
mov [mainhwnd],eax
invoke ShowWindow, [mainhwnd], SW_SHOWNORMAL
invoke UpdateWindow, [mainhwnd]

msg_loop:
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop

end_loop:
invoke ExitProcess,[msg.wParam]
;---------------------------------------------
proc WindowProc, hwnd,wmsg,wparam,lparam
enter
push ebx esi edi
cmp [wmsg],WM_DESTROY
je wmdestroy
cmp [wmsg],WM_PAINT
je wmpaint
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp finish
wmpaint:
invoke BeginPaint, [hwnd], _ps
mov [_hdc], eax
invoke CreateFont, 24, 16, 0, 0, 400, 0, 0, 0,\
OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,\
DEFAULT_QUALITY, DEFAULT_PITCH+FF_SCRIPT, _FontName
invoke SelectObject, [_hdc], eax
mov [_hfont], eax
RGB 200,200,50
invoke SetTextColor, [_hdc], eax
RGB 0,0,255
invoke SetBkColor, [_hdc], eax
invoke TextOut, [_hdc], 0 ,0, _OurText, 33
invoke SelectObject, _hdc, _hfont
invoke EndPaint, [hwnd], _ps
jmp finish
wmdestroy:
invoke PostQuitMessage,0
xor eax,eax
finish:
pop edi esi ebx
return
;-----------------------------------------------
section '.idata' import data readable writeable

library kernel,'KERNEL32.DLL',\
gdi, 'GDI32.DLL',\
user,'USER32.DLL'

import kernel,\
GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'

import user,\
RegisterClass,'RegisterClassA',\
CreateWindowEx,'CreateWindowExA',\
DefWindowProc,'DefWindowProcA',\
GetMessage,'GetMessageA',\
TranslateMessage,'TranslateMessage',\
DispatchMessage,'DispatchMessageA',\
LoadCursor,'LoadCursorA',\
LoadIcon,'LoadIconA',\
PostQuitMessage,'PostQuitMessage',\
ShowWindow,'ShowWindow',\
UpdateWindow, 'UpdateWindow',\
BeginPaint, 'BeginPaint',\
EndPaint, 'EndPaint'

import gdi,\
CreateFont, 'CreateFontA',\
SelectObject, 'SelectObject',\
SetTextColor, 'SetTextColor',\
SetBkColor, 'SetBkColor',\
TextOut, 'TextOutA'
;=============================================


Cheers,

The I
Posted on 2003-08-15 22:01:43 by imagineer