⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorlistbox.cpp

📁 自动从数据库上移动数据,,,采用ORACAL数据库.
💻 CPP
字号:
// ColorListBox.cpp : implementation file
//

#include "stdafx.h"
#include "Aotu.h"
#include "ColorListBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CColorListBox

CColorListBox::CColorListBox()
{
	m_nMaxWidth = 0;
}

CColorListBox::~CColorListBox()
{
}

BEGIN_MESSAGE_MAP(CColorListBox, CListBox)
	//{{AFX_MSG_MAP(CColorListBox)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorListBox message handlers
void CColorListBox::DrawItem(LPDRAWITEMSTRUCT lpdis) 
//void CColorListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// TODO: Add your code to draw the specified item
	if (lpdis->itemID < 0)
		return; 
	
	COLORREF cvText;
	COLORREF cvBack;
	CString  itemString="";
	
	if ((lpdis->itemState & ODS_SELECTED) &&	// if item has been selected
		(lpdis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
		DrawFocusRect(lpdis->hDC, &lpdis->rcItem); 
	
	
	if (!(lpdis->itemState & ODS_SELECTED) &&	// if item has been deselected
		(lpdis->itemAction & ODA_SELECT))
		DrawFocusRect(lpdis->hDC, &lpdis->rcItem); 
	
	
	if(lpdis->itemData)		// if color information is present
		cvText = SetTextColor(lpdis->hDC, lpdis->itemData);
	else 	// if no color information, use default system colors
		cvText = SetTextColor(lpdis->hDC, GetSysColor((lpdis->itemState & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)); 
	
	// always use system colors for background
	cvBack = SetBkColor(lpdis->hDC, GetSysColor((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT : COLOR_WINDOW)); 
	
	// get and display item text
    //if (lpdis->itemID ==)

	try
	{
		if (lpdis->itemID == 4294967295)
			return;
		GetText(lpdis->itemID, itemString );
		if (itemString=="")
			return;
		DrawText(lpdis->hDC, itemString, -1, &lpdis->rcItem, DT_LEFT | DT_SINGLELINE);
		
		// restore DC colors
		SetTextColor(lpdis->hDC, cvText); 
		SetBkColor(lpdis->hDC, cvBack); 
		
	}catch(...)
	{
		return;
	}

	
}

//***********************************************
// original AddString() method
//
// purpose: Add a string to the listbox
//
// parameters: 
//		lpszItem: pointer to item text
//
// remarks:
//	    provided because CListBox::AddString is 
//		NOT virtual
//
// return:	item index
//***********************************************
int CColorListBox::AddString( LPCTSTR lpszItem)
{
    int nRet = ((CListBox*)this)->AddString(lpszItem);
	
	SCROLLINFO scrollInfo;
    memset(&scrollInfo, 0, sizeof(SCROLLINFO));
    scrollInfo.cbSize = sizeof(SCROLLINFO);
    scrollInfo.fMask  = SIF_ALL;
    GetScrollInfo(SB_VERT, &scrollInfo, SIF_ALL);
	
	int nScrollWidth = 0;
    if(GetCount() > 1 && ((int)scrollInfo.nMax >= (int)scrollInfo.nPage))
    {
		nScrollWidth = GetSystemMetrics(SM_CXVSCROLL);
    }
    
	SIZE      sSize;
    CClientDC myDC(this);
	
	CFont* pListBoxFont = GetFont();
    if(pListBoxFont != NULL)
    {
        CFont* pOldFont = 
			myDC.SelectObject(pListBoxFont);
		
		GetTextExtentPoint32(myDC.m_hDC, 
			lpszItem, strlen(lpszItem), &sSize);
        m_nMaxWidth = max(m_nMaxWidth, (int)sSize.cx);
		SetHorizontalExtent(m_nMaxWidth + 3);
		
		myDC.SelectObject(pOldFont);    
	}
	
	return nRet;
}


//***********************************************
// new AddString() method
//
// purpose: Add a string to the listbox
//
// parameters: 
//		lpszItem: pointer to item text
//			 rgb: text color as a COLORREF
//
// return:	item index
//***********************************************
int CColorListBox::AddString( LPCTSTR lpszItem,COLORREF rgb )
{
	int item = AddString(lpszItem);
	if(item >=0)
		SetItemData(item,rgb);
	return item;
}


//***********************************************
// new InsertString() method
//
// purpose: Insert a string to the listbox
//
// parameters: 
//		  nIndex: index of inserted item
//		lpszItem: pointer to item text
//			 rgb: text color as a COLORREF
//
// return:	item index
//***********************************************
int CColorListBox::InsertString( int nIndex, LPCTSTR lpszItem, COLORREF rgb)
{
	int item = ((CListBox*)this)->InsertString(nIndex,lpszItem);
	if(item >=0)
		SetItemData(item,rgb);
	return item;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -