你的Button必须有BS_OWNERDRAW这个风格才可以的。

解决方案 »

  1.   

    我的CButton已经有BS_OWNERDRAW风格
      

  2.   

    我的CMyButton已经有BS_OWNERDRAW风格
      

  3.   

    WM_DRAWITEM是针对具有自绘制OnwerDraw风格的控件的.对于CButton类说来,必须是BS_OWNERDRAW风格的按钮
      

  4.   

    由虚函数DrawItem()来处理,如果你的button定义了BS_OWNERDRAW风格,你就需要重载这个函数,做你要做的事了。
      

  5.   

    LPDRAWITEMSTRUCT lpDrawItemStruct 
    填充这个结构
      

  6.   

    请问,WM_DRAWITEM消息为什么不能在CMyButton::WindowProc中收到?
      

  7.   

    该重新引用父类的virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); 
    至于原理不是很清楚, 期待高手的回答~~~~~DrawItem是否由消息产生? 
    如果是:
    1. 消息的来源
    2. 消息的传递
    如果不是:
    1. 函数传递的过程
      

  8.   

    The WM_DRAWITEM message is sent to the owner window of an owner-drawn button, combo box, list box, or menu when a visual aspect of the button, combo box, list box, or menu has changed. 
    A window receives this message through its WindowProc function. 
    WM_DRAWITEM是系统在控件显示状态改变(focused, active, or disable etc)时发送到父窗口的消息,你的CButton 当然不能自己接受这个消息来进行自绘操作了。你的drawing code应该放在DrawItem(...)函数中,MFC会负责在父窗口接受到WM_DRAWITEM时调用它
      

  9.   

    To masterz():
    "MFC会负责在父窗口接受到WM_DRAWITEM时调用它", 请解释一下这句好吗? 一直把DrawItem追溯到CWnd中, 是通过什么来把这个函数触发的呢? 谢谢~~~~
      

  10.   

    CMyButton: ownerdraw button
    CControlBar: parent window of the buttonCall stack is the following:CMyButton::DrawItem(tagDRAWITEMSTRUCT * 0x0012f80c) line 37
    CButton::OnChildNotify(unsigned int 43, unsigned int 103, long 1243148, long * 0x00000000) line 84
    CWnd::SendChildNotifyLastMsg(long * 0x00000000) line 2683
    CWnd::ReflectLastMsg(HWND__ * 0x00010a82, long * 0x00000000) line 2721
    CWnd::OnDrawItem(int 103, tagDRAWITEMSTRUCT * 0x0012f80c) line 1156 + 14 bytes
    CWnd::OnWndMsg(unsigned int 43, unsigned int 103, long 1243148, long * 0x0012f6b4) line 1930
    CControlBar::WindowProc(unsigned int 43, unsigned int 103, long 1243760) line 442 + 30 bytes
      

  11.   

    To masterz: 是啊~~但是最初的DrawItem是谁来触发的呢? 函数体中并没有对它的调用啊~~~~
    再请解释, 感激不尽~~~~~
      

  12.   

    下面是SDK程序中自绘按钮的例子,可以看出WM_DRAWITEM消息是由parent window处理的
    http://www.csdn.net/expert/topic/389/389181.shtm
      

  13.   

    To masterz: 
    我不是想知道这个消息是怎么处理的, 而是想知道它是怎么产生的, 就像WM_LBUTTONDOWN是由用户输入产生的, 可是WM_DRAWITEM是怎么产生的呢? 系统怎么样才会知道那个窗口是否要DrawItem??
      

  14.   

    请注意ondrawitem与drawitem 区别!!!