c++ - wxWidgets 菜单栏不显示
问题描述
我正在尝试使用 wxWidgets 创建一个带有菜单的简单程序。但是,菜单似乎没有正确显示。
这是我的代码:
helloworld.hpp:
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "TextFrame.hpp"
class HelloWorldApp : public wxApp {
public:
virtual bool OnInit();
};
DECLARE_APP(HelloWorldApp)
你好世界.cpp:
#include "helloworld.hpp"
IMPLEMENT_APP(HelloWorldApp)
bool HelloWorldApp::OnInit() {
TextFrame *frame = new TextFrame(_T("Hi"), 200, 200, 800, 600);
frame->CreateStatusBar();
frame->SetStatusText(_T("Hello, World!"));
frame->Show(true);
SetTopWindow(frame);
return true;
}
文本框.hpp:
#pragma once
#include <wx/wxprec.h>
#ifndef WX_PREC
#include <wx/wx.h>
#endif
class TextFrame : public wxFrame {
public:
/** Constructor. Creates a new TextFrame */
TextFrame(const wxChar *title, int xpos, int ypos, int width, int height);
private:
wxTextCtrl *m_pTextCtrl;
wxMenuBar *m_pMenuBar;
wxMenu *m_pFileMenu;
wxMenu *m_pHelpMenu;
};
文本框.cpp:
#include "TextFrame.hpp"
TextFrame::TextFrame(const wxChar *title, int xpos, int ypos, int width, int height)
: wxFrame((wxFrame *) NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height))
{
m_pTextCtrl = new wxTextCtrl(this, -1, _T("Type some text..."),
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
m_pMenuBar = new wxMenuBar();
// File Menu
m_pFileMenu = new wxMenu();
m_pFileMenu->Append(wxID_OPEN, _T("&Open"));
m_pFileMenu->Append(wxID_SAVE, _T("&Save"));
m_pFileMenu->AppendSeparator();
m_pFileMenu->Append(wxID_EXIT, _T("&Quit"));
m_pMenuBar->Append(m_pFileMenu, _T("&File"));
// About menu
m_pHelpMenu = new wxMenu();
m_pHelpMenu->Append(wxID_ABOUT, _T("&About"));
m_pMenuBar->Append(m_pHelpMenu, _T("&Help"));
SetMenuBar(m_pMenuBar);
}
这段代码(大部分)直接来自这里。
它编译成功(使用g++ TextFrame.cpp helloworld.cpp `wx-config -cxxflags --libs` -o helloworld
),但是当我运行它时,我看到了默认菜单,而不是我尝试添加的自定义菜单。
我尝试了“菜单”示例并且效果很好,所以我认为我在这里做错了。
谢谢您的帮助。
解决方案
推荐阅读
- java - com.sun.mail.util.MailConnectException:无法连接到主机,端口:smtp.gmail.com,587 超时 -1
- google-apps-script - 将错误消息设置为英语
- design-patterns - 如何在字符串中找到转义字符\?
- java - 逃逸分析是否有助于 JVM 在堆栈上分配数组?
- tornado - 为什么 Tornado 会花时间在 socket.send(data) 中?
- php - chmod():Laravel 中不允许的操作
- emacs - Emacsclient:搜索程序:没有这样的文件或目录,ruby
- parameters - 如何获取视图组件中的参数值?
- android - 来自后台应用程序的 Android 屏幕截图
- javascript - 找不到 Django 静态文件 404