Iczelion's Win32 Assembly Tutorial: Painting with Text

format PE GUI 4.0
entry start

include '%fasminc%\win32w.inc'


;================================================================================[DATA]====
section '.data' data readable writeable

    wTitle	   TCHAR   'Iczelion Tutorial No.4',0
    wClsName	   TCHAR   'TUT04',0
    expTxt	   TCHAR   'Win32 assembly with FASM is great and easy',0

    wMsg	   MSG
    wCls	   WNDCLASS

    wHMain	   dd	?
    wHInstance	   dd	?

    ;exp = experiment
    expHdc	   dd	?
    expPs	   PAINTSTRUCT
    expRect	   RECT


;================================================================================[CODE]====
section '.code' code readable executable

start:

  ; registering the window class
    invoke  GetModuleHandle, 0
    mov     [wHInstance], eax
    mov     [wCls.hInstance], eax
    mov     [wCls.style], CS_HREDRAW or CS_VREDRAW
    mov     [wCls.lpfnWndProc], window_procedure
    mov     [wCls.lpszClassName], wClsName
    mov     [wCls.hbrBackground], COLOR_BTNFACE+1
    invoke  LoadIcon, NULL, IDI_APPLICATION
    mov     [wCls.hIcon], eax
    invoke  LoadCursor, NULL, IDC_ARROW
    mov     [wCls.hCursor], eax
    invoke  RegisterClass, wCls

  ; creating the main window
    invoke  CreateWindowEx, 0, wClsName, wTitle,\
	    WS_OVERLAPPEDWINDOW + WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,\
	    CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, [wHInstance], NULL
    mov     [wHMain], eax

  ; entering the message loop
window_message_loop_start:
    invoke  GetMessage, wMsg, NULL, 0, 0
    or	    eax, eax
    je	    window_message_loop_end
    invoke  TranslateMessage, wMsg
    invoke  DispatchMessage, wMsg
    jmp     window_message_loop_start

window_message_loop_end:
    invoke  ExitProcess, 0


;----------------------------------------------------------------<the window procedure>----
proc window_procedure uses ebx esi edi, hWnd, uMsg, wParam, lParam

    mov     eax, [uMsg]
    cmp     eax, WM_PAINT
    je	    .wmPAINT
    cmp     eax, WM_DESTROY
    je	    .wmDESTROY

.wmDEFAULT:
    invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
    jmp     .exit
	
.wmPAINT:
    invoke  BeginPaint, [hWnd], expPs
    mov     [expHdc], eax
    invoke  GetClientRect,[hWnd],expRect
    invoke  DrawText, [expHdc], expTxt, -1, expRect,\
	    DT_SINGLELINE or DT_CENTER or DT_VCENTER
    invoke  EndPaint,[hWnd],expPs
    jmp     .exit

.wmDESTROY:
    invoke  PostQuitMessage, 0

.exit:
    ret
endp
;----------------------------------------------------------------<the window procedure>----


;===============================================================================[IDATA]====
section '.idata' import data readable

    library kernel32, 'KERNEL32.DLL',\
	    user32,   'USER32.DLL'

    include '%fasminc%\api\kernel32.inc'
    include '%fasminc%\api\user32.inc'

;==========================================================================================



Последнее обновление : 25 января 2008
Hosted by uCoz