- 使用Windows API
- 使用MFC(Microsoft Foundation Classes)
- 使用Windows Forms
此篇主要討論利用Windows API開發視窗應用程式的觀念,不例外的推薦一書:
Windows視窗程式設計可以參考MSDN的資料,這些都是基本觀念,值得一看,所謂「Basic is important」。
- What Is a Window?:http://msdn.microsoft.com/en-us/library/ff381403(VS.85).aspx
- WinMain: The Application Entry Point:http://msdn.microsoft.com/en-us/library/ff381406(VS.85).aspx
- Module 1. Your First Windows Program:http://msdn.microsoft.com/en-us/library/ff381409(VS.85).aspx
其中有個重要的觀念:Window Handles(控制代碼)
Windows are objects — they have both code and data — but they are not C++ classes.
Instead, a program references a window by using a value called a handle(控制代碼). A handle is an opaque type. Essentially, it is just a number that the operating system uses to identify an object. You can picture Windows as having a big table of all the windows that have been created. It uses this table to look up windows by their handles. (Whether that's exactly how it works internally is not important.) The data type for window handles is HWND, which is usually pronounced "aitch-wind." Window handles are returned by the functions that create windows: CreateWindow and CreateWindowEx.
在Windows視窗程式設計當中,Windows提供一系列的核心物件(Kernel Object)讓我們使用,這稱為平台叫用(Platform Invocation, P/Invoke),也就是Windows API,為了使用這些核心物件,呼叫時必須指定核心物件,而這些控制代碼(Handel)就是代表這些核心物件的識別名稱(32位元的Windows是一組32位元的資料,而64位元的Windows是一組64位元的資料),有點類似C/C++的指標。
平台叫用可以參考:
另外,Windows視窗程式設計是事件驅動()的方式,觀念和一般傳統的程序程式設計有些差異,都是依賴訊息(Message)溝通,參考:
附註:Windows系統的實用工具,請參考Windows Sysinternals http://technet.microsoft.com/en-us/sysinternals/default.aspx
Windows are objects — they have both code and data — but they are not C++ classes.
Instead, a program references a window by using a value called a handle(控制代碼). A handle is an opaque type. Essentially, it is just a number that the operating system uses to identify an object. You can picture Windows as having a big table of all the windows that have been created. It uses this table to look up windows by their handles. (Whether that's exactly how it works internally is not important.) The data type for window handles is HWND, which is usually pronounced "aitch-wind." Window handles are returned by the functions that create windows: CreateWindow and CreateWindowEx.
在Windows視窗程式設計當中,Windows提供一系列的核心物件(Kernel Object)讓我們使用,這稱為平台叫用(Platform Invocation, P/Invoke),也就是Windows API,為了使用這些核心物件,呼叫時必須指定核心物件,而這些控制代碼(Handel)就是代表這些核心物件的識別名稱(32位元的Windows是一組32位元的資料,而64位元的Windows是一組64位元的資料),有點類似C/C++的指標。
平台叫用可以參考:
- 悅知文化的一篇文章:在.NET中輕鬆快樂叫用Win32 API
- MSDN雜誌:Marshaling between Managed and Unmanaged Code
另外,Windows視窗程式設計是事件驅動()的方式,觀念和一般傳統的程序程式設計有些差異,都是依賴訊息(Message)溝通,參考:
- About Messages and Message Queues:http://msdn.microsoft.com/en-us/library/ms644927(VS.85).aspx
- Window Procedures:http://msdn.microsoft.com/en-us/library/ms632593(VS.85).aspx
Unmanaged type in Wtypes.h | Unmanaged C language type | Managed class name | Description |
---|---|---|---|
HANDLE | void* | System..::.IntPtr | 32 bits on 32-bit Windows operating systems, 64 bits on 64-bit Windows operating systems. |
BYTE | unsigned char | System..::.Byte | 8 bits |
SHORT | short | System..::.Int16 | 16 bits |
WORD | unsigned short | System..::.UInt16 | 16 bits |
INT | int | System..::.Int32 | 32 bits |
UINT | unsigned int | System..::.UInt32 | 32 bits |
LONG | long | System..::.Int32 | 32 bits |
BOOL | long | System.Int32 | 32 bits |
DWORD | unsigned long | System..::.UInt32 | 32 bits |
ULONG | unsigned long | System..::.UInt32 | 32 bits |
CHAR | char | System..::.Char | Decorate with ANSI. |
LPSTR | char* | System..::.String or System.Text..::.StringBuilder | Decorate with ANSI. |
LPCSTR | Const char* | System..::.String or System.Text..::.StringBuilder | Decorate with ANSI. |
LPWSTR | wchar_t* | System..::.String or System.Text..::.StringBuilder | Decorate with Unicode. |
LPCWSTR | Const wchar_t* | System..::.String or System.Text..::.StringBuilder | Decorate with Unicode. |
FLOAT | Float | System..::.Single | 32 bits |
DOUBLE | Double | System..::.Double | 64 bits |
附註:Windows系統的實用工具,請參考Windows Sysinternals http://technet.microsoft.com/en-us/sysinternals/default.aspx
沒有留言:
張貼留言