📄 ch13demo3view.cpp
字号:
// Ch13Demo3View.cpp : implementation of the CCh13Demo3View class
//
#include "stdafx.h"
#include "Ch13Demo3.h"
#include "UIDlg.h"
#include "UIThread.h"
#include "Ch13Demo3Doc.h"
#include "Ch13Demo3View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCh13Demo3View
IMPLEMENT_DYNCREATE(CCh13Demo3View, CView)
BEGIN_MESSAGE_MAP(CCh13Demo3View, CView)
//{{AFX_MSG_MAP(CCh13Demo3View)
ON_WM_TIMER()
ON_WM_CREATE()
ON_COMMAND(ID_UI_THREAD, OnUiThread)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCh13Demo3View construction/destruction
CCh13Demo3View::CCh13Demo3View()
{
// TODO: add construction code here
}
CCh13Demo3View::~CCh13Demo3View()
{
}
BOOL CCh13Demo3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCh13Demo3View drawing
void CCh13Demo3View::OnDraw(CDC* pDC)
{
CCh13Demo3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCh13Demo3View printing
BOOL CCh13Demo3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCh13Demo3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCh13Demo3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCh13Demo3View diagnostics
#ifdef _DEBUG
void CCh13Demo3View::AssertValid() const
{
CView::AssertValid();
}
void CCh13Demo3View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCh13Demo3Doc* CCh13Demo3View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCh13Demo3Doc)));
return (CCh13Demo3Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCh13Demo3View message handlers
void CCh13Demo3View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
CClientDC dc(this); //获得DC
CFont myfont;
CFont*oldfont;
LOGFONT font;
memset(&font,0,sizeof(LOGFONT)); //为字体结构赋初值,默认值
font.lfHeight=50; //字体高度为50
font.lfWeight=600;
strcpy(font.lfFaceName,"Arial");
myfont.CreateFontIndirect(&font); //创建新字体
oldfont=dc.SelectObject(&myfont); //将新字体选入设备环境*/
CTime m_time;
m_time=CTime::GetCurrentTime(); //获取当前时间日期
CString str=m_time.Format("当前时间:%H:%M:%S"); //格式化
dc.TextOut(40,70,str);//显示时间
dc.SelectObject(oldfont); //恢复设备环境中的旧字体
}
CView::OnTimer(nIDEvent);
}
int CCh13Demo3View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,NULL); //设置定时器,每秒触发一次
return 0;
}
void CCh13Demo3View::OnUiThread()
{
// TODO: Add your command handler code here
/* CUIDlg *pDlg=new CUIDlg;
pDlg->Create(IDD_DIALOG1); //创建非模态对话框
pDlg->ShowWindow(SW_SHOW); //显示对话*/
//使用AfxBeginThread函数启动用户界面线程
CWinThread *pThread=AfxBeginThread(RUNTIME_CLASS(CUIThread),0,0,NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -