如何将静态标签中的文本设置为粗体样式?

发布于 2024-09-14 20:26:33 字数 343 浏览 4 评论 0原文

我正在为 Pocket PC 2003 设备编写一个应用程序。其中有一个对话框,其中显示各种文本信息。信息被分开,以便每个部分都驻留在其自己的标签内,在资源文件中定义为 LTEXT。

现在我的问题是,目前所有文本标签都具有相同的字体和样式(正常或简单,即不是粗体或斜体);我希望将其设置为粗体。我知道我可以在资源文件中将字体设置为粗体,但这会设置所有标签的样式。

如何实现这一目标?我已经看到它在 Windows 的“关于”屏幕中使用,所以我知道这是可能的。我直接使用 Win32 API 用 C++ 编写了程序(除了我使用资源文件的某些对话框),因此如果以相同的语言和方法给出答案,我将不胜感激。

谢谢。

I'm writing an application for a Pocket PC 2003 device. In it there is a dialog where various text information is shown. The information is separated so that each piece resides inside its own label, defined as LTEXT in the resource file.

Now my problem is that, at the moment, all text lables have the same font and style (normal or simple, i.e. not bold or italic); I want want one to be set in bold. I know that I can set the font to bold in the resource file, but that sets the style of all labels.

How does one achieve this? I've seen it be used in the Windows 'About' screen so I know it's possible. I've written the program in C++ using the Win32 API directly (except for certain dialogs where I've used the resource file) so I would appreciate if the answer was given in the same language and approach.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2024-09-21 20:26:33

在资源编辑器中,编辑静态文本项,并将其控件 ID 更改为唯一的内容:例如 IDC_BOLD。

在承载该控件的对话框的 DialogProc 中,添加一个 WM_CTLCOLORSTATIC 处理程序:

case WM_CTLCOLORSTATIC:
  HDC hdc;
  HWND hwndCtl;
  hwndCtl = (HWND) lParam;
  hdc = (HDC) wParam;

  if( GetWindowLong(hwndClt, GWL_ID ) == IDC_BOLD )
  {
    SetBkMode(hdc,TRANSPARENT);
    SetTextColor(hdc,RGB(0xff,0,0)); // turn the text red for fun :)
    SelectObject(hdc,hBoldFont);     // but you want this...
    return (INT_PTR)GetSysColorBrush(COLOR_BTNFACE); 
    //return 0L; // if visual themes are enabled (common controls 6) then 0 is better.
  }
  // default processing
  return 0;

您正在为 Pocket PC 2003 进行开发,我不知道有哪些按钮样式可用。 此页面当然指的是桌面XP。但是,如果对话框中的按钮不是纯灰色 95esq 按钮,则返回 0 可能更合适,因为如果对话框背景不是纯灰色,则可以正确绘制文本背景。

预视觉样式返回 0 会导致系统重置 DC,因此了解哪个返回值合适很重要。

In the resource editor, edit the static text item, and change its control ID to something unique: IDC_BOLD for example.

In the DialogProc for the dialog boxes that is hosting the control, add a WM_CTLCOLORSTATIC handler:

case WM_CTLCOLORSTATIC:
  HDC hdc;
  HWND hwndCtl;
  hwndCtl = (HWND) lParam;
  hdc = (HDC) wParam;

  if( GetWindowLong(hwndClt, GWL_ID ) == IDC_BOLD )
  {
    SetBkMode(hdc,TRANSPARENT);
    SetTextColor(hdc,RGB(0xff,0,0)); // turn the text red for fun :)
    SelectObject(hdc,hBoldFont);     // but you want this...
    return (INT_PTR)GetSysColorBrush(COLOR_BTNFACE); 
    //return 0L; // if visual themes are enabled (common controls 6) then 0 is better.
  }
  // default processing
  return 0;

You are developing for Pocket PC 2003, I don't know what buttons styles are available. This Page refers of course to desktop XP. But, if the buttons in the dialogs are not flat grey 95esq buttons, then it might be more appropriate to return 0 as that will paint the text background correctly if the dialogs background is not plain grey.

Pre-visual styles a return of 0 causes the system to reset the DC so its important to know which return is appropriate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文