CategoryCombobox.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:4k
源码类别:
P2P编程
开发平台:
Visual C++
- // CategoryCombobox.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "CategoryCombobox.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCategoryCombobox
- CCategoryCombobox::CCategoryCombobox()
- {
- }
- CCategoryCombobox::~CCategoryCombobox()
- {
- }
- BEGIN_MESSAGE_MAP(CCategoryCombobox, CComboBox)
- //{{AFX_MSG_MAP(CCategoryCombobox)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCategoryCombobox message handlers
- void CCategoryCombobox::DrawItem( LPDRAWITEMSTRUCT pDIStruct )
- {
- assert(m_pimgList);
- static CString sFolder, tmpStr; // No Need To Reallocate Each Time
- CDC dcContext;
- CRect rItemRect(pDIStruct->rcItem);
- CRect rBlockRect(rItemRect);
- CRect rTextRect(rBlockRect);
- CBrush brFrameBrush;
- int iItem = pDIStruct -> itemID;
- int iState = pDIStruct -> itemState;
- int iImageIndex = 0;
- int iIndent;
- COLORREF crColor = GetSysColor(COLOR_WINDOW);
- COLORREF crNormal = GetSysColor(COLOR_WINDOW);
- COLORREF crSelected = GetSysColor(COLOR_HIGHLIGHT);
- COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
- // Attach the CDC object
- if(!dcContext.Attach(pDIStruct -> hDC ))
- return;
- brFrameBrush.CreateStockObject(BLACK_BRUSH);
- // Draw folder text and icon
- // If an item is selected...
- if( iItem != -1 )
- {
- // Get text for normal and disabled
- CString sFolder;
- GetLBText(iItem, sFolder);
- LPSFOLDER tmpFolder = (LPSFOLDER)GetItemDataPtr(iItem);
- iIndent = tmpFolder->m_iIndent;
- // if draw edit text, then no indent.
- if (iState & ODS_COMBOBOXEDIT)
- iIndent = 1;
- // Calculate icon display area and set the width
- rBlockRect.DeflateRect(CSize(2, 2));
- rBlockRect.right = ICONWIDTH * iIndent;
- // Calculate Text Area
- // Set start of text offset a bit
- rTextRect.left += (ICONWIDTH * iIndent) + 2;
- rTextRect.top += 2;
- CSize size = dcContext.GetTextExtent(sFolder);
- rTextRect.right = rTextRect.left + size.cx + 4;
- ////////////////////////////////////////////////
- // draw focus select.
- if(iState & ODS_SELECTED)
- {
- dcContext.SetTextColor((0x00FFFFFF & ~(crText)));
- dcContext.SetBkColor( crSelected );
- dcContext.FillSolidRect( &rTextRect, crSelected );
- }
- else
- {
- dcContext.SetTextColor( crText );
- dcContext.SetBkColor( crNormal );
- dcContext.FillSolidRect( &rTextRect, crNormal );
- }
- // If item has the focus...draw the focus rectangle.
- // **** useless.
- if( iState & ODS_FOCUS )
- dcContext.DrawFocusRect( &rTextRect );
- ////////////////////////////////////////////////
- // draw text and image.
- iImageIndex = tmpFolder->m_iImageIndex;
- if( iState & ODS_DISABLED )
- {
- crColor = GetSysColor(COLOR_INACTIVECAPTIONTEXT);
- dcContext.SetTextColor(crColor);
- CPoint pt(pDIStruct->rcItem.left, pDIStruct->rcItem.top);
- pt.x = pDIStruct->rcItem.left + ((iIndent - 1) * ICONWIDTH);
- m_pimgList->Draw(&dcContext, iImageIndex, pt, ILD_TRANSPARENT);
- }
- else
- {
- CPoint pt(pDIStruct->rcItem.left, pDIStruct->rcItem.top);
- pt.x = pDIStruct->rcItem.left + ((iIndent - 1) * ICONWIDTH);
- m_pimgList->Draw(&dcContext, iImageIndex, pt, ILD_NORMAL);
- }
- dcContext.SetBkMode(TRANSPARENT);
- dcContext.TextOut(rTextRect.left, rTextRect.top, sFolder);
- }
- // Detach DC
- dcContext.Detach();
- }
- void CCategoryCombobox::OnDestroy()
- {
- DeleteAllItems();
- CComboBox::OnDestroy();
- }
- void CCategoryCombobox::DeleteAllItems()
- {
- // Iterate through the items destroying all of the
- // associated data
- LPSFOLDER tmpFolder;
- int iListCount = GetCount();
- for (int x = 0; x < iListCount; x++)
- {
- tmpFolder = (LPSFOLDER)GetItemDataPtr(x);
- if (tmpFolder)
- delete tmpFolder;
- }
- ResetContent();
- }