VC++ 深入详解 学习笔记(4) -- 修改窗口样式

本文介绍了在MFC中如何通过两种方法调整窗口的大小和样式:一是在窗口创建前通过修改CREATESTRUCT结构;二是在窗口创建后使用SetWindowLongPtr函数。

在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);
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值