this isnt really much of a gem but here's how to draw line segments to a window.

.586

.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
include \masm32\include\gdi32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\gdi32.lib


WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO :DWORD,:DWORD



.data
ClassName db "Starting Template",0
CaptionText db "Drawing",0

charS dd 15,30,5,30,5,40,15,40,15,50,5,50
charM dd 20,50,20,30,25,40,30,30,30,50
charU dd 35,30,35,50,45,50,45,30
charR dd 50,50,50,30,60,30,60,40,50,40,60,50
charF dd 75,30,65,30,65,40,75,40,65,40,65,50

.data?
hWnd HANDLE ?
hInstance HANDLE ?


hDC HDC ?
rect RECT <>

ps PAINTSTRUCT <>

.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,eax
invoke InitCommonControls

; ########################################################################

WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

;====================
; Put LOCALs on stack
;====================

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD

;==================================================
; Fill WNDCLASSEX structure with required variables
;==================================================

mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW + CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
mov eax, hInstance
mov wc.hInstance, eax
invoke LoadIcon, NULL,IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL,IDC_ARROW
mov wc.hCursor, eax
mov wc.hbrBackground,HOLLOW_BRUSH
mov wc.lpszMenuName, NULL
mov wc.lpszClassName,OFFSET ClassName


invoke RegisterClassEx, addr wc

;================================
; Centre window at following size
;================================

mov Wwd, 300
mov Wht, 250

invoke GetSystemMetrics,SM_CXSCREEN
invoke TopXY,Wwd,eax
mov Wtx, eax

invoke GetSystemMetrics,SM_CYSCREEN
invoke TopXY,Wht,eax
mov Wty, eax

invoke CreateWindowEx,NULL,
ADDR ClassName,
ADDR CaptionText,
WS_OVERLAPPEDWINDOW,
Wtx,Wty,Wwd,Wht,
NULL,
NULL,
hInst,
NULL
mov hWnd,eax

invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd

;===================================
; Loop until PostQuitMessage is sent
;===================================

StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:

mov eax,msg.wParam
ret

WinMain endp

; ########################################################################

WndProc proc hWin :HWND,
uMsg :UINT,
wParam :WPARAM,
lParam :LPARAM

.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL


.ELSEIF uMsg == WM_PAINT
invoke BeginPaint,hWin,addr ps
mov hDC,eax
invoke GetClientRect,hWin,addr rect
invoke SetMapMode,hDC,MM_ANISOTROPIC
invoke SetWindowExtEx,hDC,80,85,0
invoke SetViewportExtEx,hDC,rect.right,rect.bottom,0
invoke Polyline,hDC,addr charS,6
invoke Polyline,hDC,addr charM,5
invoke Polyline,hDC,addr charU,4
invoke Polyline,hDC,addr charR,6
invoke Polyline,hDC,addr charF,6
invoke EndPaint,hWin,addr ps

.ELSE
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret

.ENDIF
xor eax,eax
ret

WndProc endp


; ########################################################################

TopXY proc wDim:DWORD, sDim:DWORD

shr sDim, 1
shr wDim, 1
mov eax, wDim
sub sDim, eax
mov eax,sDim
ret

TopXY endp

; #########################################################################

end start
Posted on 2002-01-22 16:46:35 by smurf