Win32Forth視窗程式基礎
1. 如何使用Windows系統呼叫
使用call來做,先堆好參數,然後在call 後面接函式名稱,大小寫有分。回傳值會直接堆在Data Stack上。
參數和C函式參數以相反的方式推入。
參數中有指標時要轉成絶對位址,使用REL>ABS做轉換。
在使用別的DLL時要注意:
Win32 API有三種呼叫格式,會影響呼叫後之結果。
使用標準呼叫,則參數在呼叫後會從堆疊中清除。
使用C傳統呼叫,則在呼叫後參數仍保留。
使用Pascal呼叫,參數和C相反。
例如:
CreateWindow原型
HWND CreateWindowEx(dwExStyle, lpszClass, lpszWindowName, dwStyle, x, y, nWidth, nHeight, hwndOwner, hmenu, hinst, lpvCreateParams)
DWORD dwExStyle; /* extended window style */
LPCTSTR lpszClass; /* address of registered class name */
LPCTSTR lpszWindowName; /* address of window text */
DWORD dwStyle; /* window style */
int x; /* horizontal position of the window */
int y; /* vertical position of the window */
int nWidth; /* window width */
int nHeight; /* window height */
HWND hwndOwner; /* handle of parent window */
HMENU hmenu; /* handle of menu or child-window identifier */
HANDLE hinst; /* handle of application instance */
LPVOID lpvCreateParams; /* address of window-creation data */
在Win32Forth中
: CREATE-HELLO-WINDOW ( -- f )
0 \ creation parameters
AppInst \ instance handle
0 \ menu
ConHndl \ parent window
200 300 100 100 \ window position ( h w y x )
WS_OVERLAPPEDWINDOW \ window style
Title \ window title
AppName \ class name
0 \ exended style
Call CreateWindowEx ;
2. DOS程式與視窗程式之不同
DOS程式給人的感覺是順序、按照過程驅動程式設計。有明顯的開始及結束,且由用戶決定該做什麼。
視窗程式由事件驅動,程式是”被動”執行。所以程式無明顯開始,而是分成好幾部分執行。

要建立一個標準的視窗,使視窗能夠接收系統的訊息,也能傳遞訊息給系統,所需步驟如下:
參照Hello.f
3. Win32Forth視窗程式架構簡介
參照WinHello.f,以物件的方式做為基本。
屬性Property
事件Event
方法Method
參考書籍:
Windows環境下32位元組合語言程式設計 羅雲彬 原著
全華科技出版

視窗程式設計函式庫Win32
API 林隆煥 著 金禾資訊出版

