+ dlg.ShowModal();
+}
+
+
+// ----------------------------------------------------------------------------
+// MyImageDialog
+// ----------------------------------------------------------------------------
+
+BEGIN_EVENT_TABLE(MyImageDialog, wxDialog)
+ EVT_THREAD(GUITHREAD_EVENT, MyImageDialog::OnGUIThreadEvent)
+ EVT_PAINT(MyImageDialog::OnPaint)
+END_EVENT_TABLE()
+
+MyImageDialog::MyImageDialog(wxFrame *parent)
+ : wxDialog(parent, wxID_ANY, "Image created by a secondary thread",
+ wxDefaultPosition, wxSize(GUITHREAD_BMP_SIZE,GUITHREAD_BMP_SIZE)*1.5, wxDEFAULT_DIALOG_STYLE),
+ m_thread(this)
+{
+ m_nCurrentProgress = 0;
+
+ CentreOnScreen();
+
+ // NOTE: no need to lock m_csBmp until the thread isn't started:
+
+ // create the bitmap
+ if (!m_bmp.Create(GUITHREAD_BMP_SIZE,GUITHREAD_BMP_SIZE) || !m_bmp.IsOk())
+ {
+ wxLogError("Couldn't create the bitmap!");
+ return;
+ }
+
+ // clean it
+ wxMemoryDC dc(m_bmp);
+ dc.SetBackground(*wxBLACK_BRUSH);
+ dc.Clear();
+
+ // draw the bitmap from a secondary thread
+ if ( m_thread.Create() != wxTHREAD_NO_ERROR ||
+ m_thread.Run() != wxTHREAD_NO_ERROR )
+ {
+ wxLogError(wxT("Can't create/run thread!"));
+ return;
+ }
+}
+
+MyImageDialog::~MyImageDialog()
+{
+ // in case our thread is still running and for some reason we are destroyed,
+ // do wait for the thread to complete as it assumes that its MyImageDialog
+ // pointer is always valid
+ m_thread.Delete();