我写了一个继承自CStatic的类,但却没有虚函数DrawItem供覆盖,怎么回事?

yuefeng521521521 2003-09-17 08:14:40
class CMyStatic : public CStatic
在用ClassWizard添加虚函数时,没有看到DrawItem,

可是继承自CButton的类就可以改写这个函数,why??

...全文
436 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuefeng521521521 2003-09-17
  • 打赏
  • 举报
回复
to bcpl(闲庭信步)
你的那个改写虚函数的方法好使,我试过了
谢谢
bcpl 2003-09-17
  • 打赏
  • 举报
回复
封装性不好,还是用OnChildNotify比较好
xghost 2003-09-17
  • 打赏
  • 举报
回复
CStatic::DrawItem 虚函数可能在 VS.NET 的MFC中使用的,不知是否这样...
xghost 2003-09-17
  • 打赏
  • 举报
回复
Owner-Drawn Static Control
By using the SS_OWNERDRAW style, an application can take responsibility for painting a static control. The parent window of an owner-drawn static control (its owner) receives a WM_DRAWITEM message whenever the static control needs to be painted. The message includes the address of a DRAWITEMSTRUCT structure that contains information that the owner window uses when drawing the control.

按上面的说法,你在父窗口拦截WM_DRAWITEM 消息就可以自绘Static Control 了
bcpl 2003-09-17
  • 打赏
  • 举报
回复
我的是October 2001
flinming 2003-09-17
  • 打赏
  • 举报
回复
学习。。。。。。。。。。。。。
yuefeng521521521 2003-09-17
  • 打赏
  • 举报
回复
我的MSDN版本为:January 2002
xghost 2003-09-17
  • 打赏
  • 举报
回复
CStatic类没有DrawItem虚函数
yuefeng521521521 2003-09-17
  • 打赏
  • 举报
回复
查CStatic类的Class Member
最后一个函数就是


Overridables

DrawItem Override to draw an owner-drawn static control.

CStatic::DrawItem
Called by the framework to draw an owner-drawn static control.

virtual void DrawItem(
LPDRAWITEMSTRUCT lpDrawItemStruct
);
bcpl 2003-09-17
  • 打赏
  • 举报
回复
可是我在MSDN中看到了CStatic类的DrawItem虚函数了啊!?
我查不到..
bcpl 2003-09-17
  • 打赏
  • 举报
回复
看来我说错了,上面的列表中就有ODT_STATIC(:(),static也可以有SS_OWNERDRAW风格,只是MFC没帮你加DrawItem虚函数,要自己加

1. 改写虚函数OnChildNotify
BOOL CMyStatic::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if (message != WM_DRAWITEM)
return CWnd::OnChildNotify(message, wParam, lParam, pResult);

ASSERT(pResult == NULL); // no return value expected
UNUSED(pResult); // unused in release builds

DrawItem((LPDRAWITEMSTRUCT)lParam);
return TRUE;
}

2. 加上成员函数
void DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// 在这里自画
}
yuefeng521521521 2003-09-17
  • 打赏
  • 举报
回复
可是我在MSDN中看到了CStatic类的DrawItem虚函数了啊!

CStatic MembersSee Also
CStatic Overview | Hierarchy Chart
Base Class Members

CObject Members

CCmdTarget Members

CWnd Members
。。。
Overridables

DrawItem Override to draw an owner-drawn static control.
bcpl 2003-09-17
  • 打赏
  • 举报
回复
DrawItem并不是通用的CWnd虚函数,只适用于可拥有自画风格(会发送WM_DRAWITEM消息)的控件:
ODT_BUTTON Owner-drawn button
ODT_COMBOBOX Owner-drawn combo box
ODT_LISTBOX Owner-drawn list box
ODT_LISTVIEW List view control
ODT_MENU Owner-drawn menu item
ODT_STATIC Owner-drawn static control
ODT_TAB
对于static控件,可以通过处理WM_PAINT实现自画

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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