NMCUSTOMDRAW

来源:互联网 发布:金税盘开票软件最新版 编辑:程序博客网 时间:2024/05/01 10:30

NMCUSTOMDRAW

This structure contains information specific to an NM_CUSTOMDRAWnotification message.

typedef struct tagNMCUSTOMDRAWINFO{

NMHDR hdr;

DWORD dwDrawStage;

HDC hdc;

RECT rc;

DWORD dwItemSpec;

UINT uItemState;

LPARAM lItemlParam}

NMCUSTOMDRAW, FAR * LPNMCUSTOMDRAW;

Members

hdr

Handle to a NMHDRstructure that contains information about this notification message. 含有通知信息的 NMHDR 结构.

dwDrawStage

Specifies thecurrent drawing stage. 目前绘制的步骤. It is one of the following values.

Global Drawstage values:

Value

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 Drawstage values:

Value

Description

CDDS_ITEM

Indicates that the dwItemSpec, uItemState, and lItemParam 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. 表示绘制子项.

 

hdc

Handle to thecontrol’s device context. Use this HDC to perform any GDI functions. 设备上下文句柄.

rc

RECTstructure that describes the bounding rectangle of the area being drawn. 绘制的区域.

dwItemSpec

Specifies the itemnumber. This value is control specific, using the item-referencing conventionfor that control. 当前项的状态. Additionally, trackbar controls use the following values toidentify portions of control:

Value

Description

TBCD_CHANNEL

Identifies the channel that the trackbar control’s thumb marker slides along.

TBCD_THUMB

Identifies the trackbar control’s thumb marker. This is the portion of the control that the user moves.

TBCD_TICS

Identifies the increment tic marks that appear along the edge of the trackbar control.

 

uItemState

Specifies thecurrent item state. It can be a combination of the following values:

Value

Description

CDIS_CHECKED

The item is checked.

CDIS_DEFAULT

The item is in its default state.

CDIS_DISABLED

The item is disabled.

CDIS_FOCUS

The item is in focus.

CDIS_GRAYED

The item is grayed.

CDIS_HOT

The item is currently under the pointer (“hot”).

CDIS_SELECTED

The item is selected.

 

lItemlParam

Application-defineditem data. 应用程序定义的数据.

 

假如对话框有一个ListCtrl控件,ID为IDC_MY_LIST,使用方法:先添加一个消息映射:

ON_NOTIFY ( NM_CUSTOMDRAW,IDC_MY_LIST, OnCustomdrawMyList )

然后处理函数的原形如下:

afx_msg void OnCustomdrawMyList (NMHDR* pNMHDR, LRESULT* pResult );

这就告诉MFC要处理从ListCtrl控件发出的WM_NOTIFY消息,通知码为NM_CUSTOMDRAW,OnCustomdrawMyList就是处理函数。

假如有一个从ClistCtr派生的类,想为它添加customdraw,就可以使用ON_NOTIFY_REFLECT来代替:

ON_NOTIFY_REFLECT (NM_CUSTOMDRAW, OnCustomdraw )

 

OnCustomdraw的原形和上面的函数一致,但它是声明在ClistCtr派生的类里的。

Custom draw将控件的绘制分为两部分:擦除和绘画。Windows在每部分的开始和结束都会发送NM_CUSTOMDRAW消息。所以总共就有4个消息。但是实际上你的程序所收到消息可能就只有1个或者多于四个,这取决于你想要让WINDOWS怎么做。每次发送消息的时段被称作为一个绘画段。你必须紧紧抓住这个概念,因为它贯穿于整个重绘的过程。 

所以,你将会在以下的时间点收到通知:

         一个item被画之前——“绘画前

         一个item被画之后——“绘画后

         一个item被擦除之前——“擦除前

      一个item被擦除之后——“擦除后

 例:

void CEMyListCtrl::OnCustomdraw(NMHDR*pNMHDR, LRESULT *pResult)

{

    NMLVCUSTOMDRAW* pLVCD =reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);

    // Take the default processing unless weset this to something else below.

    *pResult = 0;

    // First thing - check the draw stage. Ifit's the control's prepaint

    // stage, then tell Windows we wantmessages for every item.

    if(CDDS_PREPAINT ==pLVCD->nmcd.dwDrawStage)

    {

        *pResult = CDRF_NOTIFYITEMDRAW;

    }

    else(CDDS_ITEMPREPAINT ==pLVCD->nmcd.dwDrawStage)

    {

        // This is the prepaint stage for anitem. Here's where we set the

        // item's text color. Our return valuewill tell Windows to draw the

        // item itself, but it will use the newcolor we set here.

        // We'll cycle the colors through red,green, and light blue.

        //COLORREF crText;

       COLORREFcrBkgnd;

        if((pLVCD->nmcd.dwItemSpec % 2) ==0)

       {

            //crText = RGB(255,0,0);

           crBkgnd= RGB(135,206,250);

       }

        else

       {

            //crText = RGB(128,128,255);

           crBkgnd= RGB(240,255,255);

       }

        //pLVCD->clrText = crText;

       pLVCD->clrTextBk= crBkgnd;

       *pResult= CDRF_DODEFAULT;

    }     

}

0 0
原创粉丝点击