📄 ~toolbartime.~cpp
字号:
// ToolbarTime.cpp : implementation file
//
#include "stdafx.h"
#include "../DvrManager.h"
#include "ToolbarTime.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CToolbarTime dialog
CToolbarTime::CToolbarTime(CWnd* pParent /*=NULL*/)
: baseclass(CToolbarTime::IDD, pParent)
{
//{{AFX_DATA_INIT(CToolbarTime)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
date_fmt.LoadString(IDS_DATE_FORMAT);
time_fmt.LoadString(IDS_TIME_FORMAT);
}
void CToolbarTime::DoDataExchange(CDataExchange* pDX)
{
baseclass::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CToolbarTime)
DDX_Control(pDX, ID_TIME, m_time);
DDX_Control(pDX, ID_DATE, m_date);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CToolbarTime, baseclass)
//{{AFX_MSG_MAP(CToolbarTime)
ON_WM_ERASEBKGND()
ON_WM_TIMER()
ON_WM_CTLCOLOR()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CToolbarTime message handlers
BOOL CToolbarTime::OnInitDialog()
{
baseclass::OnInitDialog();
/*
m_date.SetFontName(_T("Verdana"));
m_date.SetFontSize(12);
m_date.SetFontBold(TRUE);
m_date.SetTransparent(TRUE);
m_date.SetTextColor(RGB(255,255,255));
m_time.SetFontName(_T("Verdana"));
m_time.SetFontSize(18);
m_time.SetFontBold(TRUE);
m_time.SetTransparent(TRUE);
m_time.SetTextColor(RGB(255,255,255));
//*/
ft_date.CreatePointFont(90, _T("Verdana"));
ft_time.CreatePointFont(90, _T("Verdana"));
LOGFONT lf;
ft_time.GetLogFont(&lf);
ft_time.DeleteObject();
lf.lfWeight = FW_BOLD;
ft_time.CreateFontIndirect(&lf);
display_time();
SetTimer(1, 1000, NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CToolbarTime::OnEraseBkgnd(CDC* pDC)
{
/*
CRect rc;
GetClientRect(rc);
pDC->FillRect(rc, &CBrush(bkcl));
pDC->FrameRect(rc, &CBrush(RGB(255,255,255)));
*/
return TRUE;
}
void CToolbarTime::OnTimer(UINT nIDEvent)
{
if( nIDEvent == 1 ) // Display time
{
display_time();
}
baseclass::OnTimer(nIDEvent);
}
void CToolbarTime::display_time()
{
COleDateTime now = COleDateTime::GetCurrentTime();
date = now.Format(date_fmt);
time = now.Format(time_fmt);
RedrawWindow();
// m_date.SetText(strDate);
// m_time.SetText(strTime);
}
HBRUSH CToolbarTime::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = baseclass::OnCtlColor(pDC, pWnd, nCtlColor);
if( nCtlColor == CTLCOLOR_STATIC )
{
// pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(RGB(0,0,80));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void paintbk(CWnd* self, CDC& cdc)
{
CRect rc;
self->GetWindowRect(rc);
self->GetParent()->ScreenToClient(rc);
CDC* dc = self->GetParent()->GetDC();
cdc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCCOPY);
self->GetParent()->ReleaseDC(dc);
}
#include "memdc.h"
void CToolbarTime::OnPaint()
{
CPaintDC dc(this); // device context for painting
if( !IsWindowVisible() )
return;
CRect rc;
GetClientRect(rc);
CMemDC mdc(&dc, rc);
// 填色, 白框
mdc.FillRect(rc, &CBrush(bkcl));
// mdc.FrameRect(rc, &CBrush(RGB(255,255,255)));
CRect rc_date;
CRect rc_time;
m_date.GetWindowRect(rc_date);
m_time.GetWindowRect(rc_time);
ScreenToClient(rc_date);
ScreenToClient(rc_time);
mdc.SetBkMode(TRANSPARENT);
mdc.SetTextColor(RGB(255,255,255));
CFont *old;
old = mdc.SelectObject(&ft_date);
mdc.DrawText(date, rc_date, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
mdc.SelectObject(old);
old = mdc.SelectObject(&ft_time);
mdc.DrawText(time, rc_time, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
mdc.SelectObject(old);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -