?? xmllistbox.cpp
字號(hào):
// ================================================================================
//
// author: Rainer Schuster
//
// created: 09.03.2005 10:20:13
//
// filename: xmllistbox.cpp IMPLEMENTATION
//
// This code is as it is. You are allowed to use, modify and/or redistribute it freely.
// I'm not responsible for any errors or damage. Use it at your own risk.
//
// ================================================================================
//
#include "stdafx.h"
#include "xml_test.h"
#include "XMLListBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CXMLListBox
CXMLListBox::CXMLListBox()
{
}
CXMLListBox::~CXMLListBox()
{
CPictureMap::iterator bmp;
for( bmp = m_bmps.begin(); bmp != m_bmps.end(); bmp++)
{
// delete ((*bmp).second); for CBitmap*
((*bmp).second)->Release();
}
m_bmps.clear();
}
BEGIN_MESSAGE_MAP(CXMLListBox, CListBox)
//{{AFX_MSG_MAP(CXMLListBox)
// HINWEIS - Der Klassen-Assistent f黦t hier Zuordnungsmakros ein und entfernt diese.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen f黵 Nachrichten CXMLListBox
void CXMLListBox::Parse( DOMDocument *doc, const char* lpcszID)
{
CXMLGrid::Parse( doc, lpcszID);
int i = m_rows.size() ;
::SendMessage( m_hWnd, LB_SETCOUNT, m_rows.size() , 0);
};
void CXMLListBox::ParseRow( DOMNode *row)
{
CXMLGrid::ParseRow( row);
}
void CXMLListBox::DrawItem(LPDRAWITEMSTRUCT lpdis)
{
ASSERT(lpdis->CtlType == ODT_LISTBOX);
if( lpdis->itemID == LB_ERR)
return;
CDC dc;
CString *pstrText;
CColsMap *pData ;
COLORREF crOldTextColor;
COLORREF crOldBkColor;
dc.Attach(lpdis->hDC);
pData = m_rows[lpdis->itemID].m_pCols;
pstrText = &((*pData)[XLB_COL_STRING]);
lpdis->rcItem.left += 2;
if( strlen( (*pData)[XLB_COL_ICON]) )
{
CPictureMap::iterator bmp = m_bmps.find( (*pData)[XLB_COL_ICON] );
if( bmp == m_bmps.end() )
{
LoadIcon( (*pData)[XLB_COL_ICON], m_strIcons, &m_bmps );
bmp = m_bmps.find( (*pData)[XLB_COL_ICON] );
}
if( bmp != m_bmps.end() )
{
UINT nStyle = ILD_TRANSPARENT;
if( (lpdis->itemAction | ODA_SELECT)
&& (lpdis->itemState & ODS_SELECTED)
)
{
nStyle = ILD_SELECTED;
}
RECT rc;
long hmWidth = 0;
long hmHeight = 0;
LPPICTURE pPict = ((*bmp).second);
GetClientRect(&rc);
pPict->get_Width (&hmWidth);
pPict->get_Height(&hmHeight);
pPict->Render( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, 16, 16,
0, hmHeight, hmWidth, -hmHeight, &rc);
lpdis->rcItem.left += 16 +2;
}
}
if ((lpdis->itemAction | ODA_SELECT) &&
(lpdis->itemState & ODS_SELECTED))
{
m_clrSelected = GetSysColor(COLOR_HIGHLIGHT);
crOldBkColor = dc.SetBkColor( m_clrSelected );
crOldTextColor = dc.SetTextColor( GetSysColor( COLOR_HIGHLIGHTTEXT));
dc.FillSolidRect(&lpdis->rcItem, m_clrSelected);
}
else
{
crOldTextColor = GetSysColor( COLOR_WINDOWTEXT);
crOldBkColor = dc.GetBkColor();
dc.FillSolidRect(&lpdis->rcItem, crOldBkColor);
}
if ((lpdis->itemAction | ODA_FOCUS) &&
(lpdis->itemState & ODS_FOCUS))
{
dc.DrawFocusRect( &lpdis->rcItem);
}
lpdis->rcItem.left += 5;
// Draw the text.
dc.DrawText( *pstrText,
pstrText->GetLength(),
&lpdis->rcItem,
DT_LEFT|DT_SINGLELINE|DT_VCENTER);
// Reset the background color and the text color back to their
// original values.
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
/*
void LoadPictureFile(HDC hdc, LPCTSTR szFile, CBitmap *pBitmap, CSize &mSize)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile);
if( hFile == INVALID_HANDLE_VALUE)
return;
// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize);
LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
LPPICTURE gpPicture;
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
OLE_HANDLE m_picHandle;
/*
long hmWidth, hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
int nWidth = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH);
*
gpPicture->get_Handle(&m_picHandle);
pBitmap->DeleteObject();
pBitmap->Attach((HGDIOBJ) m_picHandle);
BITMAP bm;
GetObject(pBitmap->m_hObject, sizeof(bm), &bm);
mSize.cx = bm.bmWidth; //nWidth;
mSize.cy = bm.bmHeight; //nHeight;
}
*/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -