我前面有介紹 組建 win32彙編IDE,現在寫個東西練一下。
這個程序是
《Windows Graphics Programming: Win32 GDI and DirectDraw》
這本書裏面 hello2 的asm 仿照版。
============================源代碼開始==================================
.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
include gdi32.inc
includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
.data
szMessage db "Hello World!",0
szFace db "Times New Roman",0
.data?
hDC dd ?
hFont dd ?
hOld dd ?
xpos dd ?
ypos dd ?
.code
start:
invoke GetDC,NULL
mov hDC,eax
;得到桌面句柄
invoke SetTextAlign,eax,TA_CENTER or TA_BASELINE
;設置文本對齊方式
invoke GetSystemMetrics,SM_CXSCREEN
sar eax,1
mov xpos,eax
invoke GetSystemMetrics,SM_CYSCREEN
sar eax,1
mov ypos,eax
;文本位置
invoke CreateFont,64,0, 0, 0,FW_BOLD,/
TRUE,FALSE,FALSE,ANSI_CHARSET,/
OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,/
PROOF_QUALITY,VARIABLE_PITCH,addr szFace
mov hFont,eax
;新建字體
invoke SelectObject,hDC,hFont
mov hOld,eax
;選入字體到DC
invoke TextOut,hDC,xpos,ypos,addr szMessage,sizeof szMessage -1
;繪製文本
invoke SelectObject,hDC,hOld
invoke DeleteObject,hFont
;恢復原字體和銷燬創建字體
invoke ReleaseDC,NULL,hDC
;釋放桌面字體
invoke ExitProcess,NULL
;退出程序
end start
===================================結束=============================================