How to Change the Forms Displayed in wxWidgets Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

How to Change the Forms Displayed in wxWidgets

Post by ColleenKobe »

I am using CodeLite and creating wxWidgets programs, with wxCrafter as my GUI generator. I am a beginner with all three software packages.

I'm creating a test program to learn how to create pages and change the focus from one to the other. Each page contains a "Next" button and a "Prev" button. The state diagram is:

Code: Select all

On              Clicking          Displays or changes the focus to
Page 1        Prev                Page 3
Page 1        Next                Page 2
Page 2        Prev                Page 1
Page 2        Next                Page 3
Page 3        Prev                Page 2
Page 3        Next                Page 1
I created the first class, and then used CodeLite's duplicate function to create pages 2 and 3. I tweaked Pages 2 and 3 appropriately. Then I had CodeLite generate event handler code to handle the button click events for me.

But now I'm at a loss: I don't know what the syntax for displaying a wxWidgets form is.

Here is my MainFrame.cpp (aka Page_1) file:

Code: Select all

#include "MainFrame.h"
#include "page_2.h"
#include "page_3.h"

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

MainFrame::~MainFrame()
{
}

void MainFrame::OnAbout(wxCommandEvent& event)
{
}
void MainFrame::OnExit(wxCommandEvent& event)
{
}
void MainFrame::OnP1_button_gotopage2ButtonClicked(wxCommandEvent& event)
{
    bool rc = false;
    rc = Page_2.Show(true);
    rc = Page_2_Class.Show(true);
}
void MainFrame::OnP1_button_gotopage3ButtonClicked(wxCommandEvent& event)
{
}
void MainFrame::OnP1_exitButtonClicked(wxCommandEvent& event)
{
}
In OnP1_button_gotopage2ButtonClicked, the compiler displayed the same error message for both lines: "expected primary-expression before '.' token". What is a primary expression?

Here is page_2.cpp.

Code: Select all

#include "page_2.h"
#include "MainFrame.h"
#include "page_3.h"

Page_2::Page_2(wxWindow* parent)
    : Page_2_Class(parent)
{
}

Page_2::~Page_2()
{
}

void Page_2::OnP2_button_gotopage1ButtonClicked(wxCommandEvent& event)
{
}
void Page_2::OnP2_button_gotopage3ButtonClicked(wxCommandEvent& event)
{
}
And here is page_3.cpp:

Code: Select all

#include "page_3.h"

Page_3::Page_3(wxWindow* parent)
    : Page_3_Class(parent)
{
}

Page_3::~Page_3()
{
}

void Page_3::OnP3_button_gotopage1ButtonClicked(wxCommandEvent& event)
{
}
void Page_3::OnP3_button_gotopage2ButtonClicked(wxCommandEvent& event)
{
}
I'm not asking anyone to write code for me. I just would like an example or directions for how to change pages.

Thanks!

Software Versions:
------------------
CodeLite = 9.1.5
tdm-gcc = 5.1.0.3
Windows 7 = 6.1
wxWidgets = 3.1.0
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to Change the Forms Displayed in wxWidgets

Post by doublemax »

Do you want to do this as a learning exercise or do you just want to solve that particular task as easy as possible?

In the latter case check one of the "book control" classes. In your case wxSimpleBook might be exactly what you need:
http://docs.wxwidgets.org/trunk/classwx_simplebook.html

It already has a method wxBookCtrlBase::AdvanceSelection() in its base class, so all you have to do is place the buttons on the pages, connect the event handlers and use it to jump to the next/previous page.

Depending on what exactly you want to achieve, wxWizard may also be useful:
http://docs.wxwidgets.org/trunk/classwx_wizard.html
Use the source, Luke!
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Re: How to Change the Forms Displayed in wxWidgets

Post by ColleenKobe »

doublemax wrote:Do you want to do this as a learning exercise or do you just want to solve that particular task as easy as possible?

In the latter case check one of the "book control" classes. In your case wxSimpleBook might be exactly what you need:
http://docs.wxwidgets.org/trunk/classwx_simplebook.html

It already has a method wxBookCtrlBase::AdvanceSelection() in its base class, so all you have to do is place the buttons on the pages, connect the event handlers and use it to jump to the next/previous page.

Depending on what exactly you want to achieve, wxWizard may also be useful:
http://docs.wxwidgets.org/trunk/classwx_wizard.html
Hi, doublemax,

Thanks for answering my question.

In answer to your question: I want to do this as a learning exercise. I have only used Visual Studios Community as a GUI so far. The VS routines I used to change pages were fairly straightforward, and I was expecting the same to be true with wxWidgets. I was planning to make a small routine that changed pages and worked perfectly, so that I could start making my own library and make that code be my first entry.

I will look into the "book control" routines you suggest for starters. I scanned it a few minutes ago, and it seems like a GREAT idea--to be able to turn pages like one does for a book. Perfect for a help or tutorial page.

I tried to look into wxWidgets's wxWizard routine, but I can't find where it appears in wxCrafter's menus. Maybe I was looking in the wrong place. I posted a message on their board asking where to find it. While I wait for an answer, I'll read the link you sent for wxWizard.

FYI: My actual goal is to re-create an existing program written in Visual Basic 6. This program links to hardware that returns high-rate streams of data (>200 Mb/sec). The program has around 20 forms. Some display settings (radio buttons, drop-downs, etc); some display charts and graphs live ("live" as in line graphs that change real-time); a few simply show progress bars; and so on. So there will be a lot of forms to display, but they're mostly different from each other, and some are displayed optionally and others only come up during specific conditions.

So the sequence of form displays will be more chaotic than displaying pages in a book would be.

Thank you again!
Post Reply