📄 colorlistctrl.cpp
字号:
////////////////////////////////////////////////////////////////////////////////////////////
/*****************************************************************************/
/* ColorListCtrl.h */
/*****************************************************************************/
#include "stdafx.h"
#include "ColorListCtrl.h"
#include "AutoMakeView0.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorListCtrl
// ColorListCtrl.cpp : 实现文件
IMPLEMENT_DYNAMIC(CColorListCtrl, CListCtrl)
CColorListCtrl::CColorListCtrl()
{
}
CColorListCtrl::~CColorListCtrl()
{
POSITION pos = m_lstItemColor.GetHeadPosition();
while (pos)
{
delete []m_lstItemColor.GetNext(pos);
}
}
BEGIN_MESSAGE_MAP(CColorListCtrl, CListCtrl)
ON_WM_LBUTTONUP()
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
END_MESSAGE_MAP()
void CColorListCtrl::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
ModifyStyle(0, /*LVS_OWNERDRAWFIXED | */LVS_REPORT, 0);
CListCtrl::PreSubclassWindow();
}
// CColorListCtrl 消息处理程序
COLORREF CColorListCtrl::SetItemColor(int nRow, int nCol, COLORREF clrItem)
{
int nCols = GetHeaderCtrl()->GetItemCount();
int nRows = GetItemCount();
if (nCol >= nCols || nRow >= nRows)
return COLORREF(-1);
for (int i = m_lstItemColor.GetCount(); i < nRow + 1; i++)
{
COLORREF *clrCol = new COLORREF[nCols];
ZeroMemory(clrCol, sizeof(clrCol));
m_lstItemColor.AddTail(clrCol);
}
for (i = 0; i < nRows; i++)
{
if (i == nRow)
{
COLORREF *clrCol = m_lstItemColor.GetAt(m_lstItemColor.FindIndex(nRow));
COLORREF clrRet = clrCol[nCol];
clrCol[nCol] = clrItem;
return clrRet;
}
}
return COLORREF(-1);
}
COLORREF CColorListCtrl::SetItemColor(LVITEM* plvItem, COLORREF clrItem)
{
if (!plvItem)
{
return COLORREF(0);
}
int nRow = plvItem->iItem;
int nCol = plvItem->iSubItem;
return SetItemColor(nCol, nRow, clrItem);
}
void CColorListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLVCUSTOMDRAW pNMCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
int nRows = m_lstItemColor.GetCount();
int nRow = int(pNMCD->nmcd.dwItemSpec);
COLORREF *clrCol = NULL;
if (nRows && nRow < nRows)
{
clrCol = m_lstItemColor.GetAt(m_lstItemColor.FindIndex(nRow));
}
switch(pNMCD->nmcd.dwDrawStage)
{
case CDDS_PREPAINT :
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT:
if (clrCol)
pNMCD->clrText = clrCol[0];
*pResult = CDRF_NOTIFYSUBITEMDRAW;
return;
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
if (clrCol)
pNMCD->clrText = clrCol[pNMCD->iSubItem];
*pResult = CDRF_NEWFONT;
return;
}
}
void CColorListCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
int nCols = GetHeaderCtrl()->GetItemCount();
int n=GetItemCount();
CRect rc;
for(int i=0;i<n;i++)
{
GetItemRect(i,&rc,LVIR_BOUNDS);
if(rc.PtInRect(point))
{
((CAutoMakeView0*)GetParent())->m_Edit.SetWindowText(GetItemText(i,0));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -