Hi! I have just got stuck in a thread dilemma.Here is my code. CUIThread.h Code: #pragma once #include "resource.h" // CUIThread class CUIThread : public CWinThread { DECLARE_DYNCREATE(CUIThread) public: CUIThread(); // protected constructor used by dynamic creation virtual ~CUIThread(); HWND m_hWnd; public: virtual BOOL InitInstance(); virtual int ExitInstance(); protected: DECLARE_MESSAGE_MAP() }; --------------------------------------------------------------------- CUIThread.cpp // UIThread.cpp : implementation file // #include "stdafx.h" #include "UIThread.h" #include "resource.h" // CUIThread IMPLEMENT_DYNCREATE(CUIThread, CWinThread) CUIThread::CUIThread() { } CUIThread::~CUIThread() { } BOOL CUIThread::InitInstance() { CDialog *ProBar = new CDialog(); ProBar->Create(IDD_PROGRESS); ProBar->ShowWindow(SW_SHOW); ProBar->UpdateWindow(); m_bAutoDelete = FALSE; m_pMainWnd = ProBar; m_hWnd = m_pMainWnd->m_hWnd; return TRUE; } int CUIThread::ExitInstance() { return CWinThread::ExitInstance(); } BEGIN_MESSAGE_MAP(CUIThread, CWinThread) END_MESSAGE_MAP() ------------------------------------------------------------------ main.cpp CUIThread *ProDlg = ( CUIThread * )AfxBeginThread(RUNTIME_CLASS( CUIThread ) ); The Modeless dialog is displayed but the problem is I am unable to access any controls in the modeless dialog from main.cpp can anyone tell where I have gone wrong or am I missing anything or is there any work around. It is a progress control dialog Thanks in advance
You are totally wrong in the concept. You are creating a dialog in one thread and trying to access the control in other thread which would make your life miserable
But the dialog (progress control) has to be present in a separate thread Is there any good example code where I can refer in terms of thread synchronization
Its not about synchronization. Windows control does not allow creation of control in one thread and update from other threads you need to use the same thread to update it. Try sending messages to the creation thread to update the controls