在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);
分享到:
相关推荐
Visual C++深入详解学习笔记,word文檔
VC++深入详解学习笔记(非常全面)
VC++深入详解代码3-4章,很全的东西
上传限制无奈分卷压缩 一共12卷 要12卷在同目录才可以解压 给大家带来不便请你们谅解 VC++深入详解pdf版 VC++深入详解 VC++深入详解电子档
VC++深入详解,学习VC++的经典教材
VC++深入详解完整版,并带完整详细的书签,包括每章,每节的书签索引。
孙鑫 VC++ 深入详解书中源码
VC++深入详解 书上的源码(全) VC++深入详解 书上的源码(全) VC++深入详解 书上的源码(全)
《VC++深入详解》主要从程序内部运行的机制和MFC程序的组织脉络入手,使读者在学习VC++编程知识时,既能够知其然,又能知其所以然,从而帮助读者从根本上理解和掌握Windows的程序设计。另外,《VC++深入详解》还贯穿...
《VC++深入详解》主要从程序内部运行的机制和MFC程序的组织脉络入手,使读者在学习VC++编程知识时,既能够知其然,又能知其所以然,从而帮助读者从根本上理解和掌握Windows的程序设计。另外,《VC++深入详解》还贯穿...
上传限制无奈分卷压缩 一共12卷 要12卷在同目录才可以解压 给大家带来不便请你们谅解 VC++深入详解pdf版 VC++深入详解 VC++深入详解电子档
VC++深入详解
上传限制无奈分卷压缩一共12卷 要12卷在同目录才可以解压给大家带来不便请你们谅解 VC++深入详解pdf版 VC++深入详解 VC++深入详解电子档
上传限制无奈分卷压缩一共12卷 要12卷在同目录才可以解压给大家带来不便请你们谅解 VC++深入详解pdf版 VC++深入详解 VC++深入详解电子档 资源绝对好 大家放心