我必须声明自己的 wxFrame 类吗?
Must I declare own wxFrame class?
我正在创建带有用户界面的简单c ++应用程序。我已经编写了自己的类,其中包含所需的机制,现在我必须使用 wxWidgets 显示它的一些组件。MyApp
包含该类的对象,但在处理事件时也需要MyFrame
它们。如果不传递指向该对象的指针来MyFrame
和实现MyApp::OnInit
函数中的所有内容,它会舒服得多。这可能吗?
// should contain informations about game state, players, gameboard, etc
class MyApp : public wxApp {
GameBoard gb;
Player player;
bool lightTheme;
public:
virtual bool OnInit();
};
// should contain only window layout, button events, etc
class MyFrame : public wxFrame {
GameBoard *gb;
Player *player;
bool *lightTheme;
std::vector<wxStaticBitmap*> cardImages;
// some events here
void displayImages(wxGridSizer*);
public:
MyFrame(GameBoard*, Player*, bool*);
};
要回答标题问题,您不必声明MyFrame
,只需创建并直接使用wxFrame
并使用Bind()
来连接不同的事件处理程序。在除最简单的情况之外的所有情况下,通常都方便使用MyFrame
类来集中窗口的数据和事件处理程序,但无论如何都不需要这样做。
如果您决定将所有内容保留在MyApp
中,您可能会发现 wxGetApp() 对于从代码中的不同位置访问它很有用。
相关文章:
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 一个Q_PROPERTY可以泛化为多个基类吗?
- 我应该在简单的策略游戏中为各个派系使用类吗 - C++
- 我可以通过将类强制转换为 char* 来序列化类吗?
- 我可以引用模板的基类吗?
- 我可以在函数中调用该类中的类吗?
- CPP:定义模板时,通用数据类型 T 是类吗?
- 我可以比朴素哈希表更快地将随机字符串映射到两个类吗?
- C++11:我可以显式调用基类析构函数来销毁派生类吗
- "const_iterator"真的需要与"迭代器"是不同的类吗?
- 这是一个有效的单例类吗?
- 我必须声明自己的 wxFrame 类吗?
- mbed 内存池 - 它可用于非平凡类吗?
- 我可以模板化以避免重写类吗?
- 我可以创建一个可以接受任何枚举的模板(非类型)param类吗?C 11
- 我可以在Qt中使用QUdpSockets轮询或自定义类吗?
- 我必须实例化这个类吗?或者这是一个糟糕的责任分离
- 我们可以"wrap"模板化类与C++中的非模板化类吗?
- 可以在C 03中有条件地声明朋友类吗?
- 无论螺纹库如何,我们都可以使用Mutex类吗?