📄 myctrl.cpp
字号:
// MYCTRL.cpp : implementation file
//
#include "stdafx.h"
#include "最近邻法分类器.h"
#include "MYCTRL.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMYCTRL
CMYCTRL::CMYCTRL()
{
for(int i=0;i<45;i++)
{
flag[i]=false;
}
start=end=0; movef=false;mf=false;textf=false; falg1=false;falg2=false;flagf=false;
//person=new CDpersonINfo(this);
//
}
CMYCTRL::~CMYCTRL()
{
}
BEGIN_MESSAGE_MAP(CMYCTRL, CListCtrl)
//{{AFX_MSG_MAP(CMYCTRL)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMYCTRL message handlers
void CMYCTRL::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
//从lpDrawItemStruct获取控件的相关信息
if(textf)
{
int j;
int col=GetHeaderCtrl( )->GetItemCount();
int ROWS = GetItemCount();
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
int nSaveDC=pDC->SaveDC();
UINT state = lpDrawItemStruct->itemState;
textf=false;
CRect rect2;
GetItemRect( count, rect2, LVIR_BOUNDS );
int templ=rect2.Width()/10;
if(flag[count])
{
for(int i1=0;i1<10;i1++)
{
CRect rect3;
rect3.top=rect2.top;
rect3.bottom=rect2.bottom;
rect3.left=rect2.left+i1*templ;
rect3.right=rect3.left+templ;
pDC->FillSolidRect(&rect3, RGB(255, 230+i1, 189+i1));
}
}
else
{
for(int i1=0;i1<10;i1++)
{
CRect rect3;
rect3.top=rect2.top;
rect3.bottom=rect2.bottom;
rect3.left=rect2.left+i1*templ;
rect3.right=rect3.left+templ;
pDC->FillSolidRect(&rect3, RGB(194+2*i1,218+2*i1,249));
}
}
for(j=0;j<col;j++)
{
CRect rect1;
GetSubItemRect(count,j,LVIR_BOUNDS ,rect1);
pDC->SelectStockObject(BLACK_PEN);
if(count==0)
{
pDC->MoveTo(rect1.left, rect1.top);
pDC->LineTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.right, rect1.top);
}
else
{
if(count==ROWS-1)
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
}
else
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.left, rect1.bottom);
}
}
}
//////////////////////////////
for (j=0;j<col;j++)
{
CRect rect;
if(j==0)
{
GetSubItemRect(count,j+1,LVIR_BOUNDS ,rect);
rect.right=rect.left;rect.left=0;
}
else
GetSubItemRect(count,j,LVIR_BOUNDS ,rect);
CString strText=GetItemText(count,j);
if (!strText.IsEmpty( ))
{
CFont* hFont = GetFont();
CFont* hOldFont = pDC->SelectObject(hFont);
CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
CPoint pt( rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2);
if (state & ODS_SELECTED)
pt.Offset(1, 1);
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
else
pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
pDC->SelectObject(hOldFont);
pDC->SetBkMode(nMode);
}
}
/////////////////////////////////
return;
}
int i,j;
CRect rect = lpDrawItemStruct->rcItem;
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
int nSaveDC=pDC->SaveDC();
UINT state = lpDrawItemStruct->itemState;
int col=GetHeaderCtrl( )->GetItemCount();
int ROWS = GetItemCount();
if(start==0&&end==0)
{
for(i=0;i<ROWS;i++)
{
CRect rect2;
GetItemRect( i, rect2, LVIR_BOUNDS );
int templ=rect2.Width()/10;
if(flag[i])
{
for(int i1=0;i1<10;i1++)
{
CRect rect3;
rect3.top=rect2.top;
rect3.bottom=rect2.bottom;
rect3.left=rect2.left+i1*templ;
rect3.right=rect3.left+templ;
pDC->FillSolidRect(&rect3, RGB(255, 230+i1, 189+i1));
}
}
else
{
for(int i1=0;i1<10;i1++)
{
CRect rect3;
rect3.top=rect2.top;
rect3.bottom=rect2.bottom;
rect3.left=rect2.left+i1*templ;
rect3.right=rect3.left+templ;
pDC->FillSolidRect(&rect3, RGB(194+2*i1,218+2*i1,249));
}
}
for(j=0;j<col;j++)
{
CRect rect1;
GetSubItemRect(i,j,LVIR_BOUNDS ,rect1);
pDC->SelectStockObject(BLACK_PEN);
if(i==0)
{
pDC->MoveTo(rect1.left, rect1.top);
pDC->LineTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.right, rect1.top);
}
else
{
if(i==ROWS-1)
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
}
else
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.left, rect1.bottom);
}
}
}
}
for(i=0;i<ROWS;i++)
{
for (j=0;j<col;j++)
{
CRect rect1;
if(j==0)
{
GetSubItemRect(i,j+1,LVIR_BOUNDS ,rect);
rect.right=rect.left;rect.left=0;
}
else
GetSubItemRect(i,j,LVIR_BOUNDS ,rect);
CString strText=GetItemText(i,j);
if (!strText.IsEmpty( ))
{
CFont* hFont = GetFont();
CFont* hOldFont = pDC->SelectObject(hFont);
CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
CPoint pt( rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2);
if (state & ODS_SELECTED)
pt.Offset(1, 1);
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
else
pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
pDC->SelectObject(hOldFont);
pDC->SetBkMode(nMode);
}
}
}
}
else
{
if(start!=0)
{
CRect rect2;
GetItemRect(start-1, rect2, LVIR_BOUNDS );
int templ=rect2.Width()/10;
for(int i1=0;i1<10;i1++)
{
CRect rect3;
rect3.top=rect2.top;
rect3.bottom=rect2.bottom;
rect3.left=rect2.left+i1*templ;
rect3.right=rect3.left+templ;
pDC->FillSolidRect(&rect3, RGB(255, 230+i1, 189+i1));
}
for(j=0;j<col;j++)
{
CRect rect1;
GetSubItemRect(start-1,j,LVIR_BOUNDS ,rect1);
pDC->SelectStockObject(BLACK_PEN);
if(start==1)
{
pDC->MoveTo(rect1.left, rect1.top);
pDC->LineTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.right, rect1.top);
}
else
{
if(start==ROWS)
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
}
else
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.left, rect1.bottom);
}
}
}
for (j=0;j<col;j++)
{
CRect rect1;
if(j==0)
{
GetSubItemRect(start-1,j+1,LVIR_BOUNDS ,rect);
rect.right=rect.left;rect.left=0;
}
else
GetSubItemRect(start-1,j,LVIR_BOUNDS ,rect);
CString strText=GetItemText(start-1,j);
if (!strText.IsEmpty( ))
{
CFont* hFont = GetFont();
CFont* hOldFont = pDC->SelectObject(hFont);
CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
CPoint pt( rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2);
if (state & ODS_SELECTED)
pt.Offset(1, 1);
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
else
pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
pDC->SelectObject(hOldFont);
pDC->SetBkMode(nMode);
}
}
}
if(end!=0)
{
CRect rect2;
GetItemRect(end-1, rect2, LVIR_BOUNDS );
int templ=rect2.Width()/10;
for(int i1=0;i1<10;i1++)
{
CRect rect3;
rect3.top=rect2.top;
rect3.bottom=rect2.bottom;
rect3.left=rect2.left+i1*templ;
rect3.right=rect3.left+templ;
pDC->FillSolidRect(&rect3, RGB(194+2*i1,218+2*i1,249));
}
for(j=0;j<col;j++)
{
CRect rect1;
GetSubItemRect(end-1,j,LVIR_BOUNDS ,rect1);
pDC->SelectStockObject(BLACK_PEN);
if(end-1==0)
{
pDC->MoveTo(rect1.left, rect1.top);
pDC->LineTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.right, rect1.top);
}
else
{
if(end==ROWS)
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
}
else
{
pDC->MoveTo(rect1.left, rect1.bottom);
pDC->LineTo(rect1.left, rect1.top);
pDC->LineTo(rect1.right, rect1.top);
pDC->LineTo(rect1.right, rect1.bottom);
pDC->LineTo(rect1.left, rect1.bottom);
}
}
}
for (j=0;j<col;j++)
{
CRect rect1;
if(j==0)
{
GetSubItemRect(end-1,j+1,LVIR_BOUNDS ,rect);
rect.right=rect.left;rect.left=0;
}
else
GetSubItemRect(end-1,j,LVIR_BOUNDS ,rect);
CString strText=GetItemText(end-1,j);
if (!strText.IsEmpty( ))
{
CFont* hFont = GetFont();
CFont* hOldFont = pDC->SelectObject(hFont);
CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
CPoint pt( rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2);
if (state & ODS_SELECTED)
pt.Offset(1, 1);
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
else
pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
pDC->SelectObject(hOldFont);
pDC->SetBkMode(nMode);
}
}
}
}
pDC->RestoreDC(nSaveDC);
}
void CMYCTRL::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CListCtrl::PreSubclassWindow();
ModifyStyle(0,LVS_OWNERDRAWFIXED );
}
BOOL CMYCTRL::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return false;
}
BOOL CMYCTRL::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
//
return CListCtrl::PreCreateWindow(cs);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -