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.
#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
IMPLEMENT_DYNCREATE(CThreadDemoView, CView)
BEGIN_MESSAGE_MAP(CThreadDemoView, CView)
ON_WM_LBUTTONDOWN()
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::CThreadDemoView()
{
}
CThreadDemoView::~CThreadDemoView()
{
}
BOOL CThreadDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
void CThreadDemoView::OnDraw(CDC* pDC)
{
CThreadDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
BOOL CThreadDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
void CThreadDemoView::OnBeginPrinting(CDC* , CPrintInfo* )
{
}
void CThreadDemoView::OnEndPrinting(CDC* , CPrintInfo* )
{
}
#ifdef _DEBUG
void CThreadDemoView::AssertValid() const
{
CView::AssertValid();
}
void CThreadDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CThreadDemoDoc* CThreadDemoView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CThreadDemoDoc)));
return (CThreadDemoDoc*)m_pDocument;
}
#endif //_DEBUG
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)
{
structure.pt=point;
structure.hWnd=GetSafeHwnd();
AfxBeginThread(ThreadProc,&point);
CView::OnLButtonDown(nFlags, &structure.pt);
}