修改窗口的风格ModifyStyle

本文详细介绍了CWnd::ModifyStyle函数的作用、参数、返回值及用法,并提供了实例代码,帮助理解如何通过该函数修改窗口样式。
CWnd::ModifyStyle
1.作用:
调用这个函数修改窗口的风格,此函数的厉害之处在于可以在窗口创建完成后修改窗口风格,虽然也有一些属性改不了。
2.函数原型:
BOOL ModifyStyle
(
DWORD dwRemove,
DWORD dwAdd,
UINT nFlags=0
);
3.参数含义:
dwRemove 指定修改时要删除的窗风格。
dwAdd 指定修改时将要增加的窗口风格。
nFlags 该参数将被传给SetWindowPos,否则为0,如果SetWindowPos不被调用的话,一般该参数默认值
4.返回值:
如果该函数成功调用返回一个非0值,否则返回0;
5.备注
如果nFlags不为0,   ModifyStyle将调用Windows API 函数 SetWindowPos并且结合nFlags和以下四个预先布置好的标志重画该窗口。
SWP_NOSIZE 保持当前大小。
SWP_NOMOVE 保持当前位置.。
SWP_NOZORDER 保持当前的Z次序。
SWP_NOACTIVATE 不激活该窗口。
6.用法:
1、修改控件的原有属性用 ModifyStyle(1,WS_DISABLED);(实际测试时只要是>=0的整形数就行)
2、改回来的话要用ModifyStyle(WS_DISABLED,1);(实际测试时只要是>=0的整形数就行)
如果把参数想像成布尔值的话就使用1这个整形数,要除去第控件的属性就让第一个参数dwRemove为真,修改回来就让第二个参数dwAdd为真.
7.参考代码:
void CMyView:: OnInitialUpdate()
{
CView:: OnInitialUpdate();
ModifyStyle(0, WS_CLIPCHILDREN);
}
………………………………………………………………………………………………………………………………
C++中一些实例
SetWindowText("abc"); //设置 窗口 标题栏  abc
ModifyStyle(WS_CAPTION,0,0); //去除 标题栏
ModifyStyle(0,WS_THICKFRAME,0); //添加 WS_THICKFRAME风格
ModifyStyle(0,WS_EX_TOOLWINDOW,0); //设置工具栏窗口风格
ModifyStyleEx(0,WS_EX_ACCEPTFILES,0); //设置Accept files 属性
也就说,要添加或除去窗口的普通风格,可以使用ModifyStyle 方法来实现
设置或去除窗口的扩展风格,可以使用 ModifyStyleEx 方法。C++中注意大小写。
以上实例摘自 2011版的 羊皮卷系列之 学通 Visual C++的24堂课。
MFC开发过程序所需的ModifyStyle(needDelStyle,needAddStyle,SWP_FRAMECHANGED); Sytel: WS_BORDER Creates a window that has a border. WS_CAPTION Creates a window that has a title bar (implies the WS_BORDER style). Cannot be used with the WS_DLGFRAME style. WS_CHILD Creates a child window. Cannot be used with the WS_POPUP style. WS_CHILDWINDOW Same as the WS_CHILD style. WS_CLIPCHILDREN Excludes the area occupied by child windows when you draw within the parent window. Used when you create the parent window. WS_CLIPSIBLINGS Clips child windows relative to each other; that is, when a particular child window receives a paint message, the WS_CLIPSIBLINGS style clips all other overlapped child windows out of the region of the child window to be updated. (If WS_CLIPSIBLINGS is not given and child windows overlap, when you draw within the client area of a child window, it is possible to draw within the client area of a neighboring child window.) For use with the WS_CHILD style only. WS_DISABLED Creates a window that is initially disabled. WS_DLGFRAME Creates a window with a double border but no title. WS_GROUP Specifies the first control of a group of controls in which the user can move from one control to the next with the arrow keys. All controls defined with the WS_GROUP style FALSE after the first control belong to the same group. The next control with the WS_GROUP style starts the next group (that is, one group ends where the next begins). WS_HSCROLL Creates a window that has a horizontal scroll bar. WS_ICONIC Creates a window that is initially minimized. Same as the WS_MINIMIZE style. WS_MAXIMIZE Creates a window of maximum size. WS_MAXIMIZEBOX Creates a window that has a Maximize button. WS_MINIMIZE Creates a window that is initially minimized. For use with the WS_OVERLAPPED style only. WS_MINIMIZEBOX Creates a window that has a Minimize button. WS_OVERLAPPED Creates an overlapped window. An overlapped window usually has a caption a
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值