How to Display a New Form

Post here wxCrafter related issues / features / bugs
User avatar
ColleenKobe
CodeLite Expert
Posts: 129
Joined: Wed Mar 30, 2016 4:31 pm
Genuine User: Yes
IDE Question: C++
Contact:

How to Display a New Form

Post by ColleenKobe »

I am a beginning wxWidgets/CodeLite/wxCrafter/C++ programmer.

I'm writing a program to display two forms. One is called Main, and the other is called Page_1. On execution, the program starts by displaying Main. When the user clicks the button, the display will show Page_1. Then the user clicks a button on Page_1 and the program displays Main again. Main, Page_1, Main, Page_1. Back and forth. Really simple.

My problem is that I cannot get my program to compile because I don't understand the syntax required in the main program to display Page_1. Does a new Page_1 need to be instantiated inside Main, in order to call the Main method to display the page? Why do my commands to instantiate Page_1 fail?

I'm not asking for anyone to write code for me. I could work from an example, if someone can send me a link. To try to figure this out, I've visited https://wiki.wxwidgets.org/Guides_%26_Tutorials, but these tutorials seem to be focused on building ONE page. Not jumping back and forth between pages. And I've visited http://svn.wxwidgets.org/viewvc/wx/wxWi ... s/display/, but I have no idea what to do when I look at that page. If it's not a CodeLite workspace file, I don't know what to do with it to compile and run it.

Here is what the two pages are supposed to look like.
Both Pages.jpg
Here is MainFrame.cpp. Note the comments at the very end, showing my different attempts to call the method and the different error messages I got.

Code: Select all

#include <wx/aboutdlg.h>
#include <wx/msgdlg.h>
#include "MainFrame.h"
#include "Page_1_Class.h"


MainFrame::MainFrame(wxWindow* parent)
    : MainFrameBaseClass(parent)
{
}

MainFrame::~MainFrame()
{
}

void MainFrame::OnExit(wxCommandEvent& event)
{
    wxUnusedVar(event);
    Close();
}

void MainFrame::OnAbout(wxCommandEvent& event)
{
    wxUnusedVar(event);
    wxAboutDialogInfo info;
    info.SetCopyright(_("My MainFrame"));
    info.SetLicence(_("GPL v2 or later"));
    info.SetDescription(_("Short description goes here"));
    ::wxAboutBox(info);
}
void MainFrame::OnGotopage1_buttonButtonClicked(wxCommandEvent& event)
{
    wxString a_st = "";

    a_st = wxT("About to display Page 1...");
    wxMessageBox(a_st, wxT("Navigating"), wxICON_NONE);

    // How do I execute Build_Page_1?  It resides in Page_1_Class.cpp.
    // Here are my attempts and the error messages I've received.

    // Page_1_BaseClass P1 = new(Page_1_BaseClass); // no matching function for call to 'Page_1_BaseClass::Page_1_BaseClass()'
    // Page_1_Class P1 = new(Page_1_Class);         // no matching function for call to 'Page_1_Class::Page_1_Class()'
    // Build_Page_1 P1 = new(Build_Page_1);         // FAIL: 'Build Page 1' was not declared in this scope

    // Build_Page_1();                              // 'Build_Page_1' was not declared in this scope

}
Here is Page_1_Class.cpp.

Code: Select all

// -----------------------------------------------------------------------------
// Page_1_Class.cpp
// -----------------------------------------------------------------------------

#include <wx/msgdlg.h>
#include "Page_1_Class.h"

Page_1_Class::Page_1_Class(wxWindow* parent)
    : Page_1_BaseClass(parent)
{
}

Page_1_Class::~Page_1_Class()
{
}

void Page_1_Class::Build_Page_1(void)
{
    wxString a_st = "";

    a_st = wxT("Inside Build_Page_1!");
    wxMessageBox(a_st, wxT("Made it!"), wxICON_HAND);

}

void Page_1_Class::OnGotomainButtonClicked(wxCommandEvent& event)
{

    // What do I put here to return to the main page?

}
And here is Page_1_Class.h.

Code: Select all

#ifndef PAGE_1_CLASS_H
#define PAGE_1_CLASS_H
#include "wxcrafter.h"

class Page_1_Class : public Page_1_BaseClass
{
public:
    Page_1_Class(wxWindow* parent);
    virtual ~Page_1_Class();

    virtual void Build_Page_1(void);

protected:
    virtual void OnGotomainButtonClicked(wxCommandEvent& event);
};
#endif // PAGE_1_CLASS_H

Can someone please tell me what I'm doing wrong? Or better, give me a link where I can see an example of how this is done?

Thank you in advance!

Colleen

------------------
Software Versions:
------------------
CodeLite: 9.1.5
tdm-gcc: 5.1.0.3
Windows 7: 6.1
wxCrafter: 2.5
wxWidgets: 3.1.0

Target platform: 32-bit
Target build: debug
You do not have the required permissions to view the files attached to this post.
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: How to Display a New Form

Post by DavidGH »

Hi,

IIUC this again isn't really a wxCrafter issue; wxForum would have been a better place to ask. However:

1) You're doing something slightly unusual. Is this just practice code, and when you write for real you'll actually use wxWizard?

If this is real code though, have a look at wxSimplebook. If for some reason you don't want to use that, consider creating both pages in the frame ctor, and hiding page 1 (P1->Show(false)). Then when you want to switch, hide main and show page 1.

I just glanced quickly at your code, but one obvious issue is: Build_Page_1 P1 = new(Build_Page_1);
As you'll know from your C++ studies, 'new' returns a pointer. So you need to do something like:
Build_Page_1* P1 = new Build_Page_1(this);

2) Please have a good look at the many samples that come with the wx source. Those, rather than tutorials, should always be your second port of call (after the documentation). They have the enormous advantage of being up to date and are far more likely to be bug-free. They also come with makefiles or the equivalent so you can build and run them outside CodeLite.

Regards,

David
User avatar
ColleenKobe
CodeLite Expert
Posts: 129
Joined: Wed Mar 30, 2016 4:31 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: How to Display a New Form

Post by ColleenKobe »

Thank you for answering my question, DavidGH.
DavidGH wrote: IIUC this again isn't really a wxCrafter issue; wxForum would have been a better place to ask. However:
So sorry! I am new to wxWidgets, wxCrafter, CodeLite, and C++. I don't know where one ends and the next one begins. They're one big environment to me.
DavidGH wrote: 1) You're doing something slightly unusual. Is this just practice code, and when you write for real you'll actually use wxWizard?
Yes, this is practice code.

I tried wxWizard once, and it seemed like a tool to MAKE a wizard--if a wizard is a program that is a string of pages, "steered" using Back/Next/Exit keys, starting on page 1 and ending on the last page. Page progression is a straight line. Like a string of pearls.

But that's not what I want to do. I have a main page, and the user can click controls to go to other pages, but it's usually only 2 or 3 steps out. Then control returns to the main page. The program exits from the main page. Page progression is advance, return, advance, return. Like the petals of a flower.

The example I gave was to explore the first petal. So no, I won't be using wxWizard.
DavidGH wrote: If this is real code though, have a look at wxSimplebook. If for some reason you don't want to use that, consider creating both pages in the frame ctor, and hiding page 1 (P1->Show(false)). Then when you want to switch, hide main and show page 1.
I looked at wxSimplebook, and it seems like a great idea for reading a novel or something. But my application isn't quite right for it.

I am interested in your suggestion for "creating both pages in the frame ctor, and hiding page 1 (P1->Show(false)). Then when you want to switch, hide main and show page 1.". But what is "frame ctor"?
DavidGH wrote: I just glanced quickly at your code, but one obvious issue is: Build_Page_1 P1 = new(Build_Page_1);
As you'll know from your C++ studies, 'new' returns a pointer. So you need to do something like:
Build_Page_1* P1 = new Build_Page_1(this);
OMG, I can't believe I missed that. THANK YOU!!!
DavidGH wrote: 2) Please have a good look at the many samples that come with the wx source. Those, rather than tutorials, should always be your second port of call (after the documentation). They have the enormous advantage of being up to date and are far more likely to be bug-free. They also come with makefiles or the equivalent so you can build and run them outside CodeLite.
I actually have looked at this code before. I need to be able to see the code and run the code to understand it. But since I'm using Windows/CodeLite, I don't know how to compile and run the code outside CodeLite. I wish the examples had come with instructions, or perhaps the executable itself. I'll see if I can find instructions to compile and run it.

Thank you!!! I appreciate your time and knowledge.

Colleen
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: How to Display a New Form

Post by DavidGH »

I looked at wxSimplebook, and it seems like a great idea for reading a novel or something. But my application isn't quite right for it.
I don't think you're necessarily right, but it's only practice so...
But what is "frame ctor"?
'ctor' is the common abbreviation for 'constructor'. In this case it's:

Code: Select all

MainFrame::MainFrame(wxWindow* parent)
    : MainFrameBaseClass(parent)
{
}
Post Reply