?? threadtestview.cpp
字號:
// ThreadTestView.cpp : implementation of the CThreadTestView class
//
#include "stdafx.h"
#include "ThreadTest.h"
#include "ThreadTestDoc.h"
#include "ThreadTestView.h"
#include "MainFrm.h"
#include "DlgThread.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
UINT TreadProc(LPVOID param);
/////////////////////////////////////////////////////////////////////////////
// CThreadTestView
IMPLEMENT_DYNCREATE(CThreadTestView, CView)
BEGIN_MESSAGE_MAP(CThreadTestView, CView)
//{{AFX_MSG_MAP(CThreadTestView)
ON_COMMAND(ID_THREAD_START, OnThreadStart)
ON_COMMAND(ID_THRAED_OTHER, OnThraedOther)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CThreadTestView construction/destruction
CThreadTestView::CThreadTestView()
{
// TODO: add construction code here
m_strMessage = "沒有線程啟動";
m_iTime = 0;
}
CThreadTestView::~CThreadTestView()
{
}
BOOL CThreadTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CThreadTestView drawing
void CThreadTestView::OnDraw(CDC* pDC)
{
CThreadTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
char chNumber[6];
itoa(m_iTime, chNumber, 10);
pDC->TextOut(30,30, m_strMessage);
pDC->TextOut(30,50,chNumber);
}
/////////////////////////////////////////////////////////////////////////////
// CThreadTestView printing
BOOL CThreadTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CThreadTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CThreadTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CThreadTestView diagnostics
#ifdef _DEBUG
void CThreadTestView::AssertValid() const
{
CView::AssertValid();
}
void CThreadTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CThreadTestDoc* CThreadTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CThreadTestDoc)));
return (CThreadTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CThreadTestView message handlers
void CThreadTestView::OnThreadStart()
{
// TODO: Add your command handler code here
HWND hWnd = GetSafeHwnd();
AfxBeginThread(TreadProc, hWnd, THREAD_PRIORITY_NORMAL);
}
UINT TreadProc(LPVOID param)
{
CThreadTestApp *pApp=(CThreadTestApp *) AfxGetApp();
CMainFrame *pMainFrame = (CMainFrame *)pApp->GetMainWnd();
CThreadTestView *pView = (CThreadTestView *) pMainFrame->GetActiveView();
pView->m_strMessage = "啟動了一個線程!";
while(pView->m_iTime < 20)
{
::Sleep(1000);
pView->m_iTime ++;
pView->Invalidate();
}
pView->m_iTime =0;
pView->m_strMessage = "線程結(jié)束!";
return 0;
}
void CThreadTestView::OnThraedOther()
{
// TODO: Add your command handler code here
CDlgThread dlg;
dlg.DoModal();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -