如何仅在单击其中的按钮时销毁 wxWidgets Popup?

How to destroy wxWidgets Popup ONLY on clicking button inside it?

我使用“wxPopupTransientWindow”创建了一个弹出窗口并添加了一些文本和一个按钮。现在我只想在单击此特定按钮时销毁此弹出窗口。现在,如果点击 Popup 之外的任何地方,Popup 就会被销毁。 这是我到目前为止尝试过的方法。

SimpleTransientPopup::SimpleTransientPopup(wxWindow *parent, bool scrolled) : wxPopupTransientWindow(parent, wxFRAME_SHAPED)
{

    m_bGotItClick = false;
    m_panel = new wxScrolledWindow(this,-1,wxDefaultPosition,wxDefaultSize);
    m_panel->SetBackgroundColour(*wxYELLOW);

    wxStaticText *text = new wxStaticText( m_panel, wxID_ANY,
                          "This panel will guide you stepwise through the workflow\n");

    wxPanel *pBottomPanel = new wxPanel(m_panel, -1);
    m_button = new wxButton(pBottomPanel, Minimal_PopupButton, "Got it!",wxDefaultPosition, wxDefaultSize);
    m_link = new wxHyperlinkCtrl(pBottomPanel, Minimal_PopupLink, _("Hide these tips"), _(""), wxDefaultPosition, wxDefaultSize, wxHL_ALIGN_LEFT);
    m_link->SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_NORMAL, true));
    m_link->SetNormalColour(*wxLIGHT_GREY);
    m_link->SetForegroundColour(*wxLIGHT_GREY);
    wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer *bottomSizer = new wxBoxSizer(wxHORIZONTAL);
    
    bottomSizer->Add(m_link,0,wxALL,20);
    bottomSizer->AddStretchSpacer();
    bottomSizer->Add(m_button, 0, wxALL, 20);
    
    pBottomPanel->SetAutoLayout(true);
    pBottomPanel->SetSizer(bottomSizer);
    bottomSizer->SetSizeHints(pBottomPanel);
    bottomSizer->Fit(pBottomPanel);

    topSizer->Add(text, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 20);
    topSizer->Add(pBottomPanel,0,wxEXPAND);
    
    m_panel->SetSizer( topSizer );
    // Use the fitting size for the panel if we don't need scrollbars.
    topSizer->Fit(m_panel);

    SetClientSize(m_panel->GetSize());
    wxTipKind tipKind = wxTipKind_Auto;
    const int offsetY = SetTipShapeAndSize(tipKind, GetBestSize());
    if (offsetY > 0)
    {
        // Offset our contents by the tip height to make it appear in the
        // main rectangle.
        topSizer->PrependSpacer(offsetY);
    }
    m_panel->Fit();
}

我在单击按钮时调用此 OnDismiss 函数。

void SimpleTransientPopup::OnDismiss()
{
    if (m_bGotItClick) {
        wxLogMessage("%p SimpleTransientPopup::OnDismiss", this);
        wxPopupTransientWindow::OnDismiss();
        m_bGotItClick = false;
    }
}

PS: 我是wxWidgets的新手

通过覆盖“wxPopupTransientWindow::Dismiss()”,我能够在单击按钮时关闭弹出窗口。

void SimpleTransientPopup::Dismiss()
{
    if (m_bGotItClick) {
        wxLogMessage("%p SimpleTransientPopup::Dismiss", this);
        wxPopupTransientWindow::Dismiss();
        m_bGotItClick = false;
    }
}