Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

A comprehensive CE class library to replace ATL and MFC

, 4 Oct 2000
A collection of classes for CE that do not use ATL or MFC, plus an FTP client, database viewer, and sample application that solves beam deflection equations.
kgwince-old.zip
WinCe
BeamEx
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
Install
BeamEx.inf
BeamEx.ini
BeamEx.MIPS_PPCBW.CAB
BeamEx.MIPS_PPCColor.CAB
BeamEx.SH3_PPCColor.CAB
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeLib
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.old
CeLib.plg
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
dbView
bitmap1.bmp
bmp00001.bmp
db5.bmp
dbView.aps
DbView.dsp
dbView.dsw
dbView.old
dbView.plg
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
Install
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
mssccprj.scc
vssver.scc
ftpView
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
FtpView.old
ftpView.plg
FtpView.vcl
FtpView.vcp
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
Install
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
options.bmp
options1.bmp
seperato.bmp
vssver.scc
Setup
ico101.ico
Setup.aps
Setup.dsp
setup.ico
Setup.plg
WinCe.dsw
WinLib.dsw
kgwince.zip
app.ico
BeamEx.dsp
BeamEx.dsw
BeamEx.ini
BeamEx.plg
BeamEx.vcl
BeamEx.vcp
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
calc.bmp
calc16.bmp
circ_cross.ico
cir_cross.ico
cross_4.ico
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico00005.ico
ico00008.ico
ico00009.ico
ico00010.ico
icon1.ico
icon2.ico
icon4.ico
id_downl.bmp
BeamEx.inf
BeamEx.ini
Setup.exe
i_cross.ico
l_cross.ico
magenic.ico
mssccprj.scc
obl_corss.ico
obl_cross.ico
options.bmp
options1.bmp
ping16.bmp
rect_cross.ico
scene_5.ico
scene_6.ico
tri_cross.ico
vssver.scc
CeFtp.vcp
CeFtp.vcw
CeLabel.inl
CeLib.aps
CeLib.dsp
CeLib.dsw
CeLib.plg
CeLib.vcl
CeLib.vcp
CeMisc.inl
CeProperty.inl
CeTab.inl
CeWnd.inl
mssccprj.scc
vssver.scc
WinLib.dsp
WinLib.dsw
bitmap1.bmp
bitmap2.bmp
bmp00001.bmp
db5.bmp
DbView.dsp
dbView.dsw
dbView.plg
DbView.vcl
DbView.vcp
deldb.bp2
deldb5.bmp
delrec.bp2
delrecor.bmp
help16.bmp
help4.bmp
icon1.ico
icon2.ico
dbView.inf
dbView.ini
Setup.exe
magenic.bmp
magenic.ico
menu1_5.bmp
mssccprj.scc
vssver.scc
appicon.ico
bitmap1.bmp
bitmap2.bmp
bitmap3.bmp
bitmap4.bmp
bmp00001.bmp
bmp00002.bmp
db5.bmp
deldb.bp2
delrec.bp2
FtpView.dsp
ftpView.dsw
ftpView.plg
FtpView.vcl
FtpView.vcp
FtpView.vcw
help16.bmp
help4.bmp
ico00001.ico
ico00002.ico
ico171.ico
ico35.ico
icon1.ico
icon2.ico
imagelis.bmp
IMAGES.bmp
ftpView.inf
ftpView.ini
Setup.exe
vssver.scc
magenic.bmp
magenic.ico
mssccprj.scc
newmenu.bmp
options.bmp
options1.bmp
rcdata1.bin
seperato.bmp
toolbar1.bmp
vssver.scc
WinCe.dsw
WinCe.vcw
// ImageComboBox.cpp : implementation file
//

#include "stdafx.h"
#include "ImageComboBox.h"

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

/////////////////////////////////////////////////////////////////////////////
// CImageComboBox

CImageComboBox::CImageComboBox()
{
}

CImageComboBox::~CImageComboBox()
{
}


BEGIN_MESSAGE_MAP(CImageComboBox, CComboBox)
	//{{AFX_MSG_MAP(CImageComboBox)
	ON_WM_KEYDOWN()
	ON_WM_SETFOCUS()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageComboBox message handlers

void CImageComboBox::OnDeleteItem(LPDELETEITEMSTRUCT lpDelIS) 
{
	if (lpDelIS->itemData && lpDelIS->itemID != -1)
		delete (CIconIndent*)lpDelIS->itemData;
}

void CImageComboBox::OnDrawItem(LPDRAWITEMSTRUCT lpDIS) 
{
	//////////////////////////////////////////////////////////////////////////////
	// Alias the given device context to simplify GDI a little
	//////////////////////////////////////////////////////////////////////////////
	HDC hDC = lpDIS->hDC;
	CeRect rect(lpDIS->rcItem);
	
	//////////////////////////////////////////////////////////////////////////////
	// Handle the case of no items
	//////////////////////////////////////////////////////////////////////////////
	if (lpDIS->itemID == -1)
	{
		if (lpDIS->itemState & ODS_FOCUS)
			::DrawFocusRect (hDC, rect);
		return;
	}

	//////////////////////////////////////////////////////////////////////////////
	// Determine the indentation level and image index from the item data
	//////////////////////////////////////////////////////////////////////////////
	int nIndentSteps	= 0;
	int nImageIndex		= 0;
	if (lpDIS->itemData)
	{
		CIconIndent* pIconIndent = (CIconIndent*)lpDIS->itemData;

		nIndentSteps	= pIconIndent->m_nIndentSteps;
		nImageIndex		= pIconIndent->m_nImageIndex;
	}

	if (lpDIS->itemState & ODS_COMBOBOXEDIT)
		nIndentSteps = 0;
	
	//////////////////////////////////////////////////////////////////////////////
	// Determine the indentation width from the icon size
	//////////////////////////////////////////////////////////////////////////////
	int nWidth, nHeight;
	if (m_pImages && m_pImages->m_hImageList)
	{
		IMAGEINFO ii;
		ASSERT(0 < m_pImages->GetImageCount());
		m_pImages->GetImageInfo(0, &ii);

		nWidth = (ii.rcImage.right - ii.rcImage.left) / 2;
		nHeight = ii.rcImage.bottom - ii.rcImage.top;
	}
	else
		nWidth = 8;
	
	//////////////////////////////////////////////////////////////////////////////
	// Draw the icon for the list item
	//////////////////////////////////////////////////////////////////////////////
	if (nImageIndex >= 0 && m_pImages && m_pImages->m_hImageList)
	{
		DWORD dwStyle = ILD_NORMAL;
		if (lpDIS->itemState & ODS_SELECTED)
			dwStyle = ILD_SELECTED;
		
		CePoint pt(rect.left + nWidth * nIndentSteps + 2, rect.top);
//		ASSERT(nImageIndex < m_pImages->GetImageCount());
		m_pImages->Draw(pDC, nImageIndex, pt, dwStyle);
	}
	
	//////////////////////////////////////////////////////////////////////////////
	// Draw the text rectangle and text for the list item
	//////////////////////////////////////////////////////////////////////////////
	CeString<64> strText;
	GetLBText(lpDIS->itemID, strText);

	HFONT hFont = GetFont();
	SelectObject(hDC, hFont);

	CSize sizeText;
	::GetTextExtentExPoint(hDC, strText, strText.GetLength(), 0, NULL, NULL, sizeText);

	rect.left += nWidth * (nIndentSteps + 2) + 4;
	rect.right = rect.left + sizeText.cx + 3;
	
	::SaveDC(hDC);

	if (lpDIS->itemState & ODS_SELECTED)
	{
		COLORREF clrHighlight = ::GetSysColor(COLOR_HIGHLIGHT);
		COLORREF clrHighlightText = ::GetSysColor(COLOR_HIGHLIGHTTEXT);

		HBRUSH br = ::CreateSolidBrush(clrHighlight);

		::FillRect(hDC, rect, &br);
		::SetBkColor(hDC, clrHighlight);
		::SetTextColor(hDC, clrHighlightText);

		::Destroy (br);
	}
	else
	{
		HBRUSH br = ::CreateSolidBrush( ::GetSysColor(COLOR_WINDOW) );
		pDC->FillRect(rect, &br);

		::Destroy (br);
	}
	
	CeRect rectText = rect;
	rectText.left += 1;
	rectText.top  += 1;
	::DrawText(hDC, strText, -1, rectText, DT_TOP|DT_LEFT);

	::RestoreDC(hDC, -1);
	
	//////////////////////////////////////////////////////////////////////////////
	// Draw the focus rectangle for the list item
	//////////////////////////////////////////////////////////////////////////////
	if (lpDIS->itemState & ODS_FOCUS)
		::DrawFocusRect(hDC, rect);
}

void CImageComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS) 
{
	int nOffset = (lpMIS->itemID == -1) ? -2: 0;

	if (m_pImages && m_pImages->m_hImageList)
	{
		IMAGEINFO ii;
		m_pImages->GetImageInfo(0, &ii);
		lpMIS->itemHeight = ii.rcImage.bottom - ii.rcImage.top;
	}
	else
		lpMIS->itemHeight = 16 + nOffset;
}

void CImageComboBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CeComboBox::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CImageComboBox::OnSetFocus(CWnd* pOldWnd) 
{
	CeComboBox::OnSetFocus(pOldWnd);
	
//	if (::GetKeyState(VK_TAB) & 0x8000) // Is the tab key down?
//		pOldFocusWindow = NULL;
//	else
//		pOldFocusWindow = OldFocus;
}


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int CImageComboBox::AddString(LPCTSTR lpszString, int nImage, int nSteps, DWORD dwData)
{
	// Add the string
	int nIndex = CeComboBox::AddString(lpszString);
	CeComboBox::SetItemDataPtr(nIndex, new CIconIndent(nSteps, nImage, dwData));
	return nIndex;
}


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int CImageComboBox::InsertString(int nIndex, LPCTSTR lpszString, int nImage, int nSteps, DWORD dwData)
{
	int nActIndex = CeComboBox::InsertString(nIndex, lpszString);
	CeComboBox::SetItemDataPtr(nActIndex, new CIconIndent(nSteps, nImage, dwData));

	return nActIndex;
}


DWORD CImageComboBox::GetItemData(int nIndex) const
{
	CIconIndent* pInfo = (CIconIndent*) CeComboBox::GetItemDataPtr(nIndex);
	return (pInfo) ? pInfo->m_dwItemData: 0;
}


void* CImageComboBox::GetItemDataPtr(int nIndex) const
{
	return (void*) GetItemData(nIndex);
}


int CImageComboBox::SetItemData(int nIndex, DWORD dwItemData)
{
	CIconIndent* pInfo = (CIconIndent*) CeComboBox::GetItemDataPtr(nIndex);
	if (pInfo)
		pInfo->m_dwItemData = dwItemData;
	else
		return CB_ERR;

	return 0;
}


int CImageComboBox::SetItemDataPtr(int nIndex, void* pData)
{
	return SetItemData(nIndex, (DWORD) pData);
}


void CImageComboBox::PreSubclassWindow()
{
	CeComboBox::PreSubclassWindow();

	// Attempt to make the combobox shorter (to match the Explorer)
	int Height = GetItemHeight(-1) - 2;
	SetItemHeight(-1, Height);
}

BOOL CImageComboBox::DestroyWindow() 
{
	int nCnt = GetCount();
	for (int ii = 0; ii < nCnt; ii++)
	{
		CIconIndent* pInfo = (CIconIndent*) CComboBox::GetItemDataPtr(ii);
		if (pInfo)
		{
			delete pInfo;
			CeComboBox::SetItemDataPtr(ii, NULL);
		}
	}
	
	return CeComboBox::DestroyWindow();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Kenny G

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 5 Oct 2000
Article Copyright 2000 by Kenny G
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid