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

📄 infostatic.cpp

📁 一个简单的日程计划工具。用VC7+DAO35开发。有兴趣的话下载后自己研究吧。
💻 CPP
字号:
// InfoStatic.cpp : implementation file
//

#include "stdafx.h"
#include "InfoStatic.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInfoStatic

CInfoStatic::CInfoStatic()
{
	EnableAutomation();
	CTime t = CTime::GetCurrentTime();
	strDate = t.Format("%Y年%m月%d日");
	strTime = t.Format("%H:%M:%S");
	strWeek = ConvertWeek(atoi(t.Format("%w")));
}

CInfoStatic::~CInfoStatic()
{
}

void CInfoStatic::OnFinalRelease()
{
	// When the last reference for an automation object is released
	// OnFinalRelease is called.  The base class will automatically
	// deletes the object.  Add additional cleanup required for your
	// object before calling the base class.

	CStatic::OnFinalRelease();
}


BEGIN_MESSAGE_MAP(CInfoStatic, CStatic)
	//{{AFX_MSG_MAP(CInfoStatic)
	ON_WM_DRAWITEM()
	ON_WM_MEASUREITEM()
	ON_WM_PAINT()
	ON_WM_TIMER()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CInfoStatic, CStatic)
	//{{AFX_DISPATCH_MAP(CInfoStatic)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IInfoStatic to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {39DC67C1-7520-11DA-B210-000039A78533}
static const IID IID_IInfoStatic =
{ 0x39dc67c1, 0x7520, 0x11da, { 0xb2, 0x10, 0x0, 0x0, 0x39, 0xa7, 0x85, 0x33 } };

BEGIN_INTERFACE_MAP(CInfoStatic, CStatic)
	INTERFACE_PART(CInfoStatic, IID_IInfoStatic, Dispatch)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInfoStatic message handlers

void CInfoStatic::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	
	CStatic::OnDrawItem(nIDCtl, lpDrawItemStruct);
}

void CInfoStatic::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	
	CStatic::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

void CInfoStatic::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CStatic::OnPaint() for painting messages
	CBrush m_brush;
	m_brush.CreateSolidBrush(RGB(0,0,0));
	CRect rect;
	GetWindowRect(rect);

	CBrush* pOldBrush = dc.SelectObject(&m_brush);
	dc.FillRect(rect,&m_brush);
	
	dc.SetBkMode(TRANSPARENT);
	CPen DrawPen;
	DrawPen.DeleteObject();
	DrawPen.CreatePen(PS_SOLID,2,RGB(0,255,0));
	CPen* pOldPen = dc.SelectObject(&DrawPen);
	dc.Rectangle(1,1,rect.Width(),rect.Height());

	dc.SetTextColor(RGB(0,255,0));
	dc.TextOut(7,6,strDate);
	dc.TextOut(126,6,strWeek);

	dc.SetTextColor(RGB(255,255,0));
	CFont font;
	font.CreatePointFont(280,"宋体");
	dc.SelectObject(&font);
	dc.TextOut(15,22,strTime);

}

BOOL CInfoStatic::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	return CStatic::PreCreateWindow(cs);
}

void CInfoStatic::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	if(nIDEvent == 0)
	{
		CTime t = CTime::GetCurrentTime();
		strDate = t.Format("%Y年%m月%d日");

		strTime = t.Format("%H:%M:%S");
		int n = atoi(t.Format("%w"));
		strWeek = ConvertWeek(n);
		InvalidateRect(CRect(0,0,515,145),TRUE);
	}
	CStatic::OnTimer(nIDEvent);
}

void CInfoStatic::OnDestroy() 
{
	CStatic::OnDestroy();
	
	// TODO: Add your message handler code here
	KillTimer(0);
}

void CInfoStatic::OnStart()
{
	SetTimer(0,1000,NULL);
}

CString CInfoStatic::ConvertWeek(int nWeekDay)
{
	CString strReturn;
	switch(nWeekDay)
	{
	case 0:
		strReturn = "星期日";
		break;			
	case 1:
		strReturn = "星期一";
		break;
	case 2:
		strReturn = "星期二";
		break;
	case 3:
		strReturn = "星期三";
		break;
	case 4:
		strReturn = "星期四";
		break;
	case 5:
		strReturn = "星期五";
		break;
	case 6:
		strReturn = "星期六";
		break;
	default:
		break;
	}
	return strReturn;
}

⌨️ 快捷键说明

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