-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathFrameShowHide.cpp
More file actions
60 lines (51 loc) · 1.76 KB
/
FrameShowHide.cpp
File metadata and controls
60 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <wx/app.h>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/frame.h>
#include <wx/panel.h>
class Frame1 : public wxFrame {
public:
Frame1() : wxFrame {nullptr, wxID_ANY, "Frame show and hide example"} {
SetClientSize(320, 325);
Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent& e) {
wxTheApp->Exit();
});
closeButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) {
if (frame2 != nullptr) frame2->Close();
});
showButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) {
CreateFrame2();
frame2->Show();
});
hideButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) {
CreateFrame2();
frame2->Hide();
});
CreateFrame2();
}
private:
void CreateFrame2() {
if (frame2 == nullptr) {
frame2 = new wxFrame(nullptr, wxID_ANY, wxString::Format("CloseCount = %d", closeCount));
frame2->SetClientSize(300, 100);
frame2->Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent& e) {
e.Skip(!cancelCloseButton->IsChecked());
if (!cancelCloseButton->IsChecked()) {
closeCount++;
frame2 = nullptr;
}
});
}
}
wxPanel* panel = new wxPanel {this};
wxButton* closeButton = new wxButton(panel, wxID_ANY, "Close", {10, 10}, {100, 40}, wxBORDER_SIMPLE);
wxButton* showButton = new wxButton(panel, wxID_ANY, "Show", {10, 60}, {100, 40}, wxBORDER_SIMPLE);
wxButton* hideButton = new wxButton(panel, wxID_ANY, "Hide", {10, 110}, {100, 40}, wxBORDER_SIMPLE);
wxCheckBox* cancelCloseButton = new wxCheckBox(panel, wxID_ANY, "cancel close", {10, 160}, {100, 40});
wxFrame* frame2 = nullptr;
int closeCount = 0;
};
class Application : public wxApp {
auto OnInit() -> bool override {return (new Frame1())->Show();}
};
wxIMPLEMENT_APP(Application);