我有一个Static控件,想要不断的变化文本的颜色
所以需要向其父窗口发送WM_CTLCOLOR消息,但我试了好多次都不行,不知这个SendMessage函数应该怎样写呢?参数是怎么样的呢?怎样让父窗口知道是哪个控件要改变颜色呢?
谢谢大家帮忙,知道的麻烦告诉我一下,或者给点建议我试一下,谢谢!

解决方案 »

  1.   

    ::SendMessage(hwnd,WM_CTLCOLOR,0,0);
    hwnd是父窗口句柄
      

  2.   

    向其父窗口发送WM_CTLCOLOR消息~~
    ::SendMessage(hwnd,WM_CTLCOLOR,0,0);
    其中hwnd你要自己获取父窗口的句柄,WM_CTLCOLOR消息要自己在父窗口里面实现消息处理~~~
      

  3.   

    TN062: Message Reflection for Windows Controls
    This technical note describes message reflection, a new feature in MFC 4.0. It also contains directions for creating a simple reusable control that uses message reflection.This technical note does not discuss message reflection as it applies to ActiveX controls (formerly called OLE controls). Please see the articleActiveX Controls: Subclassing a Windows Control in Visual C++ Programmer's Guide.What Is Message Reflection?Windows controls frequently send notification messages to their parent windows. For instance, many controls send a control color notification message (WM_CTLCOLOR or one of its variants) to their parent to allow the parent to supply a brush for painting the background of the control.In Windows and in MFC prior to version 4.0, the parent window, often a dialog box, is responsible for handling these messages. This means that the code for handling the message needs to be in the parent window’s class and that it has to be duplicated in every class that needs to handle that message. In the case above, every dialog box that wanted controls with custom backgrounds would have to handle the control color notification message. It would be much easier to reuse code if a control class could be written that would handle its own background color.In MFC 4.0, the old mechanism still works—parent windows can handle notification messages. In addition, however, MFC 4.0 facilitates reuse by providing a feature called “message reflection” that allows these notification messages to be handled in either the child control window or the parent window, or in both. In the control background color example, you can now write a control class that sets its own background color by handling the reflected WM_CTLCOLOR message—all without relying on the parent. (Note that since message reflection is implemented by MFC, not by Windows, the parent window class must be derived from CWnd for message reflection to work.)Older versions of MFC did something similar to message reflection by providing virtual functions for a few messages, such as messages for owner-drawn list boxes (WM_DRAWITEM, and so on). The new message reflection mechanism is generalized and consistent.Message reflection is backward compatible with code written for versions of MFC previous to 4.0. If you have supplied a handler for a specific message, or for a range of messages, in your parent window's class, it will override reflected message handlers for the same message provided you don't call the base class handler function in your own handler. For example, if you handle WM_CTLCOLOR in your dialog box class, your handling will override any reflected message handlers.If, in your parent window class, you supply a handler for a specific WM_NOTIFY message or a range of WM_NOTIFY messages, your handler will be called only if the child control sending those messages does not have a reflected message handler through ON_NOTIFY_REFLECT(). If you use ON_NOTIFY_REFLECT_EX() in your message map, your message handler may or may not allow the parent window to handle the message. If the handler returns TRUE, the message will be handled by the parent as well, while a call that returns FALSE does not allow the parent to handle it. Note that the reflected message is handled before the notification message.When a WM_NOTIFY message is sent, the control is offered the first chance to handle it. If any other reflected message is sent, the parent window has the first chance to handle it and the control will receive the reflected message. To do so, it will need a handler function and an appropriate entry in the control's class message map.The message-map macro for reflected messages is slightly different than for regular notifications: it has _REFLECT appended to its usual name. For instance, to handle a WM_NOTIFY message in the parent, you use the macro ON_NOTIFY in the parent’s message map. To handle the reflected message in the child control, use the ON_NOTIFY_REFLECT macro in the child control’s message map. In some cases, the parameters are different, as well. Note that ClassWizard can usually add the message-map entries for you and provide skeleton function implementations with correct parameters.
      

  4.   

    ::SendMessage(hwnd,WM_CTLCOLOR,0,0);
    我是这么写的,可是没用啊,颜色没变
      

  5.   

    send 过后还要接受
    并区别是福窗口接收,还是文本框接收
      

  6.   

    这个消息不是控件自己发的吗?你redraw static control应该就会发了吧?
      

  7.   

    是的,但问题就是我不知道怎么让它redraw呢?
    我在class wizard里找了,Static控件没有redraw的消息响应啊.
      

  8.   

    调static窗口的Invalidate应该就可以了
      

  9.   

    啊没错,确实只要调用它的Invalidate函数就行了
    谢谢了
    不过看了msdn我还是不怎么明白Invalidte是干什么的,说是什么擦除用户区什么的,不明白~
      

  10.   

    invalidate就是告诉系统这个窗口现在画的东西是不对(过时了的),你给我重新画一次.