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

📄 sublcdwin.cpp

📁 一个手机副屏的时钟程序
💻 CPP
字号:

#include "SubLCDWin.hpp"


#define PIE 3.1415926535897932384626433832795

SubLCDWin::SubLCDWin() :
	Base()
{
}	// SubLCDWin

/*	------------------------------------------------------------------------
	Init
	------------------------------------------------------------------------ */
void SubLCDWin::Init() 
{
	Base::Init();

	SetFrameType(Control::NoFrame);

	m_indicator_bar.Init(this, FALSE);


	for (INT i = IndicatorConfig::SubLCDFirstIdleScreenIndicator; i <= IndicatorConfig::SubLCDLastIdleScreenIndicator; i++)
		m_indicator_bar.AddIndicator(IndicatorConfig::GetSubLCDIndicator(i));

	

}	// Init

/*	------------------------------------------------------------------------
	OnOpen
	------------------------------------------------------------------------ */
void SubLCDWin::OnOpen()
{
	Base::OnOpen();
	SetDisplayIndex(1);

	m_time_box.SetText(L"time");
	m_date_box.SetText(L"date");


	// Set indicator visible in indicator bar
	Indicator *ind = IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDSignalStrengthIndicator);
	ind->SetVisible(TRUE);
	ValueIndicator *value_ind = (ValueIndicator*)IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDSignalStrengthIndicator);
	value_ind->SetValue(0);
	ind = IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDBatteryStrengthIndicator);
	ind->SetVisible(TRUE);


}	// OnOpen

/*	------------------------------------------------------------------------
	OnMessage
	------------------------------------------------------------------------ */
BOOLEAN SubLCDWin::OnMessage(const Message &msg)
{
	BOOLEAN dispatched = TRUE;

	switch (msg.Id()) {

	
		case SubLCDIndicatorUpdateMsg::ID: 
		{
			const SubLCDIndicatorUpdateMsg *change_indicator_msg;
			CastMsg(change_indicator_msg, &msg);
			ChangedIndicator(change_indicator_msg->GetType(),change_indicator_msg->IsVisible(), change_indicator_msg->GetValue());
			
			break;
		}
		case SubLCDDateTimeUpdateMsg::ID:
		{
			Invalidate();
			break;
		}

		default:
			dispatched = Base::OnMessage(msg);
	}

	return dispatched;
}	// OnMessage
	
void SubLCDWin::ChangedIndicator(INT16 type, BOOLEAN visible, INT value)
{
	Indicator* ind = IndicatorConfig::GetSubLCDIndicator(type);

	if (type == IndicatorConfig::SubLCDSignalStrengthIndicator || type == IndicatorConfig::SubLCDBatteryStrengthIndicator)
	{
		if (value != -1)
		{
			ValueIndicator *value_ind = (ValueIndicator*)IndicatorConfig::GetSubLCDIndicator(type);
			value_ind->SetValue(value);
		}
	}
	else
	{
	if (ind != 0)
		ind->SetVisible(visible);
	}

	m_indicator_bar.Invalidate();

}


/*	------------------------------------------------------------------------
	OnPaint
	------------------------------------------------------------------------ */
void SubLCDWin::OnPaint(const Rect &repaint_rect)
{
	PaintDc pdc(GetDeviceContext());

	DrawIcon(&pdc);
	pdc.DrawBitmap(0,12,clock_1);
	
	Draw(&pdc );
	DrawBoot(&pdc );
	Base::OnPaint(repaint_rect);
}	// OnPaint


Point SubLCDWin::CalculateClockHandPos(Point point, int Pos,int radius)
{
    //int ItemHeight = 1;
	//int ItemWidth = 1;
	Point pt ;//= {NULL}

	// adjust the pos so that 0 is at 12 o'clock
	Pos -= 15;
    //point 圆心,pos 位置,num 格子数,radius 半径
	pt.SetX( radius*cos((2*PIE*Pos)/60)+point.GetX())/*-(ItemHeight/2)*/;		// 99.9906055343044551579175019907702 Radius = 100
	pt.SetY( radius*sin((2*PIE*Pos)/60)+point.GetY())/*-(ItemWidth/2)*/;		// 1.37069503651368915565336356870794

	return pt;
}

void SubLCDWin::DrawHand(PaintDc* destDC,int nValue,Point ptCenterPoint,int nLength,Color crColor)
{
	// draw hand
	int nWidth = 1;
	destDC->SetPenColor(crColor);
	
	Point ptEndPoint = CalculateClockHandPos(ptCenterPoint,nValue,nLength);
	destDC->DrawLine(ptCenterPoint.GetX(),ptCenterPoint.GetY() ,ptEndPoint.GetX(),ptEndPoint.GetY() );

}// end

void SubLCDWin::Draw(PaintDc* destDC)
{
	//SYSTEMTIME currentTime = {NULL};
	//GetLocalTime(&currentTime);
	Time currentTime;
	currentTime=Time();
	int nTempHour = currentTime.GetHour();
	
	if( nTempHour> 11)
		nTempHour -= 12;
	// CreateClockIcon(nTempHour,currentTime.wMinute,currentTime.wSecond,currentTime.wMilliseconds);
	Point ptCenterPoint(47,32);

	DrawHand(destDC,(nTempHour*5)+(currentTime.GetMinute()/12),ptCenterPoint,10,Color(255,255,225));
	DrawHand(destDC,currentTime.GetMinute(),ptCenterPoint,13,Color(255,255,225));
	//DrawIconHand(iconDC,maskDC,nSecond,ptCenterPoint,60,8,RGB(200,0,0));

}

void SubLCDWin::DrawIcon(PaintDc* pdc) 
{
	pdc->SetBrushColorRgb(25,247,239);
	pdc->FillRect(0,0,95,11);
	
	// draw indicators
	Indicator* ind;
	
	const INT icon_int = 3;
	Point pt(1, 1);
	Rect draw_rect(0, 0, 95, 11);

	ind = IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDSignalStrengthIndicator);
	if (ind != 0) {
		ind->Draw(pdc, pt, draw_rect);
		pt.Move(ind->GetSize().GetWidth() + icon_int, 0);
	}
		
			

	ind = IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDSmsArrivedIndicator);
	if (ind != 0) {
		ind->Draw(pdc, pt, draw_rect);
		pt.Move(ind->GetSize().GetWidth() + icon_int, 0);
	}


	ind = IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDAlarmIndicator);
	if (ind != 0) {
		ind->Draw(pdc, pt, draw_rect);
		pt.Move(ind->GetSize().GetWidth() + icon_int, 0);
	}

	
	ind = IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDSilentRingIndicator);
	if (ind != 0) {
		ind->Draw(pdc, pt, draw_rect);
		pt.Move(ind->GetSize().GetWidth() + icon_int, 0);
	}



	ind = IndicatorConfig::GetSubLCDIndicator(IndicatorConfig::SubLCDBatteryStrengthIndicator);
	pt.SetX(95 - 1 - ind->GetSize().GetWidth());
	if (ind != 0) {
		ind->Draw(pdc, pt, draw_rect);
	}
}

void SubLCDWin::DrawBoot(PaintDc* pdc) 
{
	pdc->SetBrushColorRgb(25,247,239);
	pdc->FillRect(0,51,95,63);
	Date date;
	pdc->DrawText(8, 51, (date.GetWString(Date::ShortDateDMY)).c_str());

}

⌨️ 快捷键说明

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