Win32程序有用的函数&结构
WNDCLASSEX: //注册窗体时用到的结构
typedef struct {
UINT cbSize; //用来保存WNDCLASSEX结构的大小,以byte为单位 通常用::cbSize=sizeof(WNDCLASSEX)设置
UINT style; //窗口应有的样式
WNDPROC lpfnWndProc; //Pointer to the window procedure
int cbClsExtra; //一般为0
int cbWndExtra; //一般为0
HINSTANCE hInstance; //WinMain里的hInstance参数
HICON hIcon; //应用程序所使用的图标的句柄 可用::hIcon=LoadIcon(NULL, IDI_APPLICATION)加载默认图标 用::hIon=LoadIcon(hInstance,IDI_XX)加载自定义光标
HCURSOR hCursor; //应用程序所使用的鼠标光标句柄 可用::hCursor=LoadCursor(NULL, IDC_ARROW) 获取光标句柄 若加载自定义光标,用::hIcon=LoadCursor(hInstance,IDC_XX)
HBRUSH hbrBackground; //指定创建窗口的背景色
LPCTSTR lpszMenuName; //设置菜单的名字
LPCTSTR lpszClassName; //自定义的窗口类名
HICON hIconSm; //出现在任务栏的图标句柄
} WNDCLASSEX, *PWNDCLASSEX;
若非第一次注册窗口,最好先清理一下解决方案
style(Class Style):
CS_BYTEALIGNCLIENT: Aligns the window's client area on a byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.
CS_BYTEALIGNWINDOW: Aligns the window on a byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.
CS_CLASSDC: Allocates one device context to be shared by all windows in the class. Because window classes are process specific, it is possible for multiple threads of an application to create a window of the same class. It is also possible for the threads to attempt to use the device context simultaneously. When this happens, the system allows only one thread to successfully finish its drawing operation.
CS_DBLCLKS: Sends a double-click message to the window procedure when the user double-clicks the mouse while the cursor is within a window belonging to the class.
CS_DROPSHADOW: Windows XP: Enables the drop shadow effect on a window. The effect is turned on and off through SPI_SETDROPSHADOW. Typically, this is enabled for small, short-lived windows such as menus to emphasize their Z order relationship to other windows.
CS_GLOBALCLASS: Specifies that the window class is an application global class. For more information, see Application Global Classes.
CS_HREDRAW: Redraws the entire window if a movement or size adjustment changes the width of the client area.
CS_NOCLOSE: Disables Close on the window menu.
CS_OWNDC: Allocates a unique device context for each window in the class.
CS_PARENTDC: Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDC enhances an application's performance.
CS_SAVEBITS: Saves, as a bitmap, the portion of the screen image obscured by a window of this class. When the window is removed, the system uses the saved bitmap to restore the screen image, including other windows that were obscured. Therefore, the system does not send WM_PAINT messages to windows that were obscured if the memory used by the bitmap has not been discarded and if other screen actions have not invalidated the stored image.
This style is useful for small windows (for example, menus or dialog boxes) that are displayed briefly and then removed before other screen activity takes place. This style increases the time required to display the window, because the system must first allocate memory to store the bitmap.
CS_VREDRAW: Redraws the entire window if a movement or size adjustment changes the height of the client area.
GetStockObject: //The GetStockObject function retrieves a handle to one of the stock pens, brushes, fonts, or palettes.
HGDIOBJ GetStockObject(
__in int fnObject
);
fnObject:
BLACK_BRUSH: Black brush.
DKGRAY_BRUSH: Dark gray brush.
DC_BRUSH: Solid color brush. The default color is white. The color can be changed by using the SetDCBrushColor function. For more information, see the Remarks section.
GRAY_BRUSH: Gray brush.
HOLLOW_BRUSH: Hollow brush (equivalent to NULL_BRUSH).
LTGRAY_BRUSH: Light gray brush.
NULL_BRUSH: Null brush (equivalent to HOLLOW_BRUSH).
WHITE_BRUSH: White brush.
BLACK_PEN: Black pen.
DC_PEN: Solid pen color. The default color is white. The color can be changed by using the SetDCPenColor function. For more information, see the Remarks section.
NULL_PEN: NULL pen. The null pen draws nothing.
WHITE_PEN: White pen.
ANSI_FIXED_FONT: Windows fixed-pitch (monospace) system font.
ANSI_VAR_FONT: Windows variable-pitch (proportional space) system font.
DEVICE_DEFAULT_FONT: Device-dependent font.
DEFAULT_GUI_FONT: Default font for user interface objects such as menus and dialog boxes. It is not recommended that you use DEFAULT_GUI_FONT or SYSTEM_FONT to obtain the font used by dialogs and windows; for more information, see the remarks section.
The default font is Tahoma.
OEM_FIXED_FONT: Original equipment manufacturer (OEM) dependent fixed-pitch (monospace) font.
SYSTEM_FONT: System font. By default, the system uses the system font to draw menus, dialog box controls, and text. It is not recommended that you use DEFAULT_GUI_FONT or SYSTEM_FONT to obtain the font used by dialogs and windows; for more information, see the remarks section.
The default system font is Tahoma.
SYSTEM_FIXED_FONT: Fixed-pitch (monospace) system font. This stock object is provided only for compatibility with 16-bit Windows versions earlier than 3.0.
DEFAULT_PALETTE: Default palette. This palette consists of the static colors in the system palette.