CUSTOMDRAW和OwnerDraw

1.Owner Draw

当Button控件被设置成OwnerDraw属性时,父窗体就会接受到WM_DRAWITEM、WM_MEASUREITEM、WM_COMPAREITEM、WM_DELETEITEM四个消息。

除了Button空间外,还有ListBox控件设置CBS_OWNERDRAWVARIABLE属性。

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.

在MFC中,已经将这个4个消息反射到子控件的类中,如
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct);


2.Custom Draw

如下控件都支持Custom Draw。



父窗体会收到NM_CUSTOMDRAW的通知消息。即

WM_NOTIFY idCtrl = (int) wParam;

pnmh = (LPNMHDR) lParam;
typedef struct tagNMHDR {
HWND hwndFrom;
UINT idFrom;
UINT code; //通知消息码
} NMHDR;

当控制码是NM_CUSTOMDRAW时候
#ifdef LIST_VIEW_CUSTOM_DRAW
lpNMCustomDraw = (LPNMLVCUSTOMDRAW) lParam;
#elif TOOL_TIPS_CUSTOM_DRAW
lpNMCustomDraw = (LPNMTTCUSTOMDRAW) lParam;
#elif TREE_VIEW_CUSTOM_DRAW
lpNMCustomDraw = (LPNMTVCUSTOMDRAW) lParam;
#elif TOOL_BAR_CUSTOM_DRAW
lpNMCustomDraw = (LPNMTBCUSTOMDRAW) lParam;
#else
lpNMCustomDraw = (LPNMCUSTOMDRAW) lParam;
#endif
lpNMCustomDraw->dwDrawStage有如下几种可能

Global Values
Description

CDDS_POSTERASE
After the erasing cycle is complete.

CDDS_POSTPAINT
After the painting cycle is complete.

CDDS_PREERASE
Before the erasing cycle begins.

CDDS_PREPAINT
Before the painting cycle begins.

Item-specific Values
Description

CDDS_ITEM
Indicates that the dwItemSpec, uItemState, and lItemlParam members are valid.

CDDS_ITEMPOSTERASE
After an item has been erased.

CDDS_ITEMPOSTPAINT
After an item has been drawn.

CDDS_ITEMPREERASE
Before an item is erased.

CDDS_ITEMPREPAINT
Before an item is drawn.

CDDS_SUBITEM
Version 4.71. Flag combined with CDDS_ITEMPREPAINT or CDDS_ITEMPOSTPAINT if a subitem is being drawn. This will only be set if CDRF_NOTIFYITEMDRAW is returned from CDDS_PREPAINT.

在MFC或WTL中,已经反射到子控件,并封装好如下函数
DWORD OnPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD);
DWORD OnPostPaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD);
DWORD OnPreErase(int idCtrl, LPNMCUSTOMDRAW lpNMCD);
DWORD OnPostErase(int idCtrl, LPNMCUSTOMDRAW lpNMCD);

DWORD OnItemPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD);
DWORD OnItemPostPaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD);
DWORD OnItemPreErase(int idCtrl, LPNMCUSTOMDRAW lpNMCD);
DWORD OnItemPostEraset(int idCtrl, LPNMCUSTOMDRAW lpNMCD);

DWORD OnSubItemPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD);

转载于:https://www.cnblogs.com/BeyondTechnology/archive/2011/03/25/1995944.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值