(譯)win32asm例項-1 (轉)

worldblog發表於2007-12-12
(譯)win32asm例項-1 (轉)[@more@] 

1.0 - New project新的工程


Create a new folder named 'mosaic' in your asm projects folder (it is adviceable to create this folder on the same drive as the MASM package so you can use the relative lib/include paths in the examples.


在你的asm工程夾(建議這個資料夾和masm包放在同一個區因而你可以在例子中使用相對的lib/include(庫/包含檔案)路徑)中建立名為“mosaic”的新目錄。


this Zfile and extract it's contents in your 'mosaic' folder: ?file=mosaic.mosaic_lesson_files">mosaic lesson files.zip:namespace prefix = o ns = "urn:schemas--com::office" />


這個zip檔案並把它的內容解到你的“mosaic”目錄中:mosaic lesson files.zip



1.1 - Basic files基本檔案


The contains the basic (almost empty) files for your project. Here's a short description of the files:


Zip包中有你工程的基本(幾乎為空)檔案。這些檔案的簡單描述:


Mosaic.asm


;===============================================================================
; Mosaic.asm
;===============================================================================
.486
.model flat, stdcall
option casemap: none


includelib masm32libkernel32.lib
includelib masm32libuser32.lib
includelib masm32libgdi32.lib
includelib masm32libcomctl32.lib
includelib masm32libcomdlg32.lib
include masm32includekernel32.inc
include masm32includecomctl32.inc
include masm32includecomdlg32.inc
include masm32includeuser32.inc
include masm32includegdi32.inc
include masm32include.inc
include mosaic.inc


.code
start:


end start


This file contains the for a asm file.


這個檔案包含了win32asm原始檔的。


.486: indicates to use the 486+ assembly instructions
.model flat, stdcall: defines the memory model (flat) and the calling convention (stdcall)
includelib / include: These include the libraries and include files for the windows functions needed. The windows.inc includes basic windows constants. The mosaic.inc contains your own constants.
.code: code segment
start: just a label, could be anything
end start: indicates that the entry point of your program is at a label called start.


.486: 說明用486及以上的指令。
.model flat, stdcall:定義(flat)和習慣(stdcall)
includelib / include: 這些包含Windows所需要的庫和包含檔案。Windows.inc中有基本的windows常量。Mosaic.inc包含你自有的常量。
.code: 選擇程式碼段
start: 只是一個標籤,可以為任何東西
end start:表明你的的入口點是位於一個名為start的標籤.


Mosaic.inc


;---- msgbox macro: usage MSGBOX "string to display" -------
MSGBOX MACRO msg:REQ
LOCAL @msg
.data
@msg msg, 0
.code
invoke MessageBox, NULL, ADDR @msg, ADDR AppName, MB_OK
ENDM


In mosaic.inc there is a little macro to simplify the use of MessageBoxes. A macro is a piece of code that can contain variables (here msg for example), which you can then use in your code and will be replaced by the macro code when assembling. I don't go into details about macro's right now, just remember you can show a msgbox in your program by using:


在mosaic.inc中有一個小的宏來簡化MessageBox的使用。一個宏是一小塊可以包含變數(例如這裡的msg)的程式碼。你可以在你的程式碼中使用它,而且在彙編時將會被宏中的程式碼所取代。我不會立刻深入宏的細節。只要記住你可以在你的程式中使用一下程式碼來顯示一個訊息對話方塊:


msgbox "Your string to display"


make.bat


@echo off
ml /c /coff mosaic.asm
rc -r mosaic.rc
link /subsystem:windows mosaic.obj mosaic.res
pause>nul


Use this batch file to assemble and link your program. The rc command will compile your resources.


使用這個批處理檔案來彙編並連結你的程式。Rc命令編譯你的資源


resources


This folder contains some bitmaps and icons we will use in our program:


這個資料夾包含一些我們將要在我們程式中使用的圖片和圖示:






ectratio="t">










Big icon
(big.ico)



Small icon
(small.ico)



Toolbar buttons
(Toolbar.bmp)



Demo game picture
(demo.bmp)


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-991725/,如需轉載,請註明出處,否則將追究法律責任。

相關文章