/////////////////////////////////////////////////////////////////////////////
// Name: thread.cpp
-// Purpose: wxWindows thread sample
+// Purpose: wxWidgets thread sample
// Author: Guilhem Lavaux, Vadim Zeitlin
// Modified by:
// Created: 06/16/98
// RCS-ID: $Id$
-// Copyright: (c) 1998-2002 wxWindows team
+// Copyright: (c) 1998-2002 wxWidgets team
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
{
public:
MyApp();
- virtual ~MyApp();
+ virtual ~MyApp(){};
virtual bool OnInit();
// waiting for us
if ( wxGetApp().m_waitingUntilAllDone )
{
- wxGetApp().m_waitingUntilAllDone = FALSE;
+ wxGetApp().m_waitingUntilAllDone = false;
wxGetApp().m_semAllDone.Post();
}
MyApp::MyApp()
: m_semAllDone()
{
- m_waitingUntilAllDone = FALSE;
-}
-
-MyApp::~MyApp()
-{
+ m_waitingUntilAllDone = false;
}
// `Main program' equivalent, creating windows and returning main app frame
//wxLog::AddTraceMask("thread");
// Create the main frame window
- MyFrame *frame = new MyFrame((wxFrame *)NULL, _T("wxWindows threads sample"),
+ MyFrame *frame = new MyFrame((wxFrame *)NULL, _T("wxWidgets threads sample"),
50, 50, 450, 340);
// Make a menubar
frame->SetMenuBar(menuBar);
// Show the frame
- frame->Show(TRUE);
+ frame->Show(true);
SetTopWindow(frame);
- return TRUE;
+ return true;
}
// My frame constructor
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))
+ : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
{
m_nRunning = m_nCount = 0;
m_dlgProgress = (wxProgressDialog *)NULL;
+#if wxUSE_STATUSBAR
CreateStatusBar(2);
+#endif // wxUSE_STATUSBAR
- m_txtctrl = new wxTextCtrl(this, -1, _T(""), wxPoint(0, 0), wxSize(0, 0),
+ m_txtctrl = new wxTextCtrl(this, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(0, 0),
wxTE_MULTILINE | wxTE_READONLY);
}
if ( count )
{
// set the flag for MyThread::OnExit()
- wxGetApp().m_waitingUntilAllDone = TRUE;
+ wxGetApp().m_waitingUntilAllDone = true;
// stop all threads
while ( ! threads.IsEmpty() )
threads.Add(thr);
}
+#if wxUSE_STATUSBAR
wxString msg;
msg.Printf(wxT("%d new threads created."), count);
SetStatusText(msg, 1);
+#endif // wxUSE_STATUSBAR
// ...and then start them
for ( n = 0; n < count; n++ )
wxLogError(wxT("Can't start thread!"));
}
+#if wxUSE_STATUSBAR
SetStatusText(_T("New thread started."), 1);
+#endif // wxUSE_STATUSBAR
}
void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) )
thread->Delete();
+#if wxUSE_STATUSBAR
SetStatusText(_T("Thread stopped."), 1);
+#endif // wxUSE_STATUSBAR
}
}
{
wxGetApp().m_threads[n]->Resume();
+#if wxUSE_STATUSBAR
SetStatusText(_T("Thread resumed."), 1);
+#endif // wxUSE_STATUSBAR
}
}
{
wxGetApp().m_threads[n]->Pause();
+#if wxUSE_STATUSBAR
SetStatusText(_T("Thread paused."), 1);
+#endif // wxUSE_STATUSBAR
}
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
{
- Close(TRUE);
+ Close(true);
}
void MyFrame::OnExecMain(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
{
wxMessageDialog dialog(this,
- _T("wxWindows multithreaded application sample\n")
+ _T("wxWidgets multithreaded application sample\n")
_T("(c) 1998 Julian Smart, Guilhem Lavaux\n")
_T("(c) 1999 Vadim Zeitlin\n")
_T("(c) 2000 Robert Roebling"),
);
// thread is not running yet, no need for crit sect
- m_cancelled = FALSE;
+ m_cancelled = false;
thread->Run();
}
{
wxCriticalSectionLocker lock(m_critsectWork);
- m_cancelled = TRUE;
+ m_cancelled = true;
}
}
#endif