複製鏈接
請複製以下鏈接發送給好友

WNDCLASSEX

鎖定
WNDCLASSEX是一個窗口,最重要的成員是lpfnWndProc。前綴 lpfn 表示該成員是一個指向函數的長指針。在 Win32中由於內存模式是 FLAT 型,所以沒有 near 或 far 的區別。
中文名
WNDCLASSEX
類    別
窗口類
結構體原型
typedef struct WNDCLASSEX
説    明
WNDCLASSEX 結構用於註冊窗口類

WNDCLASSEX描述

每一個窗口類必須有一個窗口過程,當 Windows 把屬於特定窗口的消息發送給該窗口時,該窗口的窗口類負責處理所有的消息,如鍵盤消息或鼠標消息。由於窗口過程差不多智能地處理了所有的窗口消息循環,所以您只要在其中加入消息處理過程即可。

WNDCLASSEX結構體原型

typedef struct WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;

WNDCLASSEX説明

WNDCLASSEX 結構用於註冊窗口類
註冊實例:
ATOM MyRegisterClass( HINSTANCE hInstance )
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC) WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "My Class";
wcex.hIconSm = LoadIcon( NULL, IDI_WINLOGO );
return RegisterClassEx( &wcex );
}

WNDCLASSEX參數

1.cbSize:
WNDCLASSEX 的大小。我們可以用sizeof(WNDCLASSEX)來獲得準確的值。
2.style:
從這個窗口類派生的窗口具有的風格。您可以用“or”操作符來把幾個風格或到一起。
3.lpfnWndProc:
窗口處理函數的指針。
4.cbClsExtra:
指定緊跟在窗口類結構後的附加字節數。
5.cbWndExtra:
指定緊跟在窗口實例的附加字節數。如果一個應用程序在資源中用CLASS偽指令註冊一個對話框類時,則必須把這個成員設成DLGWINDOWEXTRA。
6.hInstance:
本模塊的實例句柄。
7.hIcon:
圖標的句柄。
8.hCursor:
光標的句柄。
9.hbrBackground:
背景畫刷的句柄。
10.lpszMenuName:
指向菜單的指針。
11.lpszClassName:
指向類名稱的指針。
12.hIconSm:
窗口類關聯的小圖標。如果該值為NULL。則把hIcon中的圖標轉換成大小合適的小圖標。

WNDCLASSEX例子

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL=1
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr w ; register our window class
invoke CreateWindowEx,NULL,\
ADDR ClassName,\
ADDR AppName,\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
NULL,\
NULL,\
hInst,\
NULL
mov hwnd,eax
invoke ShowWindow, hwnd,CmdShow ; display our window on desktop
invoke UpdateWindow, hwnd ; refresh the client area
在FirstWindow程序中,註冊窗口類的代碼是:
local @stWndClass:WNDCLASSEX ;定義一個WNDCLASSEX結構
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW + 1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass