wxWidgets menu bar doesn't show up - c++

I am trying to create a simple program with a menu using wxWidgets. However, the menu doesn't seem to be appearing properly.
This is my code:
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)
helloworld.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;
}
TextFrame.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;
};
TextFrame.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);
}
This code comes (for the most part) directly from here.
It compiles successfully (using g++ TextFrame.cpp helloworld.cpp `wx-config -cxxflags --libs` -o helloworld), but when I run it I see the default menu, and not the custom one I tried to add.
I tried out the "menu" sample and that works fine, so I think I'm doing something wrong here.
Thank you for your help.

Related

Error with using wxWidgets alongside SFML

This error is with wxWidgets 3.1.5, and SFML 2.5.1
I have the following code:
(main.cpp) :-
#include <SFML/Graphics.hpp>
#include <wx/wx.h>
#include "wxSfmlCanvas.h"
#include "main.h"
TestFrame::TestFrame() :
wxFrame(NULL, wxID_ANY, "SFML 2.5 w/ wxWidgets 3.1", wxDefaultPosition, wxSize(650, 490))
{
mCanvas = new TestSfmlCanvas(this, wxID_ANY, wxPoint(5, 25), wxSize(640, 480));
// Also add a button.
wxButton *button = new wxButton(
this,
wxID_ANY,
wxT("Toggle Size"),
wxPoint(5, 5)
);
button->Bind(wxEVT_BUTTON, [&](wxCommandEvent& arg) -> void {
mCanvas->toggleSize();
});
wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
mainSizer->Add(mCanvas, 6, wxALIGN_TOP | wxEXPAND);
mainSizer->Add(button, 0, wxALIGN_RIGHT | wxALIGN_BOTTOM);
SetSizerAndFit(mainSizer);
}
TestSfmlCanvas::TestSfmlCanvas(
wxWindow* Parent,
wxWindowID Id,
wxPoint& Position,
wxSize& Size,
long Style
) : wxSfmlCanvas(Parent, Id, Position, Size, Style),
mLarge(false)
{
// Load a texture and create a sprite.
mTexture.loadFromFile("data/ball.png");
mSprite = std::make_unique<sf::Sprite>(mTexture);
}
void
TestSfmlCanvas::OnUpdate()
{
clear(sf::Color(64, 196, 196));
draw(*mSprite);
}
void
TestSfmlCanvas::toggleSize()
{
if (mLarge) {
mSprite->setScale(sf::Vector2f(1.2f, 1.2f));
}
else {
mSprite->setScale(sf::Vector2f(0.5f, 0.5f));
}
mLarge = !mLarge;
}
IMPLEMENT_APP(TestApplication);
(and main.h) :-
#pragma once
#include <memory>
#include <SFML/Graphics.hpp>
#include <wx/wx.h>
#include <string>
#include "wxSfmlCanvas.h"
// Our overridden class that does some SFML drawing.
class TestSfmlCanvas : public wxSfmlCanvas
{
public:
TestSfmlCanvas(
wxWindow* Parent,
wxWindowID Id,
wxPoint& Position,
wxSize& Size,
long Style = 0
);
void toggleSize();
protected:
void OnUpdate() override;
private:
sf::Texture mTexture;
std::unique_ptr<sf::Sprite> mSprite;
bool mLarge;
};
// wx Frame to contain the main canvas control. Can have extra controls added to it as desired.
class TestFrame : public wxFrame
{
public :
TestFrame();
protected:
TestSfmlCanvas* mCanvas;
};
// Main wx Application instance.
class TestApplication : public wxApp
{
private :
virtual bool OnInit()
{
// Create the main window
TestFrame* MainFrame = new TestFrame;
MainFrame->Show();
return true;
}
};
(wxSFMLCanvas.h) :-
#pragma once
#include <SFML/Graphics.hpp>
#include <wx/wx.h>
#include <string>
class wxSfmlCanvas : public wxControl, public sf::RenderWindow
{
public:
wxSfmlCanvas(wxWindow* Parent = nullptr,
wxWindowID Id = -1,
//const wxPoint& Position = wxDefaultPosition,
const wxSize& Size = wxDefaultSize,
long Style = 0);
virtual ~wxSfmlCanvas();
protected:
virtual void OnUpdate();
void OnIdle(wxIdleEvent&);
void OnPaint(wxPaintEvent&);
void OnEraseBackground(wxEraseEvent&);
void OnSize(wxSizeEvent&);
DECLARE_EVENT_TABLE()
};
(wxSFMLCanvas.cpp) :-
#include "wxSfmlCanvas.h"
#include <wx/wx.h>
#include <string>
BEGIN_EVENT_TABLE(wxSfmlCanvas, wxControl)
EVT_PAINT(wxSfmlCanvas::OnPaint)
EVT_IDLE(wxSfmlCanvas::OnIdle)
EVT_ERASE_BACKGROUND(wxSfmlCanvas::OnEraseBackground)
EVT_SIZE(wxSfmlCanvas::OnSize)
END_EVENT_TABLE()
#ifdef __WXGTK__
#include <string>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <wx/gtk/win_gtk.h>
#endif
wxSfmlCanvas::wxSfmlCanvas(wxWindow* Parent,
wxWindowID Id,
const wxPoint& Position,
const wxSize& Size,
long Style) :
wxControl(Parent, Id, Position, Size, Style)
{
#ifdef __WXGTK__
#else
sf::RenderWindow::create(GetHandle());
#endif
}
void wxSfmlCanvas::OnIdle(wxIdleEvent&)
{
// Send a paint message when the control is idle, to ensure maximum framerate
Refresh();
}
wxSfmlCanvas::~wxSfmlCanvas()
{
}
void wxSfmlCanvas::OnUpdate()
{
}
void wxSfmlCanvas::OnEraseBackground(wxEraseEvent&)
{
}
void wxSfmlCanvas::OnSize(wxSizeEvent& args)
{
// Set the size of the sfml rendering window
setSize(sf::Vector2u(args.GetSize().x, args.GetSize().y));
// Also adjust the viewport so that a pixel stays 1-to-1.
setView(sf::View(sf::FloatRect(0, 0, args.GetSize().x, args.GetSize().y)));
}
void wxSfmlCanvas::OnPaint(wxPaintEvent&)
{
// Prepare the control to be repainted
wxPaintDC Dc(this);
// Let the derived class do its specific stuff
OnUpdate();
// Display on screen
display();
}
With this code, I get the following compile errors:
Severity Code Description Project File Line Suppression State Error C4996 '_wgetenv': This function or variable may be unsafe. Consider using _wdupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. ae D:\wxwidg\include\wx\wxcrt.h 1050
And 100 similar others.
Why? what did I do wrong for this?
wxWidgets is properly built, SFML and wx work fine on their own, but when combined, this error takes place for some reason.
The messages you show are not errors at all, they are static analyser warnings and can be safely ignored, the "unsafe" functions are not used in unsafe way inside wxWidgets.

wxButton covering entire client area C++

I have made an application using wxWidgets 3.1.5 in C++ and everything is working fine except a test button that I have on my main window.
Here's a pic:
The menubar, menus and their functions work perfectly but the button covers the entire client area.
Here's the code:
main.h
#pragma once
#include <wx\wx.h>
#include "mainFrame.h"
class main : public wxApp
{
private:
mainFrame* frame;
public:
virtual bool OnInit();
};
main.cpp
#include "main.h"
wxIMPLEMENT_APP(main);
bool main::OnInit()
{
frame = new mainFrame("Kill Me", wxPoint(15, 10), wxSize(640, 480));
frame->Show();
return true;
}
mainFrame.h
#pragma once
#include "About.h"
using str = std::string;
class mainFrame : public wxFrame
{
public:
mainFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
~mainFrame();
private:
About* abtF = NULL;
wxButton* hewwo = NULL;
wxMenuBar* mbar = NULL;
wxMenu* sett = NULL;
wxMenu* quitApp = NULL;
wxMenu* abt = NULL;
void onHewwo(wxCommandEvent& evt);
void onSett(wxCommandEvent& evt);
void quit(wxCommandEvent& evt);
void about(wxCommandEvent& evt);
wxDECLARE_EVENT_TABLE();
};
enum {
ID_SETT = 1,
ID_BTN = 2
};
mainFrame.cpp
#include "mainFrame.h"
wxBEGIN_EVENT_TABLE(mainFrame, wxFrame)
EVT_BUTTON(ID_BTN, onHewwo)
EVT_MENU(ID_SETT, onSett)
EVT_MENU(wxID_EXIT, quit)
EVT_MENU(wxID_ABOUT, about)
wxEND_EVENT_TABLE()
mainFrame::mainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
:
wxFrame(nullptr, wxID_ANY, title, pos, size) {
hewwo = new wxButton(this, ID_BTN, "Hewwo World", wxPoint(15, 15), wxSize(70, 20));
sett = new wxMenu();
sett->AppendSeparator();
sett->Append(ID_SETT, "&Settings");
quitApp = new wxMenu();
quitApp->AppendSeparator();
quitApp->Append(wxID_EXIT, "&Quit this crap");
abt = new wxMenu();
abt->AppendSeparator();
abt->Append(wxID_ABOUT, "&About");
mbar = new wxMenuBar();
mbar->Append(sett, "&Settings");
mbar->Append(abt, "&About");
mbar->Append(quitApp, "&Quit");
SetMenuBar(mbar);
}
void mainFrame::onHewwo(wxCommandEvent& evt) {
wxMessageBox("Hewwo", "Hewwo", wxOK | wxICON_INFORMATION, this);
}
void mainFrame::onSett(wxCommandEvent& evt) {
wxMessageBox("Settings", "Settings", wxOK | wxICON_INFORMATION, this); // Just a test
}
void mainFrame::about(wxCommandEvent& evt) {
abtF = new About(wxPoint(10, 10), wxSize(480, 320));
abtF->Show();
}
void mainFrame::quit(wxCommandEvent& evt) {
Close(true);
}
mainFrame::~mainFrame() {
delete abtF;
}
I'm using Visual Studio 2019.
(I followed OneLoneCoder's (javidx9) youtube video on wxWidgets)
That is how a wxFrame with only one child behaves.
If you don't want that, use a wxSizer to layout your button (position, align, expand etc).
Reference:
if the frame has exactly one child window, not counting the status and toolbar, this child is resized to take the entire frame client area. If two or more windows are present, they should be laid out explicitly either by manually handling wxEVT_SIZE or using sizers
wxFrame docs -> Default event processing -> wxEVT_SIZE

Can I use custom color for a specific wx[Aui]Notebook tab

I'm triying to color each tab on wxWidgets with a different color, like when you tag an Excel Sheet, is there a way to do that in the C++ version of wxWidgets, with or without AUI?
I don't think there is anything that will let you do this out of the box; but with an Aui notebook, you can write a custom tab art to color the tabs as you see fit. Here's a hideous example that I just threw together to demonstrate one way to do this:
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/aui/auibook.h>
#include <map>
class MyTabArt:public wxAuiGenericTabArt
{
public:
MyTabArt():wxAuiGenericTabArt(){}
wxAuiTabArt* Clone()
{
return new MyTabArt(*this);
}
void AddTabColor(wxWindow* w, const wxColor& c)
{
m_tabColors[w] = c;
}
virtual void DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page,
const wxRect& rect, int closeButtonState,
wxRect* outTabRect, wxRect* outButtonRect,
int* xExtent) wxOVERRIDE
{
wxSize tabSize = GetTabSize(dc, wnd, page.caption, page.bitmap,
page.active, closeButtonState, xExtent);
wxCoord tabHeight = m_tabCtrlHeight;
wxCoord tabWidth = tabSize.x;
wxCoord tabX = rect.x;
wxCoord tabY = rect.y + rect.height - tabHeight;
wxRect tabRect(tabX, tabY, tabWidth, tabHeight);
wxDCClipper clipper(dc, tabRect);
auto it = m_tabColors.find(page.window);
if ( it != m_tabColors.end() )
{
wxDCBrushChanger bchanger(dc, it->second);
wxDCPenChanger pchanger(dc, it->second);
dc.DrawRectangle(tabRect);
}
else
{
wxDCBrushChanger bchanger(dc, *wxGREEN);
wxDCPenChanger pchanger(dc, *wxGREEN);
dc.DrawRectangle(tabRect);
}
dc.DrawText(page.caption,tabRect.x,tabRect.y);
*outTabRect = tabRect;
}
private:
std::map<wxWindow*,wxColor> m_tabColors;
};
class MyFrame: public wxFrame
{
public:
MyFrame();
private:
};
MyFrame::MyFrame()
:wxFrame(NULL, wxID_ANY, "AUI Tab", wxDefaultPosition, wxSize(600, 400))
{
wxAuiNotebook * auiNotebook =
new wxAuiNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
wxPanel* panel1 = new wxPanel( auiNotebook, wxID_ANY );
wxPanel* panel2 = new wxPanel( auiNotebook, wxID_ANY );
auiNotebook->AddPage(panel1, "Page 1");
auiNotebook->AddPage(panel2, "Page 2");
MyTabArt* art = new MyTabArt();
art->AddTabColor(panel1, *wxRED);
art->AddTabColor(panel2, *wxBLUE);
auiNotebook->SetArtProvider(art);
}
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
::wxInitAllImageHandlers();
MyFrame* frame = new MyFrame();
frame->Show();
return true;
}
};
wxIMPLEMENT_APP(MyApp);
On windows, this monstrosity looks like this:
You can look at the source wxWidgets source for the other tab arts to see an example of how to make this prettier.

wxTextCtrl not aligning to center - wxSizerFlags not working in wxWidget

This code displays a single textbox and a button. When the user clicks the button, the window exits, however I want to put the textControl to the center of the window but it's not working. Here's my code:
// base.h
#ifndef base_h_
#define base_h_
#include <wx/app.h>
#include <wx/button.h>
#include <wx/string.h>
#include <wx/frame.h>
#include <wx/gdicmn.h>
#include <wx/sizer.h>
#include <wx/panel.h>
class MainApp : public wxApp {
public:
virtual bool OnInit();
};
class MainFrame: public wxFrame {
public:
MainFrame( const
wxString& title, const wxPoint& pos, const wxSize& size );
wxBoxSizer *sizer;
void OnExit(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
#endif
// base.cpp
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "base.h"
IMPLEMENT_APP(MainApp)
bool MainApp::OnInit() {
MainFrame *MainWin = new MainFrame(_T("gui"), wxDefaultPosition, wxSize(5000, 5000));
MainWin->Show(TRUE);
SetTopWindow(MainWin);
return TRUE;
}
BEGIN_EVENT_TABLE ( MainFrame, wxFrame)
EVT_BUTTON ( 3, MainFrame::OnExit )
END_EVENT_TABLE()
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size): wxFrame((wxFrame*)NULL,- 1, title, pos, size) {
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxPanel *panel = new wxPanel(this, wxID_ANY, wxPoint(0, 0));
sizer->Add(new wxTextCtrl(panel , 1, ""), wxSizerFlags().Center());
sizer->SetSizeHints(this);
SetSizer(sizer);
}
void MainFrame::OnExit( wxCommandEvent& event) {
Close(TRUE);
}
I don't know what I'm doing wrong here, shouldn't wxSizerFlags().Center do exactly what I want?
Your text control is wrapped inside a wxPanel. You add the text control to the sizer and set the sizer to the frame. This won't work and may even cause errors. You need to create two sizers, one for the panel and one for the frame. You have several options: You can have the panel expand to the size of the frame and have the text ctrl placed in the center of the panel, or you can center the panel and have the text ctrl expand to the size of the panel. Here's some code for the first option:
wxPanel* panel = new wxPanel(this, wxID_ANY);
wxTextCtrl* text = new wxTextCtrl(panel, 1, "");
wxBoxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
panelSizer->Add(text, wxSizerFlags().Center());
panel->SetSizer(panelSizer);
wxBoxSizer* frameSizer = new wxBoxSizer(wxVERTICAL);
frameSizer->Add(panel, wxSizerFlags().Expand());
SetSizer(frameSizer);
Note that I'm not familiar with wxSizerFlags, but I suppose that it should work like this. You may also have to set a size for the panel explicitly - right now it will use some default size.

WxWidgets - Changing texbox from a file other than the main one

NOTE: I completely revised the question and turned it into an example project specifically for this question, so Nicks answer doesn't really make sense anymore. wxQuestionMain.h and wxQuestionMain.cpp are mildly modified wxWidget files, auto generated by Code::Blocks.
When I click the "Go" button I want the button event in "wxQuestionMain.cpp" to call "somefunction()" which is inside "otherFile.cpp". That works just fine. But I then want to change the text in the textbox "txtCtrl1" from inside "somefunction()" and that won't work because "somefunction()" is not part of the wxWidget class, and I don't want it to be. The wxwidget class is created in "wxQuestionMain.h".
wxQuestionMain.h -> Just creates the class
#ifndef WXQUESTIONMAIN_H
#define WXQUESTIONMAIN_H
#define BOOST_FILESYSTEM_VERSION 2
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "wxQuestionApp.h"
#include <wx/button.h>
#include <wx/statline.h>
class wxQuestionDialog: public wxDialog
{
public:
wxQuestionDialog(wxDialog *dlg, const wxString& title);
~wxQuestionDialog();
protected:
enum
{
idBtnGo = 1000
};
wxStaticText* m_staticText1;
wxStaticLine* m_staticline1;
wxButton* BtnGo;
wxTextCtrl* textCtrl1;
private:
void OnClose(wxCloseEvent& event);
void OnGo(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
void somefunction();
#endif // WXQUESTIONMAIN_H
wxQuestionMain.cpp -> Lots of yadda yadda and then at the very bottom the function that handles the buttonclick event.
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#include "wxQuestionMain.h"
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__WXMAC__)
wxbuild << _T("-Mac");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
BEGIN_EVENT_TABLE(wxQuestionDialog, wxDialog)
EVT_CLOSE(wxQuestionDialog::OnClose)
EVT_BUTTON(idBtnGo, wxQuestionDialog::OnGo)
END_EVENT_TABLE()
wxQuestionDialog::wxQuestionDialog(wxDialog *dlg, const wxString &title)
: wxDialog(dlg, -1, title)
{
this->SetSizeHints(wxDefaultSize, wxDefaultSize);
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer(wxHORIZONTAL);
m_staticText1 = new wxStaticText(this, wxID_ANY, wxT("Welcome To\nwxWidgets"), wxDefaultPosition, wxDefaultSize, 0);
m_staticText1->SetFont(wxFont(20, 74, 90, 90, false, wxT("Arial")));
bSizer1->Add(m_staticText1, 0, wxALL|wxEXPAND, 5);
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer(wxVERTICAL);
wxPoint textCtrl1Position(5,5); //Position
wxSize textCtrl1size(120,25); //Size
textCtrl1 = new wxTextCtrl(this, wxID_ANY, "hi", wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, "textCtrl1"); //Create textCtrl
bSizer2->Add(textCtrl1, 0, wxALL|wxEXPAND, 5); //Add to sizer
m_staticline1 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
bSizer2->Add(m_staticline1, 0, wxALL|wxEXPAND, 5);
BtnGo = new wxButton(this, idBtnGo, wxT("&Go"), wxDefaultPosition, wxDefaultSize, 0);
bSizer2->Add(BtnGo, 0, wxALL, 5);
bSizer1->Add(bSizer2, 1, wxEXPAND, 5);
this->SetSizer(bSizer1);
this->Layout();
bSizer1->Fit(this);
}
wxQuestionDialog::~wxQuestionDialog()
{
}
void wxQuestionDialog::OnClose(wxCloseEvent &event)
{
Destroy();
}
void wxQuestionDialog::OnGo(wxCommandEvent &event)
{
somefunction();
}
otherFile.cpp:
#include "wxQuestionMain.h"
void somefunction()
{
//Try to change the text in textCtrl1
wxQuestionDialog::textCtrl1->AppendText("Red text\n");
}
Produces:
error: ‘wxTextCtrl* wxQuestionDialog::textCtrl1’ is protected
error: invalid use of non-static data member ‘wxQuestionDialog::textCtrl1’
So I moved 'wxTextCtrl* textCtrl1;' in 'wxQuestionMain.h' from 'protected' to 'public'
Produces:
error: invalid use of non-static data member ‘wxQuestionDialog::textCtrl1’
The class in wxQuestionMain.h seems to sais 'class wxQuestionDialog: public wxDialog'
I don't know what that "public" part means, I've never seen a class be created like that before, but I'm going to try to change 'otherFile.cpp' so it sais wxDialog instead of wxQuestionDialog.
#include "wxQuestionMain.h"
void somefunction()
{
//Try to change the text in textCtrl1
wxDialog::textCtrl1->AppendText("Red text\n");
}
Produces:
error: ‘textCtrl1’ is not a member of ‘wxDialog’
I'm at a loss here.. how can I update the text in "textCtrl1" without adding "somefunction()" to the wxWidget class?
CodeBlocks auto generated 2 other files, not sure if they are important, but here they are.
wxQuestionApp.cpp
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#include "wxQuestionApp.h"
#include "wxQuestionMain.h"
IMPLEMENT_APP(wxQuestionApp);
bool wxQuestionApp::OnInit()
{
wxQuestionDialog* dlg = new wxQuestionDialog(0L, _("wxWidgets Application Template"));
dlg->Show();
return true;
}
wxQuestionApp.h
#ifndef WXQUESTIONAPP_H
#define WXQUESTIONAPP_H
#include <wx/app.h>
class wxQuestionApp : public wxApp
{
public:
virtual bool OnInit();
};
#endif // WXQUESTIONAPP_H
addtolistbox2 is a private member method of gfxDialog - even if you did have a properly constructed object, you wouldn't be able to call that method from outside a gfxDialog instance. At the very least you need to move addtolistbox2 to public: from private:, and then call it on a properly constructed instance (the constructor requires arguments but your code doesn't provide them):
gfxDialog testtime(0, "test");
testtime.addtolistbox2("somestring");
(The only valid constructor requires a parent dialog and a title string:
class gfxDialog: public wxDialog
{
public:
gfxDialog(wxDialog *dlg, const wxString& title);
if I remember my wxWidgets properly, the parent may be NULL, but of course you still have to provide the argument)