7 Replies - 781 Views - Last Post: 29 January 2014 - 01:50 PM Rate Topic: -----

#1 Admiral Awesome  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 09-September 13

very basic help needed with wxWidgets

Posted 28 January 2014 - 04:53 PM

First I want to establish that I'm not in any way trying to get anyone to do my homework for me. I'm not sure if I'm just missing something very obvious or I'm just terrible at reading code. Also I wasn't 100% sure where to put this question, but it's for a intro C++ course so I assumed here was best.

Last week the professor walked us through creating a default frame in codeblocks, which is just a couple of prompts and it creates everything for the window on it's own. So for the weekend he gave us an assignment to modify the window, and I have no idea what any of it means. He didn't go over any of the code; it was more like him handing us code and telling us not to worry how it works, but now he gives us these very vague instructions to modify it the next class. This is the link to the assignment: http://web.eng.fiu.e...gOfWeek/PW3.pdf

It explains nothing of what the changes really effect in the code, only a very minor description of what it changes in the outcome. There are two links at the bottom, that I bet would be helpful if they actually worked, instead the wxWidgets site says they're dead links, and when instead I look for wxTextCtrl in the A-Z reference index, I get some highly confusing page that seems like it's only for people who at least somewhat know what they're doing. Here's the page though: http://docs.wxwidget...html#wxtextctrl

Any tips, links to a page I might have missed, or anything else would be helpful. I have some bookmarked pages of wxWidgets tutorials in hopes of familiarizing myself with it so I don't have to be in this situation again, but I doubt I have time to read the whole thing, so I'm putting this question down as some auxiliary help.

To be more descriptive of what exactly I'm having issues with, is he says to just slap those codes he gives, but I don't know where. The first piece is a pointer, I know what that is so I threw it in the only block in the exEditormain.h file (I will post the .h and .ccp files at the bottom). That seemed to build fine, I tried putting the ID_Textbox into the enum block right after the other statements that started with id_ and I get an error about expecting a "unqualified id" (error pane will be linked below the code). Even though I was already having issues, so it was useless, I put the last line of code which would initialize the pointer(it's a pointer, but how is it constructing a pointer with the new command?) inside the "wxEditorFrame::~wxEditorFrame()" thing... I'm not sure what this is, it looks like simply a namespace.

Here is the code for wxEditorMain.cpp and wxEditorMain.h respectively, and the errors afterwards (the changes I made as mentioned above are omitted). I'm sorry if this is an inappropriate question to ask but I ran out of ideas of how to do this assignment, I thank you for any and all feedback.


#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "wxEditorMain.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(wxEditorFrame, wxFrame)
    EVT_CLOSE(wxEditorFrame::OnClose)
    EVT_MENU(idMenuQuit, wxEditorFrame::OnQuit)
    EVT_MENU(idMenuAbout, wxEditorFrame::OnAbout)
END_EVENT_TABLE()

wxEditorFrame::wxEditorFrame(wxFrame *frame, const wxString& title)
    : wxFrame(frame, -1, title)
{
#if wxUSE_MENUS
    // create a menu bar
    wxMenuBar* mbar = new wxMenuBar();
    wxMenu* fileMenu = new wxMenu(_T(""));
    fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));
    mbar->Append(fileMenu, _("&File"));

    wxMenu* helpMenu = new wxMenu(_T(""));
    helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
    mbar->Append(helpMenu, _("&Help"));

    SetMenuBar(mbar);
#endif // wxUSE_MENUS

#if wxUSE_STATUSBAR
    // create a status bar with some information about the used wxWidgets version
    CreateStatusBar(2);
    SetStatusText(_("Hello Code::Blocks user!"),0);
    SetStatusText(wxbuildinfo(short_f), 1);
#endif // wxUSE_STATUSBAR

}


wxEditorFrame::~wxEditorFrame()
{

}

void wxEditorFrame::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void wxEditorFrame::OnQuit(wxCommandEvent &event)
{
    Destroy();
}

void wxEditorFrame::OnAbout(wxCommandEvent &event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}



#ifndef WXEDITORMAIN_H
#define WXEDITORMAIN_H

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "wxEditorApp.h"

class wxEditorFrame: public wxFrame
{
    wxTextCtrl* textControl;

    public:
        wxEditorFrame(wxFrame *frame, const wxString& title);
        ~wxEditorFrame();
    private:
        enum
        {
            idMenuQuit = 1000,
            idMenuAbout
            




        };

        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        DECLARE_EVENT_TABLE()
};


#endif // WXEDITORMAIN_H



||=== Build: Release in wxEditor (compiler: GNU GCC Compiler) ===|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|31|error: expected '}' before 'ID_TextBox'|
C:\wxWidgets-3.0.0\include\wx\event.h|3985|error: expected unqualified-id before 'private'|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\wxWidgets-3.0.0\include\wx\event.h|3987|error: expected unqualified-id before 'protected'|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\wxWidgets-3.0.0\include\wx\event.h|3989|error: 'virtual' outside class declaration|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\wxWidgets-3.0.0\include\wx\event.h|3989|error: non-member function 'const wxEventTable* GetEventTable()' cannot have cv-qualifier|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\wxWidgets-3.0.0\include\wx\event.h|3990|error: no matching function for call to 'wxEventHashTable::wxEventHashTable()'|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\wxWidgets-3.0.0\include\wx\event.h|3990|note: candidates are:|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\wxWidgets-3.0.0\include\wx\event.h|3305|note: wxEventHashTable::wxEventHashTable(const wxEventHashTable&)|
C:\wxWidgets-3.0.0\include\wx\defs.h|3464|note: in definition of macro 'wxDECLARE_NO_COPY_CLASS'|
C:\wxWidgets-3.0.0\include\wx\event.h|3305|note: candidate expects 1 argument, 0 provided|
C:\wxWidgets-3.0.0\include\wx\defs.h|3464|note: in definition of macro 'wxDECLARE_NO_COPY_CLASS'|
C:\wxWidgets-3.0.0\include\wx\event.h|3266|note: wxEventHashTable::wxEventHashTable(const wxEventTable&)|
C:\wxWidgets-3.0.0\include\wx\event.h|3266|note: candidate expects 1 argument, 0 provided|
C:\wxWidgets-3.0.0\include\wx\event.h|3991|error: 'virtual' outside class declaration|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\wxWidgets-3.0.0\include\wx\event.h|3991|error: non-member function 'wxEventHashTable& GetEventHashTable()' cannot have cv-qualifier|
C:\wxWidgets-3.0.0\include\wx\event.h|4451|note: in expansion of macro 'wxDECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|41|note: in expansion of macro 'DECLARE_EVENT_TABLE'|
C:\Users\David\Documents\CodeBlocks\wxEditor\wxEditorMain.h|42|error: expected declaration before '}' token|
||=== Build failed: 9 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|

Is This A Good Question/Topic? 0
  • +

Replies To: very basic help needed with wxWidgets

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1398
  • View blog
  • Posts: 4,873
  • Joined: 19-February 09

Re: very basic help needed with wxWidgets

Posted 28 January 2014 - 06:03 PM

Hi, the enum type uses a comma separated list, so it is likely you missed out the comma.

Controls is a term used for edit boxes, buttons, list boxes etc.

#ifndef WXEDITORMAIN_H
#define WXEDITORMAIN_H

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "wxEditorApp.h"

class wxEditorFrame: public wxFrame
{
    // textControl is a pointer to a wxTextCtrl object (if and when the object it exists)
    wxTextCtrl* textControl; 
    public:
        wxEditorFrame(wxFrame *frame, const wxString& title);
        ~wxEditorFrame();
    private:
        enum
        {
            idMenuQuit = 1000,
            idMenuAbout, //<- comma
            ID_TextBox
        };

        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        DECLARE_EVENT_TABLE()
};


#endif // WXEDITORMAIN_H



You have added a text control pointer in the class. In the constructor you create the instance/object by using the new operator. The new function/statement creates the object dynamically - while the program is running, allocating space in memory.

Functions starting with the tilde ~, are destructors, you are not using that yet.

If you need more help just ask.
Was This Post Helpful? 1
  • +
  • -

#3 Admiral Awesome  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 09-September 13

Re: very basic help needed with wxWidgets

Posted 28 January 2014 - 06:57 PM

View Post#define, on 28 January 2014 - 06:03 PM, said:

Hi, the enum type uses a comma separated list, so it is likely you missed out the comma.

Controls is a term used for edit boxes, buttons, list boxes etc.


You have added a text control pointer in the class. In the constructor you create the instance/object by using the new operator. The new function/statement creates the object dynamically - while the program is running, allocating space in memory.

Functions starting with the tilde ~, are destructors, you are not using that yet.

If you need more help just ask.


Thank you so much for the help. The teacher is instructing, in what I believe to be a ineffective manner, with a system of starting from the ground up with very basic c++ syntax in console, and at the same time, tearing down from top to bottom with advanced features features for application practice in wxWidgets applications; he went on about meeting somewhere in the middle with both syntax and application by the end of the semester. The prereq for this class is a intro to C with only covers procedural programming, but because of that I know the basics of things like pointers, arrays and structs, but in the class, we haven't even gone over how to create classes or objects, let alone learn that pointers can point to objects as well. It's pretty frustrating trying to figure some things out, when you're left in the dark about everything else. So I really am thankful for the help, and hope I'll be able to manage without having to resort to asking such elementary questions in the future.

One last question now that I can examine this code a little better is: Where is the main function? Since day 1 we're taught that programs start with the main function, but looking at the assignment I eventually found out to put the constructor in the wxEditorFrame::wxEditorFrame(wxFrame *frame, const wxString& title)
: wxFrame(frame, -1, title)
function, which isn't called main, as neither are the others. I only found out I needed that function because I finally realized that's where the menu bars are created, and the assignment notes "Note that ID_TextBox is used in the constructor. Where is the instance placed? Inside the Frame
constructor in wxEditorMain.cpp after the menu and status bars are created."

once again, thanks for the help.
Was This Post Helpful? 0
  • +
  • -

#4 coder5023  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-January 14

Re: very basic help needed with wxWidgets

Posted 28 January 2014 - 07:54 PM

im in the same class with the same problem, only thing is my main code looks different than yours.

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "wxEditorMain.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(wxEditorDialog, wxDialog)
    EVT_CLOSE(wxEditorDialog::OnClose)
    EVT_BUTTON(idBtnQuit, wxEditorDialog::OnQuit)
    EVT_BUTTON(idBtnAbout, wxEditorDialog::OnAbout)
END_EVENT_TABLE()

wxEditorDialog::wxEditorDialog(wxDialog *dlg, const wxString &title)
    : wxDialog(dlg, -1, title)





{
    textControl = new wxTextCtrl(this, ID_TextBox,
 wxT(""), wxDefaultPosition, wxDefaultSize,
 wxTE_MULTILINE | wxTE_RICH , wxDefaultValidator, wxTextCtrlNameStr);
    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);
    BtnAbout = new wxButton(this, idBtnAbout, wxT("&About"), wxDefaultPosition, wxDefaultSize, 0);
    bSizer2->Add(BtnAbout, 0, wxALL, 5);
    m_staticline1 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
    bSizer2->Add(m_staticline1, 0, wxALL|wxEXPAND, 5);
    BtnQuit = new wxButton(this, idBtnQuit, wxT("&Quit"), wxDefaultPosition, wxDefaultSize, 0);
    bSizer2->Add(BtnQuit, 0, wxALL, 5);
    bSizer1->Add(bSizer2, 1, wxEXPAND, 5);
    this->SetSizer(bSizer1);
    this->Layout();
    bSizer1->Fit(this);
}






wxEditorDialog::~wxEditorDialog()
{
}

void wxEditorDialog::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void wxEditorDialog::OnQuit(wxCommandEvent &event)
{
    Destroy();
}

void wxEditorDialog::OnAbout(wxCommandEvent &event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}




let me know if you figure it out im lost were to put the text box, this professor is a idiot
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1398
  • View blog
  • Posts: 4,873
  • Joined: 19-February 09

Re: very basic help needed with wxWidgets

Posted 28 January 2014 - 07:58 PM

Hi. The main function is probably hidden, notice BEGIN_EVENT_TABLE is passed the name of your wxFrame class.
The main function is the entry function for a program, ie where it starts, with console programs it is usually called main. When using Windows API it is usually called WinMain and has different parameters.

A windows type program (in a GUI or WIMP environment) appears to work differently from a console program. A console program would work in a non GUI OS. A windows type program runs within a windows OS, the windows OS captures events, such as mouse events and keyboard events, and passes the event data to your program, and the program reacts to these events. To do this a function's address is passed to windows so that windows can call the program back, it is called a callback function. This is generally hidden in wxWidgets and other GUI libraries.

A constructor is a function, which is a member of a class and has the same name as the class. The constructor function is called when a class object is created.

This is a class constructor function:

wxEditorFrame(wxFrame *frame, const wxString& title);



Here is a C++ tutorial. There are other tutorials.

C++ Language

You don't have to know and remember everything, but a general idea of, what is what, is useful. Maybe just a quick look or speed read through a tutorial or the sections on classes would help.
.

This post has been edited by #define: 28 January 2014 - 08:14 PM

Was This Post Helpful? 0
  • +
  • -

#6 coder5023  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-January 14

Re: very basic help needed with wxWidgets

Posted 28 January 2014 - 08:51 PM

dude its super easy i just figured it out
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "project01Main.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(project01Frame, wxFrame)
    EVT_CLOSE(project01Frame::OnClose)
    EVT_MENU(idMenuQuit, project01Frame::OnQuit)
    EVT_MENU(idMenuAbout, project01Frame::OnAbout)
END_EVENT_TABLE()

project01Frame::project01Frame(wxFrame *frame, const wxString& title)
    : wxFrame(frame, -1, title)
{
#if wxUSE_MENUS
    // create a menu bar
    wxMenuBar* mbar = new wxMenuBar();
    wxMenu* fileMenu = new wxMenu(_T(""));
    fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));
    mbar->Append(fileMenu, _("&File"));

    wxMenu* helpMenu = new wxMenu(_T(""));
    helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
    mbar->Append(helpMenu, _("&Help"));

    SetMenuBar(mbar);
#endif // wxUSE_MENUS

#if wxUSE_STATUSBAR
    // create a status bar with some information about the used wxWidgets version
    CreateStatusBar(2);
    SetStatusText(_("Hello Code::Blocks user!"),0);
    SetStatusText(wxbuildinfo(short_f), 1);
#endif // wxUSE_STATUSBAR

 textControl = new wxTextCtrl(this, ID_TextBox,
 wxT(""), wxDefaultPosition, wxDefaultSize,
 wxTE_MULTILINE | wxTE_RICH , wxDefaultValidator, wxTextCtrlNameStr);


}


project01Frame::~project01Frame()
{
}

void project01Frame::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void project01Frame::OnQuit(wxCommandEvent &event)
{
    Destroy();
}

void project01Frame::OnAbout(wxCommandEvent &event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}




#ifndef PROJECT01MAIN_H
#define PROJECT01MAIN_H

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "project01App.h"

class project01Frame: public wxFrame
{
    public:
        project01Frame(wxFrame *frame, const wxString& title);
        ~project01Frame();
        wxTextCtrl* textControl;

    private:
        enum
        {
            idMenuQuit = 1000,
            idMenuAbout,
            ID_TextBox


        };
        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        DECLARE_EVENT_TABLE()
};


#endif // PROJECT01MAIN_H


Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3652
  • View blog
  • Posts: 11,421
  • Joined: 05-May 12

Re: very basic help needed with wxWidgets

Posted 28 January 2014 - 09:10 PM

coder5023: I really appreciate your enthusiasm to share your success. One of the premises of this website is to provide a forum for teaching. We don't just dump code on somebody else. We explain what we did so that some learning can happen. I'm looking forward to your future participation because it looks like you have more to contribute to the community!
Was This Post Helpful? 2
  • +
  • -

#8 Admiral Awesome  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 09-September 13

Re: very basic help needed with wxWidgets

Posted 29 January 2014 - 01:50 PM

Ah thanks, I already had it figured out with #define's first post, I was just asking more questions to better understand what I was actually working with. It's complicated but I think I got a good direction now, thank you for the link to the tutorial as well, it will undoubtedly be helpful.

Should I change the thread title to say solved or something like that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1