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

red-fly 2004-01-07 07:12:48
我從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的話,也是一樣,一運行就出錯!!!!

我搞不定了

誰幫我搞一下? 我可以把我的代碼發過去,留 下你的email就行

搞定後,給你我的所有 ^-^
...全文
154 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
red-fly 2004-01-07
  • 打赏
  • 举报
回复
搞定了!

謝謝樓上的各位啦!

我自已沒有看清楚,是那個 virtual 函數,而不是那個 afx_msg 函數

自己太大意了!
red-fly 2004-01-07
  • 打赏
  • 举报
回复
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來的
我在這個函數裡下個斷點,調試就沒有運行到這裡
liu_swallow 2004-01-07
  • 打赏
  • 举报
回复
指定了BS_OWNERDRAW自绘风格,就必须重载virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
因为原来的:
void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
ASSERT(FALSE);
}
ddszhan 2004-01-07
  • 打赏
  • 举报
回复
指定了BS_OWNERDRAW自绘风格,就必须重载virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
因为原来的:
void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
ASSERT(FALSE);
}
greensofter 2004-01-07
  • 打赏
  • 举报
回复
必须重载虚函数virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );

bcpl 2004-01-07
  • 打赏
  • 举报
回复
是不是没改写CButton的虚函数
virtual void DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct)
feiniaoliang 2004-01-07
  • 打赏
  • 举报
回复
发给我看下
Eugen_Li@hotmail.com

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧