在创建窗口时属性页中的属性都是可以通过代码来动态设置的
主要用到两个函数
GetWindowLongPtr(__in HWND hWnd,//窗口句柄
__in int nIndex //要获取的类型
);
SetWindowLongPtr(
__in HWND hWnd, //窗口句柄
__in int nIndex, //要设置的类型
__in LONG dwNewLong//设置的值
);
或者
BOOL ModifyStyle
(
DWORD dwRemove,
DWORD dwAdd,
UINT nFlags=0
);
基本步骤为:
1.取得窗口当前属性值
2.修改属性值
3.设置新的属性值
或者
ModifyStyle修改窗口属性
代码示例:
//取得窗口当前属性值
LONG_PTR Style = ::GetWindowLongPtr(pMainDlg->m_hWnd,GWL_STYLE);
//修改属性值(取消标题栏,取消系统按钮,取消边框)
Style = Style &~WS_CAPTION &~WS_SYSMENU &~WS_SIZEBOX;
//设置修改后的属性值
::SetWindowLongPtr(pMainDlg->m_hWnd, GWL_STYLE, Style);
常见窗口属性值:
/*
* Window Styles窗口属性
*/
#define WS_OVERLAPPED 0x00000000L //重叠
#define WS_POPUP 0x80000000L //弹出式
#define WS_CHILD 0x40000000L //子类型
#define WS_MINIMIZE 0x20000000L //最小化状态
#define WS_VISIBLE 0x10000000L //可见
#define WS_DISABLED 0x08000000L //可用
#define WS_CLIPSIBLINGS 0x04000000L //
#define WS_CLIPCHILDREN 0x02000000L //
#define WS_MAXIMIZE 0x01000000L //最大化状态
#define WS_CAPTION 0x00C00000L /* WS_BORDER | WS_DLGFRAME */
#define WS_BORDER 0x00800000L //边框
#define WS_DLGFRAME 0x00400000L //边框类型
#define WS_VSCROLL 0x00200000L //垂直滚动条
#define WS_HSCROLL 0x00100000L //水平滚动条
#define WS_SYSMENU 0x00080000L //系统菜单
#define WS_THICKFRAME 0x00040000L //边框类型
#define WS_GROUP 0x00020000L //
#define WS_TABSTOP 0x00010000L //
#define WS_MINIMIZEBOX 0x00020000L //最小化按钮
#define WS_MAXIMIZEBOX 0x00010000L //最大化按钮
#define WS_TILED WS_OVERLAPPED /
#define WS_ICONIC WS_MINIMIZE
#define WS_SIZEBOX WS_THICKFRAME
#define WS_TILEDWINDOW WS_OVERLAPPEDWINDOW
/*
* Common Window Styles 组合窗口属性
*/
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | \
WS_CAPTION | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_MINIMIZEBOX | \
WS_MAXIMIZEBOX) //重叠窗口
#define WS_POPUPWINDOW (WS_POPUP | \
WS_BORDER | \
WS_SYSMENU) //弹出式窗口
#define WS_CHILDWINDOW (WS_CHILD) //子窗口
/*
* Extended Window Styles 扩展的窗口属性
*/
#define WS_EX_DLGMODALFRAME 0x00000001L //
#define WS_EX_NOPARENTNOTIFY 0x00000004L //
#define WS_EX_TOPMOST 0x00000008L //
#define WS_EX_ACCEPTFILES 0x00000010L //
#define WS_EX_TRANSPARENT 0x00000020L //
#if(WINVER >= 0x0400)
#define WS_EX_MDICHILD 0x00000040L //
#define WS_EX_TOOLWINDOW 0x00000080L //
#define WS_EX_WINDOWEDGE 0x00000100L //
#define WS_EX_CLIENTEDGE 0x00000200L //
#define WS_EX_CONTEXTHELP 0x00000400L //
#endif /* WINVER >= 0x0400 */
#if(WINVER >= 0x0400)
#define WS_EX_RIGHT 0x00001000L
#define WS_EX_LEFT 0x00000000L
#define WS_EX_RTLREADING 0x00002000L
#define WS_EX_LTRREADING 0x00000000L
#define WS_EX_LEFTSCROLLBAR 0x00004000L
#define WS_EX_RIGHTSCROLLBAR 0x00000000L
#define WS_EX_CONTROLPARENT 0x00010000L
#define WS_EX_STATICEDGE 0x00020000L
#define WS_EX_APPWINDOW 0x00040000L
#define WS_EX_OVERLAPPEDWINDOW (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)
#define WS_EX_PALETTEWINDOW (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST)