在MFC里面,更改窗口大小和样式是在创建窗口的时候做的,而窗口的图标,背景,光标样式是通过设计窗口类的时候实现的(下篇文章会详细说明)。 更改窗口大小和样式有两种方式:
1. 在窗口创建之前,在BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)函数中,修改其中的CREATESTRUCT结构的属性来改变窗口的样式。
typedef struct tagCREATESTRUCT {
LPVOID lpCreateParams;
HINSTANCE hInstance;
HMENU hMenu;
HWND hwndParent;
int cy;
int cx;
int y;
int x;
LONG style;
LPCTSTR lpszName;
LPCTSTR lpszClass;
DWORD dwExStyle;
} CREATESTRUCT, *LPCREATESTRUCT;
如:
cs.cx = 300;
cs.cy = 200;
2. 在窗口创建后, 在int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数中设置SetWindowsLongPtr来改变窗口样式
LONG_PTR SetWindowLongPtr( HWND hWnd,
int nIndex,
LONG_PTR dwNewLong
);
其中, nIndex表示一个类型, 而dwNewLong是对应的值
nIndex包括:
-
-
GWL_EXSTYLE
- Sets a new extended window style. For more information, see CreateWindowEx. GWL_STYLE
- Sets a new window style. GWLP_WNDPROC
- Sets a new address for the window procedure. GWLP_HINSTANCE
- Sets a new application instance handle. GWLP_ID
- Sets a new identifier of the window. GWLP_USERDATA
- Sets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.
-
The following values are also available when the
hWnd parameter identifies a dialog box.
-
DWLP_DLGPROC
- Sets the new pointer to the dialog box procedure. DWLP_MSGRESULT
- Sets the return value of a message processed in the dialog box procedure. DWLP_USER
- Sets new extra information that is private to the application, such as handles or pointers.
-
- 如:
-
SetWindowLongPtr(m_hWnd, GWL_STYLE, GetWindowLongPtr(m_hWnd, GWL_STYLE) & ~WS_MAXIMIZEBOX);
-