samedi 5 août 2023

getting -5200 while use wxTimer

Im making a simple program where the user can start and stop a timer to set a reminder, my issue is after the user stops the timer and restarts it the timer goes to -5200. This is not the intent. Also For my random number generator I am getting very high negative values.


void MainFrame::OnStartClicked(wxCommandEvent& evt)
{
    wxColour LightGreen(144, 238, 144);
    Start->SetBackgroundColour(LightGreen);
    Stop->SetBackgroundColour(wxNullColour); //sets stop back to default color
    SetStartProgram(true);
    if (!timer->IsRunning()) // Check if the timer is not already running
    {
        if (!optionsWindow) // Check if optionsWindow is nullptr
        {
            optionsWindow = new OptionsWindow("Time Settings");
            optionsWindow->Show(true);
            // Bind an event handler to catch when the OptionsWindow is closed.
            optionsWindow->Bind(wxEVT_CLOSE_WINDOW, &MainFrame::OnOptionsWindowClosed, this);
        }

        if (optionsWindow->GetRandomStatus() == true) {
            // Creating random number between 1 and 60
            std::random_device rd;
            std::mt19937 gen(rd());
            std::uniform_int_distribution<int> dist(1, 60);
            int randomNumber = dist(gen);

            int randomMilliseconds = randomNumber * 60000; // Convert the random number to milliseconds

            timer->Start(randomMilliseconds);
            wxLogMessage("Timer started with random interval: %d milliseconds", randomMilliseconds);
        }
        else {
            int reminderMilliseconds = optionsWindow->GetReminderTime() * 60000; // Convert the reminder time to milliseconds
            

            timer->Start(reminderMilliseconds);
            wxLogMessage("Timer started with interval: %d milliseconds", reminderMilliseconds);
        }

        Start->Disable();
    }

    evt.Skip();
}


void MainFrame::OnStopClicked(wxCommandEvent& evt)
{
    wxColour LightRed(255, 71, 71);
    Stop->SetBackgroundColour(LightRed);
    Start->SetBackgroundColour(wxNullColour); //sets start back to the default color
    SetStartProgram(false);

    if (timer->IsRunning()) {
        // If the timer is running, stop it.
        timer->Stop();
        
    }
    Start->Enable(); // Enable the "Start" button when the timer is stopped
    evt.Skip();
}



Aucun commentaire:

Enregistrer un commentaire