MFC代码修改窗口属性

在创建窗口时属性页中的属性都是可以通过代码来动态设置的


主要用到两个函数

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)






  • 4
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Barry__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值