Click here to Skip to main content
14,882,311 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}
Posted

You also need to make sure you free any GDI resources you use.

the thread is calling GetDC() where is the ReleaseDC() call?
Where do you delete the brush object you create?
   
Comments
TABREJ PATEL 10-Nov-11 1:51am
   
Oh.. Yes i forgot to do so. Thanks.
You misspelled UINT as UNIT in front of the ThreadProc function.
   
Comments
Albert Holguin 3-Nov-11 10:59am
   
that would explain the error, +5
TABREJ PATEL 10-Nov-11 1:52am
   
Got it. Thank you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900