Search This Blog

Friday, May 15, 2009

UIThreadImplementation

Create a new class and inherit CWinThread
Add dialog member object in the Thread class


#pragma once
#include "MyDialog.h"
// CMyNewThread

class CMyNewThread : public CWinThread
{
     DECLARE_DYNCREATE(CMyNewThread)

protected:
     CMyNewThread(); // protected constructor used by dynamic creation
     virtual ~CMyNewThread();

public:
     virtual BOOL InitInstance();
     virtual int ExitInstance();

     CMyDialog *m_dlg;

protected:
     DECLARE_MESSAGE_MAP()
};


BOOL CMyNewThread::InitInstance()
{    
     m_dlg = new CMyDialog();
     m_dlg->Create (IDD_DIALOG_MY, NULL);
     m_dlg->ShowWindow( TRUE );
     m_dlg->UpdateWindow();
     return TRUE;

     //return TRUE;
}

// calling the Thread
void CMainFrame::OnNewCreatenewwindow()
{
// TODO: Add your command handler code here
CWinThread *pThread = AfxBeginThread( RUNTIME_CLASS( CMyNewThread ) );
}

No comments: