Search code examples
c++wxwidgets

Menu and toolbar disappear with wxTopLevelWindow::ShowFullScreen()


I try to display my app automatically in fullscreen. The problem is that my toolbar and menu bar disappears with the wxTopLevelWindow::ShowFullScreen() function and that whatever the option I add in. Does someone have any idea how to deal whith that ?

Bellow a part of my code :

MyApp.cpp

#include "MyApp.h"
   
wxIMPLEMENT_APP(MyApp);

MyApp::MyApp()
{

}

MyApp::~MyApp()
{

}

bool MyApp::OnInit()
{
    wxInitAllImageHandlers();
    MainWindow* mainWindow = new MainWindow("My software");

    mainWindow->Show();
    return true;
}

MainWindow.h

class MainWindow : public wxFrame
{
public:

    MainWindow(const wxString& title);
    ~MainWindow();

    wxMenuBar* menuBar = nullptr;
    wxMenu* fileMenu = nullptr;
    wxMenu* toolsMenu = nullptr;
    wxToolBar* toolbar = CreateToolBar();


    

    wxDECLARE_EVENT_TABLE();

private:

    wxImagePanel* m_renderWindow;

};

MainWindow.cpp

    MainWindow::MainWindow(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxPoint(0,0), wxSize(800,600))
    {
     
        SetIcon(wxIcon("icon.ico", wxBITMAP_TYPE_ICO));
    
    
    wxBitmap png_ClosedDevice(wxT("close.png"), wxBITMAP_TYPE_PNG);
    
        menuBar = new wxMenuBar();
        fileMenu = new wxMenu();
        toolsMenu = new wxMenu();
    
        menuBar->Append(fileMenu, _T("&File"));
        menuBar->Append(toolsMenu, _T("&Tools"));
        SetMenuBar(menuBar);
      
        this->SetBackgroundColour(*wxWHITE);
    
        wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
        m_renderWindow = new wxImagePanel(this, wxT("Image.png"), wxBITMAP_TYPE_PNG);    
        sizer->Add(m_renderWindow, 1, wxSHAPED | wxALIGN_CENTER);
        this->SetSizer(sizer);
        this->Layout();
this->ShowFullScreen(true);

        
        toolbar->AddTool(10001, _T("ClosedDevice"), png_ClosedDevice);
        Layout();
        this->GetToolBar()->EnableTool(10001, false);
    
    }

Solution

  • ShowFullScreen has flags that determine what to hide.

    wxFULLSCREEN_NOMENUBAR
    wxFULLSCREEN_NOTOOLBAR
    wxFULLSCREEN_NOSTATUSBAR
    wxFULLSCREEN_NOBORDER
    wxFULLSCREEN_NOCAPTION
    wxFULLSCREEN_ALL (all of the above)
    

    wxFULLSCREEN_ALL is the default.

    So if you want the toolbar and menu bar you'll use.

    this->ShowFullScreen(true, wxFULLSCREEN_NOSTATUSBAR || wxFULLSCREEN_NOBORDER || wxFULLSCREEN_NOCAPTION);
    

    https://docs.wxwidgets.org/3.0/classwx_top_level_window.html#ab4089f1274bcb74e5f7763d1fb84ee28