Return to Snippet

Revision: 9620
at November 14, 2008 11:01 by jimfred


Initial Code
inline void ASSERT_GUI_THREAD() 
{
	const CWnd * pWnd           = AfxGetMainWnd();
	const HWND   hWnd           = pWnd->GetSafeHwnd();
	const DWORD  WindowThreadId = GetWindowThreadProcessId( hWnd, 0 );
	const DWORD  thisThreadId   = AfxGetThread()->m_nThreadID;
	// const bool   bGuiThread     = IsGUIThread(FALSE);
	// ctrlTree.InvokeRequired == false // this might work in .NET but not MFC.

	bool isGuiThread = 
		pWnd != NULL     &&
		hWnd != NULL     &&
		thisThreadId == WindowThreadId;

	ASSERT( isGuiThread );

}

Initial URL

                                

Initial Description

                                

Initial Title
ASSERT_GUI_THREAD - see if current thread is GUI thread in MFC C++

Initial Tags
c

Initial Language
C++