Home

MFC Topics: Threading

 

Description

This introductory program shows how to use threading:

#include <afxwin.h>

UINT FunCall(LPVOID p)
{
	AfxMessageBox("James",MB_OK);

	return true;
}

class myframe : public CFrameWnd
{
public:
	myframe()
	{
		Create(0,"James");
	}

	void Display()
	{
		CWinThread *p = new CWinThread();
	
		p->CreateThread(CREATE_SUSPENDED);
		p->ResumeThread();
	}

	void Enab()
	{
		CObject *p = new myframe();
		BOOL nEna  = ::AfxEnableMemoryTracking(FALSE);
		
		CObject *p1 = new myframe();
		::AfxEnableMemoryTracking(nEna);
		
		CString Res;
		
		Res = AfxGetAppName();
		MessageBox(Res);
		
		AfxGetMainWnd()->ShowWindow(1);
		ASSERT(AfxIsValidAddress(&p,sizeof(p),TRUE));
		ASSERT(AfxIsValidString("James"));
	}

	void Helper()
	{
		CObject *p=new myframe();
		AfxDump(p);

		/*delete p;
		delete p;
		AfxCheckMemory();*/
		//AfxBeginThread(FunCall,0,THREAD_PRIORITY_NORMAL,0,0);
		//AfxEndThread(0,FALSE);
		//AfxAbort();
	}
} ;


class myapp :public CWinApp
{
public:
	int InitInstance()
	{
		myframe *p = new myframe;

		p->ShowWindow(3);
		p->Helper();
		p->Display();
		p->Enab();
	
		m_pMainWnd=p;
		return 1;
	}
};

myapp a;

 

 

Home Copyright © 2006 James Prasanna