⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listctrlex.cpp

📁 用bcg库编写的java IDE 源码
💻 CPP
字号:
// ListCtrlEx.cpp : implementation file
//

#include "stdafx.h"
#include "VisualJava.h"
#include "ListCtrlEx.h"

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

/////////////////////////////////////////////////////////////////////////////
// CListCtrlEx

CListCtrlEx::CListCtrlEx()
{
}

CListCtrlEx::~CListCtrlEx()
{
}


BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
	//{{AFX_MSG_MAP(CListCtrlEx)
	ON_WM_DRAWITEM()
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CListCtrlEx message handlers



void CListCtrlEx::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	MessageBox("debug");
   //ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX);
   LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
   ASSERT(lpszText != NULL);
   CDC dc;
   
	 CRect rc;
	 GetClientRect(&rc);
	 int cx = rc.Width();
	 int cy = 20;
    
	 CRect rt(lpDrawItemStruct->rcItem);
	 rc.right  = rc.left+cx;
	 rc.bottom = rc.top+cy;
	 lpDrawItemStruct->rcItem = *rt;
   
	

	dc.Attach(lpDrawItemStruct->hDC);

   // Save these value to restore them when done drawing.
   COLORREF crOldTextColor = dc.GetTextColor();
   COLORREF crOldBkColor = dc.GetBkColor();

   // If this item is selected, set the background color 
   // and the text color to appropriate values. Also, erase
   // rect by filling it with the background color.
   if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
      (lpDrawItemStruct->itemState & ODS_SELECTED))
   {
      dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
      dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
      dc.FillSolidRect(&lpDrawItemStruct->rcItem, 
         ::GetSysColor(COLOR_HIGHLIGHT));
   }
   else
      dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);

   // If this item has the focus, draw a red frame around the
   // item's rect.
   if ((lpDrawItemStruct->itemAction | ODA_FOCUS) &&
      (lpDrawItemStruct->itemState & ODS_FOCUS))
   {
      CBrush br(RGB(255, 0, 0));
      dc.FrameRect(&lpDrawItemStruct->rcItem, &br);
   }

   // Draw the text.
   dc.DrawText(
      lpszText,
      strlen(lpszText),
      &lpDrawItemStruct->rcItem,
      DT_CENTER|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();	
	CListCtrl::OnDrawItem(nIDCtl, lpDrawItemStruct);
}


int CListCtrlEx::InsertItem(const LVITEM* pItem)
{
  return CListCtrl::InsertItem(pItem);
}

int CListCtrlEx::InsertItem(int nItem,LPCTSTR lpszItem)
{
  return CListCtrl::InsertItem(nItem,lpszItem);
}

int CListCtrlEx::InsertItem(int nItem,LPCTSTR lpszItem,int nImage)
{
  return CListCtrl::InsertItem(nItem,lpszItem,nImage);
}

int CListCtrlEx::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;
	/*CRect rc;
	GetClientRect(&rc);
	int cx = rc.Width();
	int cy = 20;
	ApproximateViewRect(CSize(cx,cy));*/
	return 0;
}

void CListCtrlEx::OnSize(UINT nType, int cx, int cy) 
{
  CListCtrl::OnSize(nType, cx, cy);
  //ApproximateViewRect(CSize(cx,20));
}

void CListCtrlEx::PreSubclassWindow() 
{
	CRect rc;
	/*GetClientRect(&rc);
	int cx = rc.Width();
	int cy = 20;
	ApproximateViewRect(CSize(cx,cy));	*/
	CListCtrl::PreSubclassWindow();
}

⌨️ 快捷键说明

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