MyColorListbox.zip

  • PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 3KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 24
    下载次数
  • 2008-12-26 15:09
    上传日期
UsbPort打印例子usbprint的开发的源代码
MyColorListbox.zip
  • ColorListBox.cpp
    9.3KB
  • www.pudn.com.txt
    218B
  • ColorListBox.h
    2.1KB
内容介绍
// ColorListBox.cpp : implementation file // #include "stdafx.h" #include "ami.h" #include "ColorListBox.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CColorListBox CColorListBox::CColorListBox() { m_bInitialized = false; } CColorListBox::~CColorListBox() { } BEGIN_MESSAGE_MAP(CColorListBox, CListBox) //{{AFX_MSG_MAP(CColorListBox) ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CColorListBox message handlers void CColorListBox::DrawItem(LPDRAWITEMSTRUCT pDIStruct) { static CString sColor; // No Need To Reallocate Each Time CDC dcContext; CRect rItemRect( pDIStruct -> rcItem ); CRect rBlockRect( rItemRect ); CRect rTextRect( rBlockRect ); CBrush brFrameBrush; int iFourthWidth = 0; int iItem = pDIStruct -> itemID; int iAction = pDIStruct -> itemAction; int iState = pDIStruct -> itemState; COLORREF crColor = 0; COLORREF crNormal = GetSysColor( COLOR_WINDOW ); COLORREF crSelected = GetSysColor( COLOR_HIGHLIGHT ); COLORREF crText = GetSysColor( COLOR_WINDOWTEXT ); if( !dcContext.Attach( pDIStruct -> hDC ) ) // Attach CDC Object return; // Stop If Attach Failed iFourthWidth = ( rBlockRect.Width() / 4 ); // Get 1/4 Of Item Area brFrameBrush.CreateStockObject( BLACK_BRUSH ); // Create Black Brush if( iState & ODS_SELECTED ) // If Selected { // Set Selected Attributes dcContext.SetTextColor( ( 0x00FFFFFF & ~( crText ) ) ); // Set Inverted Text Color (With Mask) dcContext.SetBkColor( crSelected ); // Set BG To Highlight Color dcContext.FillSolidRect( &rBlockRect, crSelected ); // Erase Item } else // If Not Selected { // Set Standard Attributes dcContext.SetTextColor( crText ); // Set Text Color dcContext.SetBkColor( crNormal ); // Set BG Color dcContext.FillSolidRect( &rBlockRect, crNormal ); // Erase Item } if( iState & ODS_FOCUS ) // If Item Has The Focus dcContext.DrawFocusRect( &rItemRect ); // Draw Focus Rect // // Calculate Text Area // rTextRect.left += ( iFourthWidth + 2 ); // Set Start Of Text rTextRect.top += 2; // Offset A Bit // // Calculate Color Block Area // rBlockRect.DeflateRect( CSize( 2, 2 ) ); // Reduce Color Block Size rBlockRect.right = iFourthWidth; // Set Width Of Color Block // // Draw Color Text And Block // if( iItem != -1 ) // If Not An Empty Item { GetText( iItem, sColor ); // Get Color Text if( iState & ODS_DISABLED ) // If Disabled { crColor = GetSysColor( COLOR_INACTIVECAPTIONTEXT ); dcContext.SetTextColor( crColor ); // Set Text Color } else // If Normal crColor = GetItemData( iItem ); // Get Color Value dcContext.SetBkMode( TRANSPARENT ); // Transparent Background dcContext.TextOut( rTextRect.left, rTextRect.top, sColor ); // Draw Color Name dcContext.FillSolidRect( &rBlockRect, crColor ); // Draw Color dcContext.FrameRect( &rBlockRect, &brFrameBrush ); // Draw Frame } dcContext.Detach(); // Detach DC From Object } void CColorListBox::PreSubclassWindow() { Initialize(); // Initialize Contents CListBox::PreSubclassWindow(); // Subclass Control SetCurSel( 0 ); // Select First Item By Default return; // Done! } int CColorListBox::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CListBox::OnCreate(lpCreateStruct) == -1) return -1; Initialize(); // Initialize Contents SetCurSel( 0 ); // Select First Item By Default return 0; } void CColorListBox::Initialize( void ) { int iAddedItem = -1; if( m_bInitialized ) // If Already Initialized return; // Return ResetContent(); /* AddColor("Black", RGB(0x00, 0x00, 0x00)); AddColor("Dark Grey", RGB( 0x40, 0x40, 0x40 )); AddColor("Grey", RGB( 0x80, 0x80, 0x80 )); AddColor("Light Grey", RGB( 0xC0, 0xC0, 0xC0 )); AddColor("White", RGB( 0xFF, 0xFF, 0xFF )); AddColor("Navy", RGB( 0x00, 0x00, 0x80 )); AddColor("Blue", RGB( 0x00, 0x00, 0xFF )); AddColor("Aqua", RGB( 0x00, 0xDD, 0xDD )); AddColor("Cyan", RGB( 0x00, 0xFF, 0xFF )); AddColor("Teal", RGB( 0x40, 0x80, 0x80 )); AddColor("Dark Green", RGB( 0x00, 0x40, 0x00 )); AddColor("Green", RGB( 0x00, 0x80, 0x00 )); AddColor("Lime", RGB( 0x00, 0xFF, 0x00 )); AddColor("Olive" , RGB( 0x66, 0x66, 0x00 )); AddColor("Khaki", RGB( 0xCC, 0xCC, 0x00 )); AddColor("Brown", RGB( 0x80, 0x40, 0x40 )); AddColor("Purple", RGB( 0x99, 0x66, 0xCC )); AddColor("Red", RGB( 0xFF, 0x00, 0x00 )); AddColor("Magenta", RGB( 0xFF, 0x00, 0xFF )); AddColor("Maroon", RGB( 0x80, 0x00, 0x00 )); AddColor("Fushcia", RGB( 0xFF, 0x00, 0xFF )); AddColor("Yellow", RGB( 0xFF, 0xFF, 0x00 )); AddColor("Light Yellow", RGB( 0xFF, 0xFF, 0x40 )); AddColor("Pale Yellow", RGB( 0xFF, 0xFF, 0x80 )); */ m_bInitialized = true; // Set Initialized Flag } COLORREF CColorListBox::GetSelectedColorValue( void ) { int iSelectedItem = GetCurSel(); // Get Selected Item if( iSelectedItem == CB_ERR ) // If Nothing Selected return( RGB( 0, 0, 0 ) ); // Return Black return( GetItemData( iSelectedItem ) ); // Return Selected Color } CString CColorListBox::GetSelectedColorName( void ) { int iSelectedItem = GetCurSel(); // Get Selected Item if( iSelectedItem == CB_ERR ) // If Nothing Selected return( m_sColorName = afxEmptyString ); // Return Nothing (Not "Black!") GetText( iSelectedItem, m_sColorName ); // Store Name Of Color return( m_sColorName ); // Return Selected Color Name } void CColorListBox::SetSelectedColorValue( COLORREF crClr ) { int iItems = GetCount(); for( int iItem = 0; iItem < iItems; iItem++ ) { if( crClr == GetItemData( iItem ) ) // If Match Found SetCurSel( iItem ); // Select It } return; // Done! } void CColorListBox::SetSelectedColorName( PCSTR cpColor ) { int iItems = GetCount(); CString sColorName; for( int iItem = 0; iItem < iItems; iItem++ ) { GetText( iItem, sColorName ); // Get Color Name if( !sColorName.CompareNoCase( cpColor ) ) // If Match Found SetCurSel( iItem ); // Select It } return; // Done! } bool CColorListBox::RemoveColor( PCSTR cpColor ) { int iItems = GetCount(); CString sColor; bool bRemoved = false;
评论
    相关推荐
    • 50_vc_usb.rar
      本程序演示了如何利用编写高层应用程序与USB接口通信。读者有必要了解主机是如何识别USB设备以及USB工作的基本原理。
    • VCUSBCode.rar
      VC++USB程序源码,对USB进行控制,适合初学者。
    • USB Driver Programming - a DIY developers guide.ra
      USB Driver Programming - a DIY developers guide
    • USBPort.rar
      USBPort的编译说明 -- 01(VC知识库) 1. 安装DDK 2. 把DDK的inc路径填在头文件的包含路径中 3. 把DDK的lib路径填在库文件的包含路径中 4. 注释掉原代码中的HIDD_ATTRIBUTES结构 // 不知作者为什么要添加这个...
    • USBA5.rar
      这是一个简单的USB编程,用VC++写的,可用
    • USB_BianCheng.rar
      USB编程,利用Visual C++进行开发研究学习
    • USBport.rar
      USB代码,原始程序,可以修改,对学习很有帮助
    • c_language_code_for_USB_excuse_classic_preparation
      c语言USB借口经典编写设计代码c language code for USB excuse classic preparation of design
    • portlist:端口列表-列出Microsoft Windows 2000或更高版本(XP,Vista,7、8或10)上可用的
      端口列表 ... 目录 端口列表 目的 将新的USB或蓝牙(等)串行或并行设备连接到运行Microsoft Windows的PC的一个问题是,您并不总是看到闪烁的消息,该消息告诉您串行或并行端口的名称。 您可能会忘记名称,或者如果将其...
    • Proteus7.12.rar
      Proteus7.12完美破解版.rar电路仿真软件很好用可以仿真单片数字模拟电路