标题栏大小,字体设置

李水云 2018-04-11 02:34:16
自绘制标题栏还要加关闭、缩小按钮太麻烦。

怎么获取标题栏的宽度,设置标题栏字体大小。

有源码最好。

...全文
905 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2018-04-11
  • 打赏
  • 举报
回复
How to Draw a Custom Window Caption Last reviewed: November 2, 1995 Article ID: Q99046 The information in this article applies to: Microsoft Windows Software Development Kit (SDK) versions 3.1 Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows NT versions 3.5 and 3.51 - Microsoft Windows 95 version 4.0 SUMMARY Microsoft Windows draws captions in the caption bar (or title bar) for all eligible windows in the system. Applications need to specify only the WS_CAPTION style to take advantage of this facility. The current version of Microsoft Windows, however, imposes three significant restrictions on the captions. An application that does not want to be tied by any of these restrictions may want to draw its own caption. This article lists the restrictions and the steps required to draw a window caption. These restrictions also apply to Windows NT, but there are a few differences for Windows 95. It is important to note that an application should not draw its own caption unless it has very good reasons to do so. A window caption is a user interface object, and rendering it in ways different from other windows in the system may obstruct the user's conceptual grasp of the Microsoft Windows user interface. MORE INFORMATION Windows and Windows NT The three important restrictions imposed by Microsoft Windows version 3.1 and Microsoft Windows NT on the caption for a window are: - It consists of text only; graphics are not allowed. - All text is centered and drawn with the system font. - The length of the displayed caption is limited to 78 characters even when there is space on the caption bar to accommodate extra characters. An application can essentially render its own caption consisting of any graphic and text with the standard graphics and text primitives by painting on the nonclient area of the window. The application should draw in response to the WM_NCPAINT, WM_NCACTIVATE, WM_SETTEXT, and WM_SYSCOMMAND messages. When processing these messages, an application should first pass on the message to DefWindowProc() for default processing, then render its caption before returning from the message. This ensures that Microsoft Windows can properly draw the nonclient area. Because drawing the caption is part of DefWindowProc()'s nonclient area processing, an application should specify an empty window title to avoid any Windows-initiated drawing in the caption bar. The following steps indicate the computations needed to determine the caption drawing area: Get the current window's rectangle using GetWindowRect(). This includes client plus nonclient areas and is in screen coordinates. Get a device context (DC) to the window using GetWindowDC(). Compute the origin and dimensions of the caption bar. One needs to account for the window decorations (frame, border) and window bitmaps (min/max/system boxes). Remember that different window styles will result in different decorations and a different number of min/max/system boxes. Use GetSystemMetrics() to compute the dimensions of the frame, border, and the system bitmap dimensions. Render the caption within the boundaries of the rectangle computed in step 3. Remember that the user can change the caption bar color any time by using the Control Panel. Some components of the caption, particularly text backgrounds, may need to be changed based on the current caption bar color. Use GetSysColor to determine the current color. The following code sample draws a left-justified caption for a window (the code sample applies only to the case where the window is active): Sample Code case WM_NCACTIVATE: if ((BOOL)wParam == FALSE) { DefWindowProc( hWnd, message, wParam, lParam ); // Add code here to draw caption when window is inactive. return TRUE; } // Fall through if wParam == TRUE, i.e., window is active. case WM_NCPAINT: // Let Windows do what it usually does. Let the window caption // be empty to avoid any Windows-initiated caption bar drawing DefWindowProc( hWnd, message, wParam, lParam ); hDC = GetWindowDC( hWnd ); GetWindowRect( hWnd, (LPRECT)&rc2 ); // Compute the caption bar's origin. This window has a system box // a minimize box, a maximize box, and has a resizeable frame x = GetSystemMetrics( SM_CXSIZE ) + GetSystemMetrics( SM_CXBORDER ) + GetSystemMetrics( SM_CXFRAME ); y = GetSystemMetrics( SM_CYFRAME ); rc1.left = x; rc1.top = y; // 2*x gives twice the bitmap+border+frame size. Since there are // only two bitmaps, two borders, and one frame at the end of the // caption bar, subtract a frame to account for this. rc1.right = rc2.right - rc2.left - 2*x - GetSystemMetrics( SM_CXFRAME ); rc1.bottom = GetSystemMetrics( SM_CYSIZE ); // Render the caption. Use the active caption color as the text // background. SetBkColor( hDC, GetSysColor(COLOR_ACTIVECAPTION) ); DrawText( hDC, (LPSTR)"Left Justified Caption", -1, (LPRECT)&rc1, DT_LEFT ); ReleaseDC( hWnd, hDC ); break; Windows 95 On Windows 95, the text is not centered and the user can choose the Font. In addition, your application might want to monitor the WM_WININICHANGED message, because the user can change titlebar widths, and so forth, dynamically. When this happens, the application should take the new system metrics into account, and force a window redraw. -------------------------------------------------------------------------------- Additional reference words: 3.00 3.10 3.50 4.00 minimum maximum KbCategory: kbui kbcode KbSubCategory: UsrPnt THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Last reviewed: November 2, 1995 © 1998 Microsoft Corporation. All rights reserved. Terms of Use.
赵4老师 2018-04-11
  • 打赏
  • 举报
回复
Constant Name(Value)..Description --------------------------------- SM_CXSCREEN(0)........Width of screen SM_CYSCREEN(1)........Height of screen SM_CXFRAME(32)........Width of window frame that can be sized SM_CYFRAME(33)........Height of window frame that can be sized SM_CXVSCROLL(2).......Width of arrow bitmap on vertical scroll bar SM_CYVSCROL(20).......Height of arrow bitmap on vertical scroll bar SM_CXHSCROLL(21)......Width of arrow bitmap on horizontal scroll bar SM_CYHSCROLL(3).......Height of arrow bitmap on horizontal scroll bar SM_CYCAPTION(4).......Height of caption SM_CXBORDER(5)........Width of window frame that cannot be sized SM_CYBORDER(6)........Height of window frame that cannot be sized SM_CXDLGFRAME(7)......Width of frame when window has WS_DLGFRAME style SM_CYDLGFRAME(8)......Height of frame when window has WS_DLGFRAME style SM_CXHTHUMB(10).......Width of thumb on horizontal scroll bar SM_CYHTHUMB(9)........Height of thumb on horizontal scroll bar SM_CXICON(11).........Width of icon SM_CYICON(12).........Height of icon SM_CXCURSOR(13).......Width of cursor SM_CYCURSOR(14).......Height of cursor SM_CYMENU(15).........Height of single-line menu SM_CXFULLSCREEN(16)...Width of window client area for full-screen window SM_CYFULLSCREEN(17)...Height of window client area for full-screen window (height - caption) SM_CYKANJIWINDOW(18)..Height of Kanji window SM_CXMINTRACK(34).....Minimum tracking width of window SM_CYMINTRACK(35).....Minimum tracking height of window SM_CXMIN(28)..........Minimum width of window SM_CYMIN(29)..........Minimum width of window SM_CXSIZE(30).........Width of bitmaps contained in the title bar SM_CYSIZE(31).........Height of bitmaps contained in the title bar SM_MOUSEPRESENT(19)...Mouse present SM_DEBUG(22)..........Nonzero if Windows debug version
赵4老师 2018-04-11
  • 打赏
  • 举报
回复
标题栏宽度不就是窗口宽度减去边框宽度吗? GetWindowRect GetSystemMetrics SM_CXBORDER
李水云 2018-04-11
  • 打赏
  • 举报
回复
属性修改就不说了,那个知道。
目 录 第一章 开发环境 1.1 Qt 简介5 1.2 下载安装 Qt Creator 6 1.3 第一个程序 Hello World 7 第二章 窗体应用 1.1 窗体基类说明 12 1.2 控制窗体大小 13 1.3 窗体初始位置及背景色 13 1.4 修改标题栏图标 14 1.5 移动无边框窗体 16 1.6 去掉标题栏中最大化、最小化按钮 17 1.7 多窗体调用 18 1.8 字体形状窗体 20 第三章 控件应用 1.1 QPushButton按钮 23 1.2 QLabel标签 23 1.3 QLineEdit单行文本 24 1.4 QTextEdit多行文本 25 1.5 QPlainTextEdit多行文本 26 1.6 QComboBox下拉列表框 26 1.7 QFontComboBox字体下拉列表框 27 1.8 QSpinBox控件 28 1.9 QTimeEdit时间控件 29 1.10 QDateEdit日期控件 30 1.11 QScrollBar控件 30 1.12 QRadioButton单选按钮 31 1.13 QCheckBox复选框 32 1.14 QListView 列表控件 34 1.15 QTreeView树控件 34 1.16 QTableView表格控件 35 1.17 QHBoxLayout横向布局 36 1.18 QGridLayout网格布局 37 1.19 QGroupBox控件 38 1.20 QTabWidget控件 39 1.21 QMenu、QToolBar控件 41 1.22 任务栏托盘菜单 43 第四章 组件应用 1.1日历组件 47 1.2登录窗口 48 1.3文件浏览对话框 50 1.4颜色选择对话框 51 1.5进度条实例53 1.6Timer实时更新时间 54 第五章 文件操作 1.1创建文件夹 57 1.2写入文件 58 1.3修改文件内容 60 1.4删除文件 62 1.5修改文件名 63 1.6 INI文件写入操作 65 1.7 INI文件读取操作 68 1.8创建XML文件 71 1.9读取XML文件 72 第六章 图形图像操作 1.1绘制文字 75 1.2绘制线条 75 1.3绘制椭圆 77 1.4显示静态图像 78 1.5显示动态图像 78 1.6图片水平移动 79 1.7图片翻转 80 1.8图片缩放 82 1.9图片中加文字 84 1.10图像扭曲 85 1.11模糊效果 85 1.12着色效果 86 1.13阴影效果 87 1.14透明效果 87 第七章 多媒体应用 1.1音频、视频播放器 90 1.2播放Flash动画 94 1.3播放图片动画 95 第八章 系统操作 1.1获取屏幕分辨率 98 1.2获取本机名、IP地址 98 1.3根据网址获取IP地址 99 1.4判断键盘按下键值 100 1.5获取系统环境变量 101 1.6执行系统命令 102 第九章 注册表 1.0简要说明注册表 105 1.1写入注册表 105 1.2查找注册表 106 1.3修改IE浏览器的默认主页 107 第十章 数据库基础 1.1查询数据库驱动 109 1.2Qodbc连接Access数据库 109 1.3插入数据 111 1.4数据列表 112 1.5操作SQLite数据库 113 1.6SQLite数据库视图管理器 115 第十一章 网络开发 1.1点对点聊天服务端 119 1.2点对点聊天客户端 123 1.3局域网广播聊天 128 1.4SMTP协议发送邮件 148 1.5调用系统DLL判断网络连接状态 152 第十二章 进程与线程 1.1进程管理器 155 1.2线程QThread应用 158 1.3线程QRunnable应用 159 第十三章 数据安全 1.1 QByteArray加密数据 163 1.2 AES加密数据 164 1.3 MD5 加密数据 165 1.4 生成随机数 166 第十四章 打包部署 1.1 FilePacker 打包 169 1.2 Inno Setup 打包 174

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧