CWindow::ModifyStyleEx
Modifies the extended window styles of the CWindow object.
BOOL ModifyStyleEx( DWORD dwRemove, DWORD dwAdd,UINT nFlags = 0 );
参数
dwRemove
[in] Specifies the extended styles to be removed during style modification.
dwAdd
[in] Specifies the extended styles to be added during style modification.
nFlags
[in] Window-positioning flags. For a list of possible values, see the SetWindowPos function in the Windows SDK.
返回值
TRUE if the extended window styles are modified; otherwise, FALSE.
注意
Styles to be added or removed can be combined by using the bitwise OR ( | ) operator. See the CreateWindowEx function in the Windows SDK for information about the available extended styles.
If nFlags is nonzero, ModifyStyleEx calls the Win32 function SetWindowPos, and redraws the window by combining nFlags with the following four flags:
SWP_NOSIZE Retains the current size.
SWP_NOMOVE Retains the current position.
SWP_NOZORDER Retains the current Z order.
SWP_NOACTIVATE Does not activate the window.
To modify windows using regular window styles, call ModifyStyle.
示例
//The following example attaches an HWND to the CWindow object and
//calls CWindow::ModifyStyleEx() to add and remove the extended
//window styles
CWindow myWindow;
myWindow.Attach(hWnd);
//The following line removes WS_EX_CONTEXTHELP extended style from
//the window and adds WS_EX_TOOLWINDOW extended style to the window
myWindow.ModifyStyleEx(WS_EX_CONTEXTHELP, WS_EX_TOOLWINDOW);
需要头文件
Header: atlwin.h
参考网址:http://msdn.microsoft.com/zh-cn/netframework/b1y6fbte.aspx
ModifyStyle,调用这个函数修改窗口的风格,此函数的厉害之处在于可以在窗口创建完成后修改窗口风格,虽然也有一些属性改不了。
参数:dwRemove 指定修改时要删除的窗风格。
dwAdd 指定修改时将要增加的窗口风格。
nFlags 该参数将被传给SetWindowPos,否则为0,如果SetWindowPos不被调用的话,一般该参数默认值
返回值:如果该函数成功调用返回一个非0值,否则返回0;
备注:如果nFlags不为0, ModifyStyle将调用Windows API 函数SetWindowPos并且结合nFlags和以下四个预先布置好的标志重画该窗口。
SWP_NOSIZE 保持当前大小。
SWP_NOMOVE 保持当前位置.。
SWP_NOZORDER 保持当前的Z次序。
SWP_NOACTIVATE 不激活该窗口。
用法:
1、修改控件的原有属性用 ModifyStyle(1,WS_DISABLED);(实际测试时只要是>=0的整形数就行)
2、改回来的话要用ModifyStyle(WS_DISABLED,1);(实际测试时只要是>=0的整形数就行)
如果把参数想像成布尔值的话就使用1这个整形数,要除去调控件的属性就让第一个参数dwRemove为真,修改回来就让第二个参数dwAdd为真.
参考代码:
void CMyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
ModifyStyle(0, WS_CLIPCHILDREN);
}