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

📄 threadtestview.cpp

📁 第4章 图像增强(对比度增强、灰度变换法、直方图修整法、图像平滑、图像锐化、伪彩色和假彩色增强);
💻 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"
#include "afxmt.h"

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

CEvent threadStart;
CEvent threadEnd;
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)
	ON_COMMAND(ID_THREAD_STOP, OnThreadStop)
	ON_MESSAGE(WM_THREAD_SENDMESS, OnThreadSendmess)
	ON_WM_CREATE()
	//}}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
	threadStart.SetEvent();	
}

UINT TreadProc(LPVOID param)
{
	CThreadTestApp *pApp=(CThreadTestApp *) AfxGetApp();
    CMainFrame *pMainFrame = (CMainFrame *)pApp->GetMainWnd();
    CThreadTestView *pView = (CThreadTestView *) pMainFrame->GetActiveView();

    ::WaitForSingleObject(threadStart.m_hObject, INFINITE);
	pView->m_strMessage = "启动了一个线程!";
	BOOL keepRunning = TRUE;
	while (keepRunning)
	{
		::Sleep(1000);
		int result = ::WaitForSingleObject(threadEnd.m_hObject, 0);
		if (result == WAIT_OBJECT_0)
		keepRunning = FALSE;
		::PostMessage((HWND)param, WM_THREAD_SENDMESS, 0, 0);
	}
	pView->m_iTime =0;
	pView->m_strMessage = "线程结束!";
	return 0;
}

void CThreadTestView::OnThraedOther() 
{
	// TODO: Add your command handler code here
	CDlgThread dlg;
	dlg.DoModal();
}

void CThreadTestView::OnThreadStop() 
{
	// TODO: Add your command handler code here
	threadEnd.SetEvent();	
}

int CThreadTestView::OnThreadSendmess()
{
	m_iTime ++;
	Invalidate();
    return 0;
}

int CThreadTestView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	HWND hWnd = GetSafeHwnd();
	AfxBeginThread(TreadProc, hWnd, THREAD_PRIORITY_NORMAL);
	
	return 0;
}

⌨️ 快捷键说明

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