Why is CLISTCTRL?

zhaozj2021-02-16  194

1. Define message mapping functions

H File: AFX_MSG Void OncustomDraw (NmHDR * PNMHDR, LRESULT * PRESULT); CPP file: on_notify_reflect (nm_customdraw, oncustomDraw)

void CMyListCtrl :: OnCustomdraw (NMHDR * pNMHDR, LRESULT * pResult) {NMLVCUSTOMDRAW * pLVCD = reinterpret_cast (pNMHDR); * pResult = 0; USES_CONVERSION; // Request item-specific notifications if this is the // beginning of . the paint cycle if (CDDS_PREPAINT == pLVCD-> nmcd.dwDrawStage) {* pResult = CDRF_NOTIFYITEMDRAW;} else if (CDDS_ITEMPREPAINT == pLVCD-> nmcd.dwDrawStage) {// This is the beginning of an item's paint cycle LVITEM. rItem; int nItem = static_cast (pLVCD-> nmcd.dwItemSpec); CDC * pDC = CDC :: FromHandle (pLVCD-> nmcd.hdc); COLORREF crBkgnd; BOOL bListHasFocus; CRect rcItem; CRect rcText, rcText1; CString sText; UINT uFormat; CImageList * pImage = CListCtrl :: GetImageList (LVSIL_SMALL); bListHasFocus = (GetSafeHwnd () == :: GetFocus ()); // Get the image index and selected / focused state of the // item b eing drawn ZeroMemory (& rItem, sizeof (LVITEM));. rItem.mask = LVIF_IMAGE | LVIF_STATE | LVIF_TEXT; rItem.iItem = nItem; rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; GetItem (& rItem); // Get the rect that bounds the text label GetItemRect (nItem, rcItem, LVIR_BOUNDS);. // Draw the background of the list item Colors are selected // according to the item's state if (rItem.state & LVIS_SELECTED).. {crBkgnd = RGB (198,227,231);} Else {crbkgnd = RGB (255, 255, 255);} // Draw the Background &

. Prep the DC for the text drawing Note // that the entire item RECT is filled in, so this emulates the full- // row selection style of normal lists pDC-> FillSolidRect (rcItem, crBkgnd);. PDC-> SetBkMode ( TRANSPARENT); if (pimage! = Null) {// Get The Rect this Holds The item's icon. GetItemRect (NITEM, & RCITEM, LVIR_ICON); // Draw the icon. Uformat = Ild_Transparent; Pimage-> DRAW (PDC, RITEM. IIMAGE, RCITEM.TOPLEFT (), UFORMAT);} // Draw The Background & Prep The DC for the text Drawing. Note // That The Entire Item Rect IS Filled in, So this Emulates The full full- // Row Selection Style of normal lists.GetItemRect (nItem, rcItem, LVIR_LABEL); pDC-> FillSolidRect (rcItem, crBkgnd); pDC-> SetBkMode (TRANSPARENT);. // Tweak the rect a bit for nicer-looking text alignment rcText1 = rcText = rcItem; // rctext.Left = 3; rctext.top = 3; rcText.bottom - = rcText.height () * 2/5; rctext1.top = rcText.bottom;

// Draw the text. CallLogptr Pitem = (CallLogptr) GetItemData (NITEM);

IF (pitem! = null) {if (_TCSLEN (wchar *) pitem-> strname)! = 0) {Stext = (wchar *) Pitem-> strname; if (_TCSCMP (wchar *) Pitem-> Strcontact, (Wchar *) pitem-> strname)! = 0) {Stext = _t (") cString ((wchar *) pitem-> strcontact) _t (") ");}} else stext = (Wchar *) pitem-> strcontact; // pdc-> drawtext (stext, rctext, dt_vcenter | dt_singeline);

CFont vertFont, tipFont; CFont * pOldFont; // Font vertFont.CreateFont (15, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T ( "MS Sans Serif") ); tipFont.CreateFont (10, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T ( "MS Sans Serif")); pOldFont = pDC-> SelectObject (& vertFont ); PDC-> DRAWTEXT (Stext, rctext, dt_vcenter | dt_singeline); ctime m_time (pitem-> dwbegintime); cstract txtbelow = _t ("); txtBElow.format (_t ("% D-% 02D-% 02D% 02D:% 02D "), m_time.getyear (), m_time.getday (), m_time.getday (), m_time.getMinute (); if (Pitem-> dwlasting! = 0) {CSTRING CALLTIME; INT DAY, HOUR, Minute, Second, Tmp; Day = Pitem-> dwlasting / (24 * 60 * 60); TMP = Pitem-> dwlasting% (24 * 60 * 60); Hour = TMP / (60 * 60); TMP = Tmp% (60 * 60); minute = TMP / 60; second = Tmp% 60; I f (day! = 0) CallTime.Format (_T ("% D,% D:% 02D:% 02D"), DAY, HOUR, Minute, Second); Else IF (Hour! = 0) CallTime.Format (_t) ("% D:% 02D:% 02D"), Hour, minute, second; else CallTime.Format (_T ("% 02d:% 02d"), Minute, Second); csyslogdlg * pParent = null; pparent = Csyslogdlg *) this-> getParent ();

转载请注明原文地址:https://www.9cbs.com/read-9054.html

New Post(0)