1

I have created thread in VC++ class. using regular way i.e. How do you use CreateThread for functions which are class members?

now i am showing alert message box to user in this thread. using dialog (not using AfxMessageBox)

Dialog style is POPUP. but it is showing another new tab for this alert on taskbar along with my main dialogs tab

How do i remove this tab (tab for alert) from showing in taskbar .

Community
  • 1
  • 1
  • and second dialog is created as CSecondDialog dlg; dlg.DoModal(); – omkarpardeshi Sep 25 '12 at 15:29
  • Thanks i got answer for this just added ModifyStyleEx( WS_EX_APPWINDOW, 0 ); ModifyStyleEx( 0, WS_EX_TOOLWINDOW ); in OnInitDialog() of secondary dialog that works thanks to MSDN Saved my Day – omkarpardeshi Sep 26 '12 at 07:47

1 Answers1

-1

Well, showing a window in another thread is a big no-no! Always show the UI in your UI thread. If your worker thread needs to show some UI, it needs to notify the UI thread (in a safe manner) to let it show the dialog.

Removing the WS_EX_APPWINDOW style is not the solution here. You will most likely end up with weird deadlocks if you don't do it right.

Let your thread post messages to your UI window and then handle it there!

#define UWM_SHOW_UI (WM_APP + 1)
//    
// In your thread procedure:
PostMessage(pThreadData->m_hWnd, UWM_SHOW_UI);
WaitForMultipleObjects(...); // Wait for both exit event (set in `OnDestroy`) and continue event.
// Handle signal... Exit or continue?
//
// In your main window message handler:
void CMyWindow::OnShowUI(WPARAM wParam, LPARAM lParam)
{
    CMyDlg dlg(this);
    dlg.DoModal();
    //
    SetEvent(m_hEventContinue); // Continue thread!
}
l33t
  • 18,692
  • 16
  • 103
  • 180
  • thank you this could be the elegant one i will also try to implement your solution Thanks and regards @NOP slider – omkarpardeshi Sep 27 '12 at 14:03
  • That's nonsense. It's perfectly reasonable (in general, not necessarily in this case) to display user interface components from different threads, subject to certain MFC restrictions (namely that MFC objects are typically only accessible from the thread that created them). In fact, MFC explicitly supports "user interface" threads in AfxBeginThread. – Nik Bougalis Oct 17 '12 at 17:29
  • You're right. Still, I would argue that multithreaded UI is both rare and error-prone. – l33t Oct 18 '12 at 14:36