本文介绍了mfc中与程序相关的多线程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个Thrad过程函数ThreadProc制作了一个视图文件.编译时会出现如下错误:

ThreadDemoView.cpp(114):错误C2146:语法错误:丢失;在标识符``ThreadProc''之前;
ThreadDemoView.cpp(114):错误C2501:UNIT; :缺少存储类或类型说明符
严重错误C1004:发现文件意外结束
执行cl.exe时出错.

我是MFC的新手,请帮忙.








I have made one view file with one Thrad procedure function ThreadProc. While compiling it gives error as:

ThreadDemoView.cpp(114) : error C2146: syntax error : missing ; before identifier ''ThreadProc'';
ThreadDemoView.cpp(114) : error C2501: UNIT; : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found
Error executing cl.exe.

I am new in mfc please help.








// ThreadDemoView.cpp : implementation of the CThreadDemoView class
//

#include "stdafx.h"
#include "ThreadDemo.h"

#include "ThreadDemoDoc.h"
#include "ThreadDemoView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView

IMPLEMENT_DYNCREATE(CThreadDemoView, CView)

BEGIN_MESSAGE_MAP(CThreadDemoView, CView)
	//{{AFX_MSG_MAP(CThreadDemoView)
	ON_WM_LBUTTONDOWN()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView construction/destruction

CThreadDemoView::CThreadDemoView()
{
	// TODO: add construction code here

}

CThreadDemoView::~CThreadDemoView()
{
}

BOOL CThreadDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView drawing

void CThreadDemoView::OnDraw(CDC* pDC)
{
	CThreadDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView printing

BOOL CThreadDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CThreadDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CThreadDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView diagnostics

#ifdef _DEBUG
void CThreadDemoView::AssertValid() const
{
	CView::AssertValid();
}

void CThreadDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CThreadDemoDoc* CThreadDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CThreadDemoDoc)));
	return (CThreadDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView message handlers

struct ThreadStruct
{
	CPoint pt;
	CDC dc;
	HWND hWnd;
};
ThreadStruct structure;

UINT ThreadProc(LPVOID param);
UNIT ThreadProc(LPVOID param)
{
	structure *s=(structure *)param;
	HDC dc=GetDC(s->hWnd);
	RECT rect;
	HBrush hbr;
	hbr = CreateSolidBrush(RGB(255, 0, 0));
	SelectObject(dc,hbr);
	for(i=0;i<10;i++)
	{
		Ellipse(dc,s->pt.x,s->pt.y,s->pt.x+30,s->pt.y+30);
		Sleep(1000);
	}
	return 0;
}
void CThreadDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	structure.pt=point;
	structure.hWnd=GetSafeHwnd();
	AfxBeginThread(ThreadProc,&point);
	CView::OnLButtonDown(nFlags, &structure.pt);
}

推荐答案



这篇关于mfc中与程序相关的多线程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:41
查看更多