关于API
应用程序中要完成某个功能,都是以函数调用的形式实现的,同样,应用程序也是以函数调用的方式来通知操作系统执行相应的功能的。操作系统所能够完成的每一个特殊功能通常都有一个函数与其对应,也就是说,操作系统把它所能够完成的功能以函数的形式提供给应用程序使用,应用程序对这些函数的调用就叫做系统调用,这些函数的集合就是Windows操作系统提供给应用程序编程的接口(Application Programming Interface),简称Windows API。如CreateWindow就是一个API函数,应用程序中调用这个函数,操作系统就会按照该函数提供的参数信息产生一个相应的窗口。
关于消息及消息队列
MSG
操作系统是将感知到的事件通过消息机制(Message)来实现的。操作系统将每个事件都包装成一个称为消息的结构体MSG来传递给应用程序,
MSG结构定义如下:
typedef struct tagMSG {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG;
The MSG structure contains message information from a thread's message queue.
typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG, *PMSG;
Members
-
hwnd
- Handle to the window whose window procedure receives the message. message
- Specifies the message identifier. wParam
- Specifies additional information about the message. The exact meaning depends on the value of the message member. lParam
- Specifies additional information about the message. The exact meaning depends on the value of the message member. time
- Specifies the time at which the message was posted. pt
- Specifies the cursor position, in screen coordinates, when the message was posted.
WinMain()函数
The WinMain function is called by the system as the initial entry point for a Win32-based application.
int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state );
Parameters
-
hInstance
- [in] Handle to the current instance of the application. hPrevInstance
-
[in] Handle to the previous instance of the application. For a Win32-based application, this parameter is always NULL.
If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the GetLastError function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first.
lpCmdLine
- [in] Pointer to a null-terminated string specifying the command line for the application, excluding the program name. To retrieve the entire command line, use the GetCommandLine function. nCmdShow
- [in] Specifies how the window is to be shown nCmdShow 的选项有以下等具体参考MSDN:s
Value | Meaning |
---|---|
SW_HIDE | Hides the window and activates another window. |
SW_MAXIMIZE | Maximizes the specified window. |
SW_MINIMIZE | Minimizes the specified window and activates the next top-level window in the Z order. |