gpt4 book ai didi

C++ Win32,编辑控件可以是所有者绘制的吗?

转载 作者:太空狗 更新时间:2023-10-29 21:23:35 26 4
gpt4 key购买 nike

我正在尝试让我的对话框匹配。我已经通过谷歌,随机测试等,甚至阅读了一些无法完成的地方。

我能做的是使用其中一条消息来设置字体和颜色,但没有绘制本身。

我认为它必须能够做到...

有人有什么想法吗?或者对此有所了解?

http://imageshack.com/a/img832/5955/91m.png

最佳答案

看起来编辑控件不支持所有者绘制,但您仍然可以解决您的直接问题。根据the MSDN page for EDITTEXT , 默认情况下,资源文件中的编辑控件具有 WS_BORDER 样式集。看起来你可以用这样的东西摆脱它:

EDITTEXT IDC_EDIT1,17,51,136,14,ES_AUTOHSCROLL | NOT WS_BORDER

对于状态栏,您可以尝试使用具有自定义颜色的静态控件而不是真实的状态栏。或者您可以自己动手,在资源文件中指定窗口类名称,并确保在显示对话框之前注册该类。

已更新:哇,状态栏的文档太糟糕了。不过,您可以自己画一张。请按照以下步骤操作:

// where hStatus is the HWND of a status bar...

// You must set simple mode to false, because simple mode doesn't
// support owner draw.

SendMessage(hStatus, SB_SIMPLE, FALSE, 0);

// I'm assuming 1 status bar part for demonstration. Setting the right edge
// for the 1 part to -1 make it take up the whole status bar.

int partWidths[] = { -1 };

SendMessage(hStatus, SB_PARTS, 1, reinterpret_cast<LPARAM>(partWidths));

// There is background stuff that stays behind even with owner draw,
// so you have to set the background color to black, too, to get rid of
// any appearance of borders.

SendMessage(hStatus, SB_SETBKCOLOR, 0, RGB(0, 0, 0));

// There is still a slim border that stays behind, so you need to set
// SBT_NOBORDERS in addition to SBT_OWNERDRAW. The 0 is the index of the
// status bar part. It could be anything between 0 and 255.

SendMessage(
hStatus,
SB_SETTEXT,
SBT_NOBORDERS | SBT_OWNERDRAW | 0,
reinterpret_cast<LPARAM>(_T("Status")));

从那里,您还必须处理状态栏的 WM_DRAWITEM。现在,至于为什么我说状态栏的文档很糟糕......

SB_SETTEXT 的文档说 WPARAM 的低位字的高字节可以是后面的值之一。这有两个问题:

  1. 您可以将它们结合起来,但您必须这样做才能发挥作用。 MFC 也这样做。我查过了。

  2. 您可能想编写 MAKEWPARAM(MAKEWORD(0, SBT_OWNERDRAW), 0)。这不会起作用。从外观上看,SBT_ 样式被定义为如果您只是将它们与您的索引值进行或运算,它们将自动出现在低字的高字节中。

我必须查看 MFC 源代码才能弄清楚如何正确使用 SB_SETTEXT 这说明了这一点。

关于C++ Win32,编辑控件可以是所有者绘制的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17961807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com