In pursuit of my other question . As an option, I would like to try in the wxWidgets window application just to programmatically simulate menu commands, buttons, etc. - to automate the calculation, as if it is a person. Something like a macro :)

Only I can’t find out how to transfer these commands (alternatively, I found GetEventHandler()->ProcessEvent(event) in the help), and what function should I do to send the commands right away, not by my command: ) - not in OnInit main window - the window should be completely created and initialized by this moment.

How to do all this correctly?

    1 answer 1

    Well, since no one answers, I myself :)

    So, how to do it - just create the appropriate event and send it for processing.

     wxCommandEvent event; event.SetEventObject(this); event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED); event.SetId(id_CalcDs); GetEventHandler()->ProcessEvent(event); 

    The subtlety is (that I didn’t realize right away) that it’s not handling the event that triggers a button, say, but vice versa. Those. if I need to change, say, the state of the TOGGLE_BUTTON switch, then I need to not only handle the event, but first change its state — about

     event.SetEventType(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED); event.SetId(id_ToggleButton); toggleButton->SetValue(!toggleButton->GetValue()); // Меняем состояние GetEventHandler()->ProcessEvent(event); 

    Well, the last thing is how to automate the call initiation ... In principle, it worked in CreateControls() main window, but it seemed to me somewhat "dumb", so I did - I don’t know how correct it was to initiate this process OnIdle() - something like this:

     void MainWindow::OnIdle( wxIdleEvent& event) { static bool once = true; if (once) { once = false; AutoRun(); // Здесь вся обработка последовательности } } 

    Not very sure of absolute correctness, but it works.

    Waiting for criticism :)