ioctllistbox.cpp

来自「IO函数调用测试」· C++ 代码 · 共 177 行

CPP
177
字号
// IOCTLListBox.cpp : implementation file
//

#include "stdafx.h"
#include "IOExplorer.h"
#include "HSListBox.h"
#include "ioctl.h"  
  #include "IOCTLListBox.h"

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

/////////////////////////////////////////////////////////////////////////////
// CIOCTLListBox

CIOCTLListBox::CIOCTLListBox()
{
}

CIOCTLListBox::~CIOCTLListBox()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CIOCTLListBox message handlers

int CIOCTLListBox::CompareItem(LPCOMPAREITEMSTRUCT cis) 
{
 	return lstrcmp( ((IOCTL *)cis->itemData1)->getName(), 
		        ((IOCTL *)cis->itemData2)->getName());

	// return -1 = item 1 sorts before item 2
	// return 0 = item 1 and item 2 sort the same
	// return 1 = item 1 sorts after item 2
	
	return 0;
}

void CIOCTLListBox::DeleteItem(LPDELETEITEMSTRUCT dis) 
{
 IOCTL * ioctl = (IOCTL *)dis->itemData;

 delete ioctl;
	
 CHSListBox::DeleteItem(dis);
}

/****************************************************************************
*                           CIOCTLListBox::DrawItem
* Inputs:
*       LPDRAWITEMSTRUCT dis:
* Result: void
*       
* Effect: 
*       Draws the item
* Notes:
*	This is really sort of a frill, but it greatly simplifies the problem
*	of garbage-collecting the IOCTL * objects associated with the list
*	box, and allows us to use a different form of highlighting when
*	the list box does not have the focus
****************************************************************************/

void CIOCTLListBox::DrawItem(LPDRAWITEMSTRUCT dis) 
{
 CDC * dc = CDC::FromHandle(dis->hDC);
 
 if(dis->itemID == -1)
    { /* no items */
     CBrush bg(::GetSysColor(COLOR_WINDOW));
     dc->FillRect(&dis->rcItem, &bg);
     if(dis->itemState & ODS_FOCUS)
        { /* selected */
	 dc->DrawFocusRect(&dis->rcItem);
	} /* selected */
     return;
    } /* no items */

 IOCTL * ioctl = (IOCTL *)dis->itemData;

// if(dis->itemState & ODA_FOCUS)
//    { /* focus only */
//     dc->DrawFocusRect(&dis->rcItem);
//     return;
//    } /* focus only */

 int saved = dc->SaveDC();

 COLORREF txcolor;
 COLORREF bkcolor;

 if(dis->itemState & ODS_SELECTED)
    { /* selected */
     if(::GetFocus() == m_hWnd)
        { /* has focus */
	 bkcolor = ::GetSysColor(COLOR_HIGHLIGHT);
	 txcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
	} /* has focus */
     else
        { /* no focus */
	 bkcolor = ::GetSysColor(COLOR_BTNFACE);
	 txcolor = ::GetSysColor(COLOR_BTNTEXT);
	} /* no focus */
    } /* selected */
 else
    { /* not selected */
     txcolor = ::GetSysColor(COLOR_WINDOWTEXT);
     bkcolor = ::GetSysColor(COLOR_WINDOW);
    } /* not selected */

 {
  CBrush bg(bkcolor);
  dc->FillRect(&dis->rcItem, &bg);
 }

 dc->SetTextColor(txcolor);
 dc->SetBkMode(TRANSPARENT);

 dc->TextOut(dis->rcItem.left, dis->rcItem.top, ioctl->getName());

 if(dis->itemState & ODS_FOCUS)
    dc->DrawFocusRect(&dis->rcItem);

 dc->RestoreDC(saved);
	
}

/****************************************************************************
*                          CIOCTLListBox::AddString
* Inputs:
*       IOCTL * ioctl: the IOCTL to add
* Result: int
*       The position at which it was added
* Effect: 
*       Adds the IOCTL to the list
* Notes:
*	This is a convenience so the caller doesn't have to do the cast
****************************************************************************/

int CIOCTLListBox::AddString(IOCTL * ioctl)
    {
     return CHSListBox::AddString((LPCTSTR)ioctl);
    }

/****************************************************************************
*                       CIOCTLListBox::FindStringExactCS
* Inputs:
*       int start: Starting position (search starts at next position)
*	LPCTSTR str: String to search for
* Result: int
*       Index of item found, or LB_ERR if not found
****************************************************************************/

int CIOCTLListBox::FindStringExactCS(int start, LPCTSTR str)
    {
     int count = CHSListBox::GetCount();
     for(int i = start+1; i < count; i++)
        { /* test each */
	 IOCTL * ioctl = GetItemData(i);
	 ASSERT(ioctl != NULL);
	 if(ioctl == NULL)
	    continue; // should be impossible
	 if(lstrcmp(ioctl->getName(), str) == 0) // case sensitive!
	    return i;
	} /* test each */
     return LB_ERR; // not found
    }

⌨️ 快捷键说明

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