0

我正在编写 WindowsLISTBOX公共控件的超类版本以添加额外的功能。

标准控件将WM_CTLCOLORLISTBOX消息发送到其父级,从而允许在运行时在适当的消息处理程序中指定其文本和背景颜色。但是WM_CTLCOLORLISTBOX不会发送到控件本身,因此无法在内部进行封装和处理。

我试图解决的方案是根据控件的启用/禁用状态更改背景和文本颜色。无论其状态如何,让列表框背景保持相同阴影的标准行为对我来说看起来很丑陋且不一致。是否有另一种方法可以在封装设置这些值,但将所有其他绘画任务移交给基类窗口过程?

我想知道如何使用SetClassLongPtr(). 但是,这不仅不会解决文本颜色问题,而且如果我理解正确,它会更改当前存在的该类的所有控件的背景,而不是状态已更改的特定控件。

4

1 回答 1

0

The answer should be obvious - since WM_CTLCOLORLISTBOX is sent to the parent window, you have to subclass the parent window in order to receive the message. There is no getting around that. However, some wrapper UI frameworks, like VCL, are designed to forward such messages to the control that generated then, so controls can handle their own messages. But if you are not using a wrapper framework and are working with Win32 directly, you have to handle the parent messages yourself. Refer to MSDN for details about subclassing a given HWND:

Subclassing Controls

于 2014-12-05T19:37:31.940 回答