#26990·wxWidgets

Child widget added via CallAfter to a wxAuiNotebook page remains disabled after MessageBox is closed (wxMSW)

Author: BazaarAcc32Created Sep 9, 2026Updated Sep 13, 2026

Description

When a MessageBox is displayed and a non-GUI thread calls CallAfter(func), where func adds a child widget to a page of a wxAuiNotebook, the newly added widget appears in a disabled state while the MessageBox is visible. After the MessageBox is closed, the widget remains disabled and never becomes enabled.

Also, this error is shown in console: wxWidgets\src\msw\window.cpp(532): 'SetFocus' failed with error 0x00000057 (The parameter is incorrect.)

Expected vs observed behaviour:

I expect that the child widget should be enabled after MessageBox is closed

To Reproduce:

  1. Run app
  2. Press LoadContent button
  3. Wait until new button is added in the wxAuiNotebook page
  4. Close MessageBox by pressing OK
  5. Enjoy disabled button :)

App code:

cpp
#include <wx/wx.h>
#include <wx/aui/auibook.h>
#include <thread>
#include <chrono>

class MyPage : public wxPanel
{
public:
    wxBoxSizer* sizer;

    MyPage(wxWindow* parent) : wxPanel(parent)
    {
        sizer = new wxBoxSizer(wxVERTICAL);
        SetSizer(sizer);
    }

    void AddRealWidget()
    {
        wxButton* btn = new wxButton(this, wxID_ANY, "ClickMe");
        btn->Bind(wxEVT_BUTTON, &MyPage::OnButton, this);
        sizer->Add(btn, 0, wxALL, 10);
        Layout();
    }

    void OnButton(wxCommandEvent&)
    {
        wxMessageBox("Button clicked", "Info", wxOK, this);
    }
};

class MyFrame : public wxFrame
{
public:
    wxAuiNotebook* notebook;
    MyPage* page;

    MyFrame() : wxFrame(nullptr, wxID_ANY, "Repro", wxDefaultPosition, wxSize(600, 400))
    {
        notebook = new wxAuiNotebook(this);

        page = new MyPage(notebook);
        notebook->AddPage(page, "Page", true);

        wxButton* loadBtn = new wxButton(this, wxID_ANY, "LoadContent");
        loadBtn->Bind(wxEVT_BUTTON, &MyFrame::OnLoad, this);

        wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
        sizer->Add(loadBtn, 0, wxALL, 10);
        sizer->Add(notebook, 1, wxEXPAND | wxALL, 10);
        SetSizer(sizer);
    }

    void OnLoad(wxCommandEvent&)
    {
        std::thread([this]() {
            std::this_thread::sleep_for(std::chrono::milliseconds(500));
            page->CallAfter([this]() {
                page->AddRealWidget();
            });
        }).detach();

        wxMessageBox("Loading in progress", "Info", wxOK, this);
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        MyFrame* frame = new MyFrame();
        frame->Show(true);
        return true;
    }
};

wxIMPLEMENT_APP(MyApp);

Platform and version information

  • wxWidgets version you use: 3.3.4 (master)
  • wxWidgets port you use: wxMSW
  • OS and its version: Windows 11