自己跟踪一下吧。
至于调用,看看msdn

解决方案 »

  1.   

    看看侯老师《深入浅出MFC》的书你肯定有启发。
      

  2.   

    onpaint 是一个消息,drawitem是一个虚函数,onpaint是当系统发送wm_paint消息时才调用,一般是系统调用,而drawitem需要重载,若要强行调用onpaint函数,需要手工发送wm—paint消息,或者用invalidate函数,drawitem仅重载就行了onpaint是对所有的屏幕进行刷新,drawitem可以设定刷新的控件的类型,其参数就是对控件类型的说明。
      

  3.   

    界面稍有变化就会引发OnDrawItem
      

  4.   

    if you use MFC
    OnPaint() be called by Frame(框架)if you overload the OnPaint() then OnDraw() must be called in OnPaint() by yourself控件必须设置成自绘制,OnDrawItem()才会起作用
      

  5.   

    我onpaint()和drawitem()两个都重载了
    我在onpaint()里给控件画背景,但是我发现重载
    onpaint()以后,在drawitem里画的东西就不显示了
    这是怎么回事?还有顺便问一下ondrawitem()和drawitem()有什么区别?
    这个问题再解决了马上分分
      

  6.   

    The framework calls OnDrawItem() function for the owner of an owner-draw button control, combo-box control, list-box control, or menu when a visual aspect of the control or menu has changed.
    then the DrawItem virtual function of the appropriate class is called. 
      

  7.   

    shenyc(shenyc)说得对,在不重载OnPaint()时,系统会自动调用OnDraw() 在重载了OnPaint()之后就得自己手动调用OnDraw()了,
      

  8.   

    OnDraw不是消息响应函数,我想OnDraw在OnPaint没有被重载时,系统会自动在某个消息映射函数(不知道是不是OnPaint)内调用它,而OnPaint则被映射为WM_PAINT消息的响应函数,在OnPaint被重载了以后,此时OnDraw就不会被系统自动调用。看MSDN好象也没有说清楚到底两者关系怎么样
      

  9.   

    自绘控件时调用OnDrawItem()就可以了,不用重载OnPaint()吧。
    The WM_PAINT message is sent <when the system or another application makes a request to paint a portion of an application's window>. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.
    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>.
    我觉得两个消息的区别就在我打了<>的地方。当后者被发送时前者就不用理会了,windows(或mfc)会自己打点好的。
      

  10.   

    OnPaint是View的客户区需要刷新时用 的
    OnDrawItem是控件中的某某数据项需要刷新时用的
      

  11.   

    OnPaint调用DrawItem,DrawItem用法如下:void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
      UINT uStyle = DFCS_BUTTONPUSH;  // This code only works with buttons.
      ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);  // If drawing selected, add the pushed style to DrawFrameControl.
      if (lpDrawItemStruct->itemState & ODS_SELECTED)
        uStyle |= DFCS_PUSHED;  // Draw the button frame.
      ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, 
        DFC_BUTTON, uStyle);  // Get the button's text.
      CString strText;
      GetWindowText(strText);  // Draw the button text using the text color red.
      COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
      ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), 
        &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
      ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
    }
      

  12.   

    我想给分,但是告诉我说"贴子回复次数大于跟给分次数 "是什么意思顺便再问一下,基于对话框的程序好像没有 ondraw()还用不用自己调用?
      

  13.   

    OnDraw是虚函数,需要时可重载.
      

  14.   

    OnDraw()一般用在Document/View结构中
      

  15.   

    cdialog好象没有ondraw这个函数,ondraw好象是cview独有的
    msdn上好象是说cdialog的paint就相当于cview的ondraw,这样理解对不对还有我现在不能给分是怎么回事?
    "贴子回复次数大于跟给分次数 "
      

  16.   

    cdialog好象没有ondraw这个函数,ondraw好象是cview独有的
    msdn上好象是说cdialog的paint就相当于cview的ondraw,这样理解对不对还有我现在不能给分是怎么回事?
    "贴子回复次数大于跟给分次数 "
      

  17.   

    onpaint调用OnDraw()
    Onpaint()中用CPaintDC;
    CPaintDC的构造函数调用BeginPaint  解构函数Endpaint()
    防止WM_PAINT不断发出
    OnPaint()是WM_PAINT的消息处理函数
      

  18.   

    对,CDialog没有OnDraw,用WM_PAINT一样.
      

  19.   

    OnPaint()和OnDrawItem()没有太大的联系当 windows要显示某一区域(很多时候是指窗口——CView和CWnd)时就要发送WM_PAINT消息,然后就调用OnPaint()函数。OnDrawItem()是显示控件时,把绘制控件细节的控制权交给编程的人。