DataDisplay.cpp
资源名称:pciexp.zip [点击查看]
上传用户:zhuqijet
上传日期:2007-01-04
资源大小:138k
文件大小:6k
源码类别:
驱动编程
开发平台:
Visual C++
- // DataDisplay.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PCI Explorer.h"
- #include "DataDisplay.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDataDisplay
- CDataDisplay::CDataDisplay()
- {
- col1 = 0;
- format = DISPLAY_HEX_BYTES;
- }
- CDataDisplay::~CDataDisplay()
- {
- }
- BEGIN_MESSAGE_MAP(CDataDisplay, CListBox)
- //{{AFX_MSG_MAP(CDataDisplay)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDataDisplay message handlers
- /****************************************************************************
- * cvdisp
- * Inputs:
- * char * c: Character to convert
- * Result: void
- *
- * Effect:
- * Converts the character to a printable character
- ****************************************************************************/
- void cvdisp(char * c)
- {
- if(*c < ' ')
- *c = '.';
- }
- void CDataDisplay::DrawItem(LPDRAWITEMSTRUCT dis)
- {
- CDC * dc = CDC::FromHandle(dis->hDC);
- if(dis->itemID == -1)
- { /* empty */
- CBrush bg(::GetSysColor(COLOR_WINDOW));
- dc->FillRect(&dis->rcItem, &bg);
- if(dis->itemState & ODS_FOCUS)
- { /* selected */
- dc->DrawFocusRect(&dis->rcItem);
- } /* selected */
- return; // nothing to draw
- } /* empty */
- if(dis->itemState & ODA_FOCUS)
- { /* focus only */
- dc->DrawFocusRect(&dis->rcItem);
- return;
- } /* focus only */
- int saved = dc->SaveDC();
- COLORREF txcolor;
- COLORREF gycolor;
- dc->SetBkMode(TRANSPARENT);
- ///////////////////////////////////////////////////////////////////////
- // Background
- ///////////////////////////////////////////////////////////////////////
- if((dis->itemState & ODS_SELECTED))
- { /* selected */
- COLORREF fill;
- if(::GetFocus() == m_hWnd)
- fill = ::GetSysColor(COLOR_HIGHLIGHT);
- else
- fill = ::GetSysColor(COLOR_GRAYTEXT);
- CBrush bg(fill);
- dc->FillRect(&dis->rcItem, &bg);
- txcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
- gycolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
- } /* selected */
- else
- { /* not selected */
- CBrush bg(::GetSysColor(COLOR_WINDOW));
- dc->FillRect(&dis->rcItem, &bg);
- txcolor = ::GetSysColor(COLOR_WINDOWTEXT);
- gycolor = ::GetSysColor(COLOR_GRAYTEXT);
- } /* not selected */
- ///////////////////////////////////////////////////////////////////////
- // Value
- ///////////////////////////////////////////////////////////////////////
- if(col1 == 0)
- { /* set it */
- col1 = dc->GetTextExtent(CString(_T("000: "))).cx;
- } /* set it */
- CString s;
- s.Format(_T("%3d: "), dis->itemID * sizeof(DWORD));
- int offset = dc->GetTextExtent(s, s.GetLength()).cx;
- dc->SetTextColor(RGB(0, 0, 255));
- dc->TextOut(col1 - offset, dis->rcItem.top, s);
- ///////////////////////////////////////////////////////////////////////
- // Data
- ///////////////////////////////////////////////////////////////////////
- dc->SetTextColor(txcolor);
- switch(format)
- { /* decode format */
- case DISPLAY_HEX_BYTES:
- s.Format(_T("%02x %02x %02x %02x"),
- HIBYTE(HIWORD(dis->itemData)),
- LOBYTE(HIWORD(dis->itemData)),
- HIBYTE(LOWORD(dis->itemData)),
- LOBYTE(LOWORD(dis->itemData)));
- break;
- case DISPLAY_HEX_WORDS:
- s.Format(_T("%04x %04x"), HIWORD(dis->itemData),
- LOWORD(dis->itemData));
- break;
- case DISPLAY_HEX_DWORDS:
- s.Format(_T("%08x"), dis->itemData);
- break;
- case DISPLAY_DECIMAL_BYTES:
- s.Format(_T("%u %u %u %u"),
- HIBYTE(HIWORD(dis->itemData)),
- LOBYTE(HIWORD(dis->itemData)),
- HIBYTE(LOWORD(dis->itemData)),
- LOBYTE(LOWORD(dis->itemData)));
- break;
- case DISPLAY_DECIMAL_WORDS:
- s.Format(_T("%u %u"), HIWORD(dis->itemData),
- LOWORD(dis->itemData));
- break;
- case DISPLAY_DECIMAL_DWORDS:
- s.Format(_T("%u"), dis->itemData);
- break;
- case DISPLAY_ANSI_CHARACTERS:
- {
- char t[5];
- t[0] = HIBYTE(HIWORD(dis->itemData));
- t[1] = LOBYTE(HIWORD(dis->itemData));
- t[2] = HIBYTE(LOWORD(dis->itemData));
- t[3] = LOBYTE(LOWORD(dis->itemData));
- t[4] = ' ';
- cvdisp(&t[0]);
- cvdisp(&t[1]);
- cvdisp(&t[2]);
- cvdisp(&t[3]);
- s.Format(_T("%02x %02x %02x %02x |%c%c%c%c|"),
- HIBYTE(HIWORD(dis->itemData)),
- LOBYTE(HIWORD(dis->itemData)),
- HIBYTE(LOWORD(dis->itemData)),
- LOBYTE(LOWORD(dis->itemData)),
- t[0],
- t[1],
- t[2],
- t[3]);
- }
- break;
- case DISPLAY_UNICODE_CHARACTERS:
- {
- WCHAR t[3];
- t[0] = HIWORD(dis->itemData);
- t[1] = LOWORD(dis->itemData);
- t[2] = L' ';
- // If we are already in Unicode, no need to convert
- // If we are in ANSI, convert it
- // NYI: ugly hack
- char t2[3];
- t2[0] = (char)t[0];
- t2[1] = (char)t[1];
- t2[2] = (char)t[2];
- cvdisp(&t2[0]);
- cvdisp(&t2[1]);
- s.Format(_T("%04x %04x |%c%c|"), HIWORD(dis->itemData),
- LOWORD(dis->itemData),
- t2[0],
- t2[1]);
- }
- break;
- } /* decode format */
- dc->TextOut(col1, dis->rcItem.top, s);
- ///////////////////////////////////////////////////////////////////////
- // finish off processing
- ///////////////////////////////////////////////////////////////////////
- if(dis->itemState & ODS_FOCUS)
- { /* selected */
- dc->DrawFocusRect(&dis->rcItem);
- } /* selected */
- dc->RestoreDC(saved);
- // TODO: Add your code to draw the specified item
- }