in my example, I want to do a very simple example just Increasing a progress bar (wxGauge) to reach 100% by using a thread.
Code: Select all
// mainFrm.cpp (Main Window)
void mainFrm::button_OnClick(wxCommandEvent & event) {
thread = new CThread;
if (thread->Run() != wxTHREAD_NO_ERROR) {
wxLogError("Can't create the thread!");
delete thread;
thread = NULL;
}
}
// CThread.cpp
CThread::CThread() : wxThread(wxTHREAD_DETACHED) {
}
Code: Select all
wxThread::ExitCode CThread::Entry() {
int counter = 0;
progressbar = (wxGauge*)wxWindow::FindWindowByName("progressbar");
button = (wxButton*)wxWindow::FindWindowByName("button");
textbox = (wxTextCtrl*)wxWindow::FindWindowByName("textbox");
button->Enable(false);
while (!TestDestroy()) {
while (counter <= 100) {
progressbar->SetValue(counter);
counter += 10;
textbox->SetValue(wxString::Format("%i", progressbar->GetValue()));
wxThread::Sleep(200);
}
}
button->Enable(true);
wxMessageOutputDebug().Printf("%s", "The operation was compeleted.");
return (wxThread::ExitCode)0;
}
Code: Select all
wxThread::ExitCode CThread::Entry() {
int counter = 0;
while (!TestDestroy()) {
while (counter <= 100) {
counter += 10;
wxMessageOutputDebug().Printf("%i", counter);
wxThread::Sleep(200);
}
wxMessageOutputDebug().Printf("%i", this->IsAlive()); // prints "1"
}
wxMessageOutputDebug().Printf("%s", "The operation was compeleted.");
return (wxThread::ExitCode)0;
}
Is there something wrong with my code?