-MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
- wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
-{}
+MyFrame::MyFrame(wxFrame *frame, const wxString& title,
+ int x, int y, int w, int h)
+ : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
+{
+ m_nRunning = m_nCount = 0;
+
+ m_dlgProgress = (wxProgressDialog *)NULL;
+
+ CreateStatusBar(2);
+
+ m_txtctrl = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(0, 0),
+ wxTE_MULTILINE | wxTE_READONLY);
+
+}
+
+MyThread *MyFrame::CreateThread()
+{
+ MyThread *thread = new MyThread(this);
+
+ if ( thread->Create() != wxTHREAD_NO_ERROR )
+ {
+ wxLogError("Can't create thread!");
+ }
+
+ wxCriticalSectionLocker enter(wxGetApp().m_critsect);
+ wxGetApp().m_threads.Add(thread);
+
+ return thread;
+}
+
+void MyFrame::OnStartThreads(wxCommandEvent& WXUNUSED(event) )
+{
+ static long s_num = 10;
+
+ s_num = wxGetNumberFromUser("How many threads to start: ", "",
+ "wxThread sample", s_num, 1, 10000, this);
+ if ( s_num == -1 )
+ {
+ s_num = 10;
+
+ return;
+ }
+
+ size_t count = (size_t)s_num, n;
+
+ wxArrayThread threads;
+
+ // first create them all...
+ for ( n = 0; n < count; n++ )
+ {
+ wxThread *thr = CreateThread();
+
+ // we want to show the effect of SetPriority(): the first thread will
+ // have the lowest priority, the second - the highest, all the rest
+ // the normal one
+ if ( n == 0 )
+ thr->SetPriority(WXTHREAD_MIN_PRIORITY);
+ else if ( n == 1 )
+ thr->SetPriority(WXTHREAD_MAX_PRIORITY);
+ else
+ thr->SetPriority(WXTHREAD_DEFAULT_PRIORITY);
+
+ threads.Add(thr);
+ }
+
+ wxString msg;
+ msg.Printf("%d new threads created.", count);
+ SetStatusText(msg, 1);
+
+ // ...and then start them
+ for ( n = 0; n < count; n++ )
+ {
+ threads[n]->Run();
+ }
+}