如何一次创建帧的一个实例

How to create one instance of a frame at a time

我在我的 C++ 应用程序中使用 wxWidgets。

我有一个 wxGrid 设置,用户可以在其中双击一个单元格,这将创建一个新的 window 和另一个网格。

我在关闭和重新打开带有网格的新 window 时遇到问题。

void FeatureList::mouseDClick(wxGridEvent& event)
{
int n_row, n_col;
n_row = event.GetRow();
n_col = 0;

m_sCellValue = grid->GetCellValue(n_row, n_col); 

if ( frame == NULL ) // If frame is closed
{
    CreateCrackBoxFrame(m_sCellValue);
}
else{
    frame->Raise();  // otherwise bring it to the front.
}
}

void FeatureList::CreateCrackBoxFrame(wxString m_sCellValue)
{
frame = new CrackBoxFrame(m_pvFeatures, m_sCellValue, m_bDisplayInMetric);
frame->Show(true);
}

CrackBoxFrame::CrackBoxFrame(vector<Feature> *pvFeatures, wxString CellValue, 
bool bDisplayInMetric)
: wxFrame(NULL, wxID_ANY, wxT("CrackBoxes"),wxDefaultPosition, wxSize(725, 
400))
{
 }

如果我关闭新的 window,然后单击另一个单元格,我的程序就会崩溃

为此你有几个选择:

  1. 保持线的向量,当网格中的线被点击时,检查是否从向量中点击了合适的线,只有当它没有被点击时才允许事件发生。

  2. 处理完点击后禁用线路,不要让第二个通过。

  3. 在网格中的每一行添加复选框,并在第一次单击时选中它。在后续的 - 检查是否未检查该值。

你选择...

谢谢。


编辑:

void FeatureList::CreateCrackBoxFrame(wxString m_sCellValue)
{
    frame = new CrackBoxFrame(m_pvFeatures, m_sCellValue, m_bDisplayInMetric);
    frame->Show(true);
    frame->Bind( wxEVT_CLOSE, &FeatureList::OnCrackBoxClose, this );
}