📄 mysheetcontrol.cpp
字号:
// MySheetcontrol.cpp: implementation of the CMySheetcontrol class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "front.h"
#include "MyLabel.h"
#include "MySheetcontrol.h"
#include "MySheetpage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMySheetcontrol::CMySheetcontrol(UINT id,CWnd *parent)
{
col=RGB(243, 243, 243);
bodorcol=GetSysColor(COLOR_BACKGROUND);
ID=id;
pParentWnd=parent;
iCurrentPage=0;
bEnable=true;
}
CMySheetcontrol::~CMySheetcontrol()
{
int i=0,AllCount=arTitles.GetSize();
CMyLabel *temp;
CMySheetpage *page;
for(i=0;i<AllCount;i++)
{
temp=(CMyLabel *)arTitles.GetAt(i);
if(temp)
delete temp;
page=(CMySheetpage *)arPages.GetAt(i);
delete page;
}
if(AllCount>0)
{
arTitles.RemoveAll();
arPages.RemoveAll();
}
}
void CMySheetcontrol::draw(CDC *pDC)
{
CPen *pOldPen,pen,pen1;
CBrush *pOldBrush,brush;
brush.CreateSolidBrush(col);
pen.CreatePen(PS_SOLID | PS_COSMETIC, 1, bodorcol);
pOldBrush = pDC->SelectObject(&brush);
pOldPen = pDC->SelectObject(&pen);
pDC->RoundRect(ControlRect,CPoint(17,17));
pen1.CreatePen(PS_SOLID | PS_COSMETIC, 1, col);
pOldPen = pDC->SelectObject(&pen1);
CRect tempRC;
tempRC.SetRect(ControlRect.left+1,ControlRect.top+1,ControlRect.right-1,ControlRect.bottom/2);
pDC->RoundRect(tempRC,CPoint(1,1));
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
if(arPages.GetSize()==0)return;
CMyLabel *PressedLabel;
for(int i=0;i<arPages.GetSize();i++)
{
CMyLabel *label=(CMyLabel *)arTitles.GetAt(i);
if(!label->bPressed)
label->DrawLabel(pDC);
else
PressedLabel=label;
}
// PressedLabel->crBodercol+=100; 如果标题是叠加的就要用上
PressedLabel->DrawLabel(pDC);
//画每一页
for(i=0;i<arPages.GetSize();i++)
{
CMySheetpage *page=(CMySheetpage *)arPages.GetAt(i);
page->setEnable(false); //让不显示的页不能用
if(i==PressedLabel->iAct) //是要画的那一页
{
page->draw(pDC);
page->setEnable(true);
}
}
}
void CMySheetcontrol::Addpage(void *page)
{
arPages.Add(page);
int all=arPages.GetSize();
CMyLabel *label;
label=new CMyLabel(((CMySheetpage *)page)->cTitle,2,((CMySheetpage *)page)->iShape,true,false,ID,-1,pParentWnd);
label->crBodercol=bodorcol+1;
label->crBackcol=bodorcol;
label->iAct=all-1;
if(label->iAct==0)label->bPressed=true;
if(((CMySheetpage *)page)->IsFile) //图标存于文件
{
label->OpenBitmap(((CMySheetpage *)page)->cFilename);
label->StretchWidth=4;
}
int left,right,top,bottom;
left=ControlRect.left-ControlRect.Width()/4;
right=ControlRect.left;
top=(label->iAct)*ControlRect.Height()/11+ControlRect.top;
bottom=top+ControlRect.Height()/11;
label->setPos(left,top,right,bottom);
arTitles.Add((void *)label);
}
void CMySheetcontrol::OnMouseMove(CPoint point)
{
if(!bEnable)return;
CMyLabel *label;
CMySheetpage *page;
for(int i=0;i<arPages.GetSize();i++)
{
label=(CMyLabel *)arTitles.GetAt(i);
label->iAct=i;
label->OnMouseMove(point);
if(iCurrentPage==i) //只检测当前显示页的鼠标事件
{
page=(CMySheetpage *)arPages.GetAt(i);
page->OnMouseMove(point);
}
}
}
void CMySheetcontrol::OnRButtonDown(CPoint point)
{
if(!bEnable)return;
CMyLabel *label;
CMySheetpage *page;
for(int i=0;i<arPages.GetSize();i++)
{
label=(CMyLabel *)arTitles.GetAt(i);
label->iAct=i;
label->OnRButtonDown(point);
if(iCurrentPage==i) //只检测当前显示页的鼠标事件
{
page=(CMySheetpage *)arPages.GetAt(i);
page->OnRButtonDown(point);
}
}
}
void CMySheetcontrol::OnLButtonUp(CPoint point)
{
if(!bEnable)return;
CMyLabel *label;
CMySheetpage *page;
for(int i=0;i<arPages.GetSize();i++)
{
label=(CMyLabel *)arTitles.GetAt(i);
label->iAct=i;
label->OnLButtonUp(point);
if(iCurrentPage==i) //只检测当前显示页的鼠标事件
{
page=(CMySheetpage *)arPages.GetAt(i);
page->OnLButtonUp(point);
}
}
}
void CMySheetcontrol::OnLButtonDown(CPoint point)
{
if(!bEnable)return;
CMyLabel *label;
CMySheetpage *page;
for(int i=0;i<arPages.GetSize();i++)
{
label=(CMyLabel *)arTitles.GetAt(i);
label->iAct=i;
label->OnLButtonDown(point);
if(iCurrentPage==i) //只检测当前显示页的鼠标事件
{
page=(CMySheetpage *)arPages.GetAt(i);
page->OnLButtonDown(point);
}
}
}
void CMySheetcontrol::setPos(int left, int top, int right, int bottom)
{
ControlRect.SetRect(left,top,right,bottom);
}
void CMySheetcontrol::outRect()
{
CMySheetpage *page;
for(int i=0;i<arPages.GetSize();i++)
if(iCurrentPage==i)
{
page=(CMySheetpage *)arPages.GetAt(i);
page->OutRect();
}
}
void CMySheetcontrol::setCurrentpage(int pageNo)
{
iCurrentPage=pageNo;
}
void CMySheetcontrol::OnTimer()
{
CMySheetpage *page;
page=(CMySheetpage *)arPages.GetAt(iCurrentPage);
page->OnTimer();
}
void CMySheetcontrol::setEnable(bool enable)
{
bEnable=enable;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -