MFC去掉标题栏

 

在初始化的时候加入以下函数

//去掉标题栏
ModifyStyle(WS_CAPTION, NULL, SWP_DRAWFRAME );

转载于:https://my.oschina.net/Thekillersohot/blog/699583

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
要更改MFC对话框的标题栏颜色,您可以使用以下步骤: 1. 打开您的对话框类的头文件(例如"YourDialog.h")并添加以下代码: ``` afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); CBrush m_brush; // 声明一个画刷对象 ``` 2. 在您的对话框类的实现文件(例如"YourDialog.cpp")中,添加以下代码: ``` BEGIN_MESSAGE_MAP(YourDialog, CDialog) ON_WM_CTLCOLOR() END_MESSAGE_MAP() HBRUSH YourDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_DLG) { // 设置标题栏的颜色和背景 pDC->SetBkColor(RGB(255, 0, 0)); // 设置背景颜色为红色 pDC->SetTextColor(RGB(255, 255, 255)); // 设置文字颜色为白色 // 创建一个画刷对象并返回它 if (m_brush.m_hObject) m_brush.DeleteObject(); m_brush.CreateSolidBrush(RGB(255, 0, 0)); hbr = m_brush; } return hbr; } ``` 在这个函数中,我们重载了OnCtlColor函数。当nCtlColor参数为CTLCOLOR_DLG时,意味着我们正在处理对话框的背景和文本颜色。我们设置标题栏的背景颜色和文本颜色,然后创建一个画刷对象并将其返回。 3. 在您的对话框类的OnInitDialog函数中,添加以下代码: ``` // 去掉标题栏的默认按钮 LONG lStyle = GetWindowLong(m_hWnd, GWL_STYLE); lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); SetWindowLong(m_hWnd, GWL_STYLE, lStyle); // 重新计算窗口大小 CRect rect; GetWindowRect(&rect); SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); ``` 这将去掉默认的标题栏按钮,并重新计算窗口的大小。 4. 编译并运行程序,您应该看到对话框的标题栏已经更改为红色并且文本颜色为白色。 请注意,这种方法只适用于MFC对话框,对于其他类型的窗口可能需要不同的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值