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


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. inline void ASSERT_GUI_THREAD()
  2. {
  3. const CWnd * pWnd = AfxGetMainWnd();
  4. const HWND hWnd = pWnd->GetSafeHwnd();
  5. const DWORD WindowThreadId = GetWindowThreadProcessId( hWnd, 0 );
  6. const DWORD thisThreadId = AfxGetThread()->m_nThreadID;
  7. // const bool bGuiThread = IsGUIThread(FALSE);
  8. // ctrlTree.InvokeRequired == false // this might work in .NET but not MFC.
  9.  
  10. bool isGuiThread =
  11. pWnd != NULL &&
  12. hWnd != NULL &&
  13. thisThreadId == WindowThreadId;
  14.  
  15. ASSERT( isGuiThread );
  16.  
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.