📄 dlgkqprojectmaster.cpp
字号:
// DlgKqProjectMaster.cpp : implementation file
//
#include "stdafx.h"
#include "Kvip.h"
#include "DlgKqProjectMaster.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgKqProjectMaster
CDlgKqProjectMaster::CDlgKqProjectMaster()
{
}
CDlgKqProjectMaster::~CDlgKqProjectMaster()
{
}
BEGIN_MESSAGE_MAP(CDlgKqProjectMaster, CListCtrl)
//{{AFX_MSG_MAP(CDlgKqProjectMaster)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgKqProjectMaster message handlers
void CDlgKqProjectMaster::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
CRect rcItem, rcMask;
CString sText;
CBrush Brush;
COLORREF rcColor, rcBkColor;
int x = 0;
int nItem = lpDrawItemStruct->itemID;
int nColumnSize = GetHeaderCtrl()->GetItemCount();
//取区间
rcItem = GetCellRect(nItem, 0, FALSE);
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
//画背景
pDC->FillSolidRect(rcMask, GetBkColor());
for (x=0; x<nColumnSize; x++)
{//画每一子项目
rcItem = GetCellRect(nItem, x, FALSE);
sText = CListCtrl::GetItemText(nItem, x);
if(x == 0 )
{//第一列
GetColorEx(sText, rcColor, rcBkColor);
}
else
{
GetDrawColors(nItem, x, rcColor, rcBkColor);
}
pDC->FillSolidRect(rcItem, rcBkColor);
if (IsCheckBox(x))
{//是否CheckBox
DrawCheckbox(pDC, sText, rcItem, rcColor, rcBkColor);
}
else
{
pDC->SetTextColor(rcColor);
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(sText, rcItem, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
}
}
}
void CDlgKqProjectMaster::GetDrawColors(int nItem,
int nSubItem,
COLORREF& colorText,
COLORREF& colorBkgnd)
{
DWORD dwStyle = GetStyle();
DWORD dwExStyle = GetExtendedStyle();
//COLORREF crText = colorText;
//COLORREF crBkgnd = colorBkgnd;
COLORREF crText =m_crWindowText; //系统默认
COLORREF crBkgnd =m_crWindow;
if (GetItemState(nItem, LVIS_SELECTED))
{
if (dwExStyle & LVS_EX_FULLROWSELECT)
{
// selected? if so, draw highlight background
crText = m_crHighLightText;
crBkgnd = m_crHighLight;
// has focus? if not, draw gray background
if (m_hWnd != ::GetFocus())
{
if (dwStyle & LVS_SHOWSELALWAYS)
{
crText = m_crWindowText;
crBkgnd = m_crBtnFace;
}
else
{
crText = colorText;
crBkgnd = colorBkgnd;
}
}
}
else // not full row select
{
if (nSubItem == 0)
{
// selected? if so, draw highlight background
crText = m_crHighLightText;
crBkgnd = m_crHighLight;
// has focus? if not, draw gray background
if (m_hWnd != ::GetFocus())
{
if (dwStyle & LVS_SHOWSELALWAYS)
{
crText = m_crWindowText;
crBkgnd = m_crBtnFace;
}
else
{
crText = colorText;
crBkgnd = colorBkgnd;
}
}
}
}
}
colorText = crText;
colorBkgnd = crBkgnd;
}
///////////////////////////////////////////////////////////////////////////////
// DrawCheckbox
void CDlgKqProjectMaster::DrawCheckbox(CDC *pDC,
CString &sText,
CRect& rect,
COLORREF crText,
COLORREF crBkgnd)
{
ASSERT(pDC);
// ASSERT(pXLCD);
// GetDrawColors(nItem, nSubItem, crText, crBkgnd);
// pDC->FillSolidRect(&rect, crBkgnd);
CRect chkboxrect, rc2;
chkboxrect = rect;
// chkboxrect.bottom -= 1;
chkboxrect.left += 9; // line up checkbox with header checkbox
chkboxrect.right = chkboxrect.left + chkboxrect.Height() + 3; // width = height
// CString str;
// str = GetItemText(nItem, nSubItem);
// if (str.IsEmpty())
// {
// center the checkbox
// chkboxrect.left = rect.left + rect.Width()/2 - chkboxrect.Height()/2 - 1;
// chkboxrect.right = chkboxrect.left + chkboxrect.Height();
// }
// fill rect around checkbox with white
pDC->FillSolidRect(&chkboxrect, m_crWindow);
chkboxrect.left += 1;
// draw border
pDC->DrawEdge(&chkboxrect, EDGE_SUNKEN, BF_RECT);
//if (pXLCD[nSubItem].nCheckedState == 1)
if(sText == _T("Y"))
{
rc2 = chkboxrect;
rc2.left += 2; rc2.top += 2;
rc2.right -= 2; rc2.bottom-=1;
pDC->FillSolidRect(&rc2, RGB(255,0,0));
CPen *pOldPen = NULL;
//CPen graypen(PS_SOLID, 1, m_crGrayText);
CPen blackpen(PS_SOLID, 1, RGB(0,0,0));
//if (pXLCD[0].bEnabled)
pOldPen = pDC->SelectObject(&blackpen);
//else
// pOldPen = pDC->SelectObject(&graypen);
// draw the checkmark
int x = chkboxrect.left + 9;
ASSERT(x < chkboxrect.right);
int y = chkboxrect.top + 3;
int i;
for (i = 0; i < 4; i++)
{
pDC->MoveTo(x, y);
pDC->LineTo(x, y+3);
x--;
y++;
}
for (i = 0; i < 3; i++)
{
pDC->MoveTo(x, y);
pDC->LineTo(x, y+3);
x--;
y--;
}
if (pOldPen)
pDC->SelectObject(pOldPen);
}
}
void CDlgKqProjectMaster::SetCheckBox(int nSubItem)
{
if(nSubItem < 0) return;
m_caCheckBox.Add((UINT)nSubItem);
}
BOOL CDlgKqProjectMaster::IsCheckBox(int nSubItem)
{
if(nSubItem < 0) return false;
for(int i = 0; i < m_caCheckBox.GetSize(); i++)
{
if(m_caCheckBox.GetAt(i) == (UINT)nSubItem)
return true;
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -