為什麼我的派生按鈕的自畫ownerdraw功能總是出錯?

我從CButton派生出一個個自已的類CMyButton  
  然後在窗體中聲明一個  
  CMyButton   m_btnTest;  
  然後在窗體的OnInitialDialog中寫  
  m_btnTest.Create(...,   WS_CHILD|WS_VISIBLE,...);  
  再CMyButton::PreSubclassWindow()    
  {  
  //   TODO:   Add   your   specialized   code   here   and/or   call   the   base   class  
   
  CButton::PreSubclassWindow();  
  ModifyStyle(0,BS_OWNERDRAW);  
  }  
   
  一運行就出錯,我在Create   時加入BS_OWNERDRAW的話,也是一樣,一運行就出錯!!!!

 

 

1 楼feiniaoliang(♂飞鸟良♀)回复于 2004-01-07 19:56:33 得分 5

发给我看下  
  Eugen_Li@hotmail.comTop

2 楼bcpl(林平之)回复于 2004-01-07 20:55:38 得分 22

是不是没改写CButton的虚函数  
  virtual   void   DrawItem   (LPDRAWITEMSTRUCT   lpDrawItemStruct)Top

3 楼greensofter(MC.CN)回复于 2004-01-07 20:57:13 得分 22

必须重载虚函数virtual   void   DrawItem(   LPDRAWITEMSTRUCT   lpDrawItemStruct   );  
   
  Top

4 楼ddszhan(高等数学)回复于 2004-01-07 22:56:38 得分 22

指定了BS_OWNERDRAW自绘风格,就必须重载virtual   void   DrawItem(   LPDRAWITEMSTRUCT   lpDrawItemStruct   );  
  因为原来的:  
  void   DrawItem(   LPDRAWITEMSTRUCT   lpDrawItemStruct   )  
  {  
  ASSERT(FALSE);  
  }Top

5 楼liu_swallow(swallow)回复于 2004-01-07 23:01:43 得分 15

指定了BS_OWNERDRAW自绘风格,就必须重载virtual   void   DrawItem(   LPDRAWITEMSTRUCT   lpDrawItemStruct   );  
  因为原来的:  
  void   DrawItem(   LPDRAWITEMSTRUCT   lpDrawItemStruct   )  
  {  
  ASSERT(FALSE);  
  }  
  Top

6 楼jszj(老板说mis部不是赚钱的部门...)回复于 2004-01-07 23:21:51 得分 0

void   CSelfDrawButton::OnDrawItem(int   nIDCtl,   LPDRAWITEMSTRUCT   lpDrawItemStruct)    
  {  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
  LPDRAWITEMSTRUCT   lpdis   =   lpDrawItemStruct;  
   
  //RECT   rc;//   =   lpdis->rcItem;  
   
  //CButton::OnDrawItem(nIDCtl,   lpDrawItemStruct);  
  }  
  //注意:   CSelfDrawButton就是最上邊我寫的CMyButton,這裡是從代碼裡copy來的  
  我在這個函數裡下個斷點,調試就沒有運行到這裡Top

7 楼jszj(老板说mis部不是赚钱的部门...)回复于 2004-01-07 23:25:54 得分 0

搞定了!  
   
    謝謝樓上的各位啦!  
   
  我自已沒有看清楚,是那個   virtual   函數,而不是那個   afx_msg   函數  
   
  自己太大意了!

posted @ 2009-01-07 13:37  小奇偶  阅读(462)  评论(0编辑  收藏  举报