简体   繁体   English

是否可以在edit内更改编辑控件的背景颜色?

[英]Is it possible to change a background color of an edit control inside edit?

I am writing a GUI wrapper for windows api right now ( i can't use qt or mfc ). 我现在正在为Windows api写一个GUI包装器(我不能使用qt或mfc)。 The library itself is extremely basic. 库本身是非常基础的。 After subclassing windows common controls ( and wrapping them into the classes ) i have faced a problem. 在将Windows的通用控件子类化(并将它们包装到类中)之后,我遇到了一个问题。 As far as i know (and i hope i am wrong), only parent control can handle a message like WM_CTLCOLOREDIT and the same. 据我所知(我希望我错了),只有父控件才能处理类似WM_CTLCOLOREDIT之类的消息。 But i want to be able to write something like this: 但是我希望能够写这样的东西:

myedit->SetBkColor ( RGB ( 0, 0, 0 ) ); myedit-> SetBkColor(RGB(0,0,0));

Is it possible to implement at all ( like in windows forms, for example ), or i should write a new controll from scratch, and write the painting by myself? 是否有可能完全实现(例如在Windows窗体中),或者我应该从头开始编写新的控件,然后自己写画?

Thank you, #535. 谢谢#535

You can do it, but it is a fair amount of work. 您可以做到,但是这是很多工作。 The basic idea is that you create another window to act as the parent to the control you're subclassing. 基本思想是,您创建另一个窗口作为要子类化的控件的父级。 In that, you keep track of whether a notification message (eg WM_CTLCOLOREDIT) is being handled by the parent or the sub-classed control itself. 这样,您可以跟踪通知消息(例如WM_CTLCOLOREDIT)是由父级控件还是由子类控件本身处理。 If it's being handled by the parent, it just passes the message through, but if it's supposed to be handled by the subclassed control itself, it reflects it back to the control. 如果它是由父级处理的,它只是传递消息,但是如果应该由子类控件本身处理,则它将消息反映回该控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM