Multiple wxFrame Doubt II 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
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Multiple wxFrame Doubt II

Post by Nick »

Still with difficulties...
In my previous doubt I learned:

Code: Select all

Form1 *WindowForm1 = new Form1(0);
WindowForm1->My_wxTextCtrl->SetValue("A");
But in this case above, the Window was still being created.
In my doubt below, the Window already exists!

I also understood the message below but the problem is, I don't know how to do it any other way, and I have no idea how it is :roll:
However, it's bad practice to manipulate a variable of another object directly this way. Usually you would add a public method to the class which let other classes set the variable from the "outside". In your case it could also make sense to pass additional parameters to the constructor of Form1.
What I am doing now is call another window from a button. Hiding this button that called the Window. It works

Code: Select all

   // The program starts like this:
   Frame1* Frame = new Frame1(0);
   Frame->Show();
   SetTopWindow(Frame);
   
   // By clicking on the Button which is in Frame1
void Frame1::OnBtFrame1Click(wxCommandEvent &event) {
   BtFrame1->Hide();
   Frame2 *frame2 = new Frame2(0);
   frame2->Show(); // I go to Frame2 which is shown on the screen along with Frame1
}
So when closing Frame2 I would like the Frame1 button to appear again

Code: Select all

void Frame2::OnClose(wxCloseEvent &event) {
   Close(); // PROBLEM This command is terminating the entire program.
//   Frame->BtFrame1->Show(); // No Work
//   Frame1->BtFrame1->Show(); // error: expected unqualified-id before ‘->’ token
   Frame1 *frame1 = new Frame1(0);
   frame1->BtFrame1->Show();
}
PROBLEM:
Close(); This command is terminating the entire program. Without it the window will not close
I don't know if it works as I did above create an instance of Window, and it doesn't even seem right, because the Window is already displayed.

My objective
I want to open Form2 through a button. When I click this button I hide it. (So far I can do)
So I have 2 open Frames on my screen.
When closing Frame2 I want to show again the Button that I hid
Remembering that: Each Frame is using separate files. Frame1.cpp, Frame2.cpp, Frame1.h, Frame2.h

The purpose of the example I am showing is because I need to learn to work with separate windows in my application.
The case of the button is because in my program I'm doing, I have 6 separate frames. I often need to change controls from another frame from one frame, such as button, label, title with the application running.

I will have 1 Frame buttons that will change the Grid content of another frame for example.
I simplified the question to just 1 button, because if I can do it the right way other controls will follow the same example.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple wxFrame Doubt II

Post by doublemax »

First of all: It's a little bit unusual to work with two frames like that. Often you'd have one main frame and you would open another frame or dialog additionally. But you wouldn't hide the first one.

But lets assume you have a good reason to do this :)

With two frames you could manage somehow that they know about each other and handle the showing / hiding. With more than two this would become complicated and error prone already. In these cases it's better to have one "manager" object higher up in the hierarchy. This could be your wxApp instance.

Create both frames and store their pointers in the wxApp object.
Add methods to wxApp to show / hide these frames.

Example based on "minimal" sample:

Code: Select all

// include declarations for frames
#include "frame1.h"
#include "frame2.h"

class MyApp : public wxApp
{
public:
    virtual bool OnInit() wxOVERRIDE;

    void ShowFrame1()
    {
      m_frame1->Show();
      m_frame2->Hide();
    }

    void ShowFrame2()
    {
      m_frame1->Hide();
      m_frame2->Show();
    }

protected:
  Frame1 *m_frame1;
  Frame2 *m_frame2;
};

Code: Select all

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() )
        return false;

    m_frame1 = new Frame1("this is frame 1");
    m_frame2 = new Frame2("this is frame 2");

    ShowFrame1();

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}
You can get a reference to your wxApp instance from anywhere with wxGetApp(). For that you need to include the header with the MyApp declaration and add the wxDECLARE_APP(MyApp) macro near the top of any other source file.

Then you can e.g. call wxGetApp().ShowFrame1() from anywhere.
Use the source, Luke!
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

doublemax wrote: Tue Aug 20, 2019 7:10 am Example based on "minimal" sample:
Your idea is good, and of course I learn from it too, mainly because I will do the codes by hand in the future.

But I will explain my current motives. I am still learning how to use. And in the meantime I am creating a small database to register what I learn.
And I'm doing this on Codeblocks.
For each Frame created Codeblocks creates 2 separate files .cpp and .h and of course their .wxs.
So look at my problem with this program I am creating and learning how to create it.

Frame Tips.cpp Where is it bool MyProgram::OnInit() {
It just loads this frame, because it will be the most used. Other frames may not even be used when consulting Tips
I think that way I don't consume resources. If I do not use the other frames at that time
Beside, in the background, you can see all the project and the files it has.
Image

Clicking on the Add button of the Frame Tips.cpp then opens the other frame. CadTips.cpp
FrmCadTips *FrameCadTips = new FrmCadTips(0);
FrameCadTips->Show();
// BtAdd->Hide(); // I want to hide the Add Button to prevent it from being clicked when this Frame is already open!
Image

In case I need to see Hashtags, I open Hashtags.cpp And I think it's also good for me to hide the button that shows it.
Image

In case I need to register Hashtags
Image

Another situation is that, by the way, I may need to look in previous frames as I registered that tip, or as I registered Hashtags to register the new one correctly. Which is why I may need the previous Frames open at that time.

The main goal is to learn how to mecher with these separate frames. Because I think for the future when I know better, use an idea I saw in Source/samples wxWidgets A layout similar to richtext and dataview I really liked But I think it's still too advanced for me to try to do

Every little bit I made, besides using Codeblocks, I am gradually bringing to hand in my own way.

Image
Image

I keep the code as simple and clean as possible to understand each line what it does.
But I know at the moment I can't do it all by myself, so using Codeblocks not only to create Frames, but also to show me how his code is written, even if I have to correct it, because he writes things too much.

I don't even think about working with multiple spread files either. My idea is that there is only 1 file, the .cpp because it will not have much written and is simpler. But since everyone writes 10 lines and spreads to 6 files, I need to learn to understand the examples.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple wxFrame Doubt II

Post by doublemax »

These are all typical cases where you would normally show a modal dialog instead of a wxFrame. This would make the whole logic much easier.
Use the source, Luke!
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

doublemax wrote: Tue Aug 20, 2019 10:28 am These are all typical cases where you would normally show a modal dialog instead of a wxFrame. This would make the whole logic much easier.
The problem with using Modal Dialogs is that I could not use previous Windows if I had to! :D
Example: When I register a Hashtags for example Find. Her synonyms would be: Search, seek, look and etc...
I will need to check if I have not registered something similar, or if I need to register separately for some reason. OR if in the tip itself this is necessary or not then I would have to go back to 1st Frame
To search Tips that could discard the registration of that hashtag. But if I come back closing the windows, I would have to open all over again and write all over again.

Which is why, I prefer if it happens to be able to access all at the same time. Or it may happen that I have to be viewing a Tips to copy part to the Hashtags register. :D
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

One day, what I want is something like this
Image

And the Tips displayed something like this and can put images, colors and etc ...
Image

But this is still too advanced for me to try to do! I have a lot to learn before ...
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

Summary of the program I am trying to do.
I want a program where I can register various information such as Tips for: C, C ++, Linux, wxWidgets, Cooking Recipes, Remedies, Electronics Tips, General Knowledge.

It's like an encyclopedia of information. Where I will consult with a word and have the desired information.

Since I still don't know how to make everything colorful, with images and many other things, I am doing the basics with just plain text initially, a Link to a folder on my PC where other file formats will be, until I know how to complete everything.

I want to remember that in the end my program will only have 1.cpp file because it is simple and will not be large. But I am doing with several separate files to learn how to create just like many people do.

Still for future project ...
Learn how to paste text into non-program windows so I can create my Snippets, where I type for example: m@
And he replaces it with: [email protected]

Among other texts like date and etc ...
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple wxFrame Doubt II

Post by doublemax »

I'd still use the wxApp object as global "manager" for the display of all frames and the communication between them.
Use the source, Luke!
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

doublemax wrote: Tue Aug 20, 2019 7:12 pm I'd still use the wxApp object as global "manager" for the display of all frames and the communication between them.
Well, I think then I will have to consider your suggestion a lot! Because I believe you must have countless reasons I don't know, and why it's truly easier to do and to control.

Thank you for being patient with me, and keep insisting on your opinion! I'll start to find a way to make Codeblocks recognize this, so I can continue modeling the forms in it.

I will post the modified Source as soon as I modify it, I believe I already know how to do that!
So in my Main .cpp, as you showed I will have all the calls to Frames. I will do this.
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

doublemax wrote: Tue Aug 20, 2019 7:10 am Example based on "minimal" sample:

Code: Select all

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() )
        return false;

    m_frame1 = new Frame1("this is frame 1");
    m_frame2 = new Frame2("this is frame 2");

    ShowFrame1();

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}
I have a problem!
In this statement below:

Code: Select all

      FrmCadTips *FrameFrmCadTips = new FrmCadTips(0);
      FrmHashtags *FrameFrmHashtags = new FrmHashtags(0);
      FrmCadHashtags *FrameFrmCadHashtags = new FrmCadHashtags(0);
When I declare like this, is it just a statement or will the program allocate memory for these frames?
I ask that, because here is only Database Tips. And only now did I remember the others. This application when I join Database Contacts, Database Passwords, Database Snippets, Database Bookmarks, it will go over 60 Frames.
And when the application is used, the most it will mix from open Frames as needed will be Tips + Snippets + Bookmarks, at the same time that would give 15 Frames. The other frames would not even be in use. Because DataBase Contacts I open and close after consulting.
And it wouldn't be good for them to exist in memory.
And there's FrmTasks that I remembered right now

Code: Select all

bool MyProgram::OnInit() {
   LoadFiles();

   bool wxsOK = true;
   wxInitAllImageHandlers();

   if (wxsOK) {
      FrmCadTips *FrameFrmCadTips = new FrmCadTips(0);
      FrmHashtags *FrameFrmHashtags = new FrmHashtags(0);
      FrmCadHashtags *FrameFrmCadHashtags = new FrmCadHashtags(0);
      
      FrmTips *FrameFrmTips = new FrmTips(0);
      FrameFrmTips->Show();
      SetTopWindow(FrameFrmTips);
    }
    //*)
    return wxsOK;
}
Another annoying problem that can be ignored is that Codeblocks when joining these Forms and Headers it keeps repeating the Code in Source, and whenever I move a Form I have to delete. That's because of his mixed statements.

Code: Select all

#include "Tips.h"
#include <wx/msgdlg.h> // wxMessageBox
#include <wx/intl.h>
#include <wx/string.h>

//(*AppHeaders
//*)
//(*InternalHeaders(FrmTips)
//*)
//(*InternalHeaders(FrmCadTips)
//*)
//(*InternalHeaders(FrmHashtags)
//*)
//(*InternalHeaders(FrmCadHashtags)
//*)
The boring codeblocks
declares 5 times in a row below all includes above in InternalHeaders

This source has: Tips.cpp and Tips.h only

It's just that I started doing it split so it didn't complicate for me, because when I started creating all the Structs, the code got big with many Headers and Frames for me to learn. So I temporarily separated and preferred to continue with Tips, because it will be the current source of research for what I am noting when I learn.
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

Another problem. That I believe I got it wrong! I will post the statements from the beginning, because I believe they were declared wrong

Tips.h

Code: Select all

#include <wx/button.h>
#include <wx/frame.h>
#include <wx/grid.h>
#include <wx/srchctrl.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>

//(*Headers(FrmTips)
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
//*)
//(*Headers(FrmCadTips)
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
//*)
//(*Headers(FrmHashtags)
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
//*)
//(*Headers(FrmCadHashtags)
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
//*)

class FrmTips: public wxFrame {
public:
   FrmTips(wxWindow *parent, wxWindowID id = -1);
   virtual ~FrmTips();

private:
   //(*Handlers(FrmTips)
   void OnBtAddFrmTipsClick(wxCommandEvent& event);
   //*)

   //(*Identifiers(FrmTips)
   static const long ID_EdSearchFrmTips;
   static const long ID_GridTips;
   static const long ID_BtAddFrmTips;
   //*)

   //(*Declarations(FrmTips)
   wxButton* BtAddFrmTips;
   wxGrid* GridTips;
   wxSearchCtrl* EdSearchFrmTips;
   //*)
};

class FrmCadTips: public wxFrame {
public:
	FrmCadTips(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
	virtual ~FrmCadTips();

	//(*Declarations(FrmCadTips)
	wxButton* BtHashtagsFrmCadTips;
	wxButton* BtSaveFrmCadTips;
	wxStaticText* EdCodFrmCadTips;
	wxStaticText* EdModifiedFrmCadTips;
	wxStaticText* EdRegisteredFrmCadTips;
	wxStaticText* LbCodFrmCadTips;
	wxStaticText* LbHashtagFrmCadTips;
	wxStaticText* LbLinkLbFrmCadTips;
	wxStaticText* LbModifiedFrmCadTips;
	wxStaticText* LbRegisteredFrmCadTips;
	wxStaticText* LbTipTitleFrmCadTips;
	wxTextCtrl* EdHashtagFrmCadTips;
	wxTextCtrl* EdLinkFrmCadTips;
	wxTextCtrl* EdTipFrmCadTips;
	wxTextCtrl* EdTipTitleFrmCadTips;
	//*)

protected:
	//(*Identifiers(FrmCadTips)
	static const long ID_LbCodFrmCadTips;
	static const long ID_EdCodFrmCadTips;
	static const long ID_LbRegisteredFrmCadTips;
	static const long ID_EdRegisteredFrmCadTips;
	static const long ID_LbModifiedFrmCadTips;
	static const long ID_EdModifiedFrmCadTips;
	static const long ID_LbTipTitleFrmCadTips;
	static const long ID_EdTipTitleFrmCadTips;
	static const long ID_LbHashtagFrmCadTips;
	static const long ID_EdHashtagFrmCadTips;
	static const long ID_LbLinkFrmCadTips;
	static const long ID_EdLinkFrmCadTips;
	static const long ID_EdTipFrmCadTips;
	static const long ID_BtSaveFrmCadTips;
	static const long ID_BtHashtagsFrmCadTips;
	//*)

private:
	//(*Handlers(FrmCadTips)
	void OnBtAddHashtagsFrmCadTipsClick(wxCommandEvent& event);
	void OnBtHashtagsFrmCadTipsClick(wxCommandEvent& event);
	void OnCloseFrmCadTips(wxCloseEvent& event);
	//*)
};

class FrmHashtags: public wxFrame {
public:
	FrmHashtags(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize);
	virtual ~FrmHashtags();

	//(*Declarations(FrmHashtags)
	wxButton* BtAddFrmHashtags;
	wxGrid* GridHashtags;
	wxSearchCtrl* EdSearchFrmHashtgs;
	//*)

protected:
	//(*Identifiers(FrmHashtags)
	static const long ID_EdSearchFrmHashtgs;
	static const long ID_GridHashtags;
	static const long ID_BtAddFrmHashtags;
	//*)

private:
	//(*Handlers(FrmHashtags)
	void OnBtAddFrmHashtagsClick(wxCommandEvent& event);
	//*)
};

class FrmCadHashtags: public wxFrame {
public:
	FrmCadHashtags(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize);
	virtual ~FrmCadHashtags();

   //(*Declarations(FrmCadHashtags)
   wxButton* BtDeleteFrmCadHashtags;
   wxButton* BtSaveFrmCadHashtags;
   wxStaticText* LbHashtagFrmCadHashtags;
   wxStaticText* LbSynonymsFrmCadHashtags;
   wxTextCtrl* EdHashtagFrmCadHashtags;
   wxTextCtrl* EdSynonymsFrmCadHashtags;
   //*)

protected:
	//(*Identifiers(FrmCadHashtags)
	static const long ID_LbHashtagFrmCadHashtags;
	static const long ID_EdHashtagFrmCadHashtags;
	static const long ID_LbSynonymsFrmCadHashtags;
	static const long ID_EdSynonymsFrmCadHashtags;
	static const long ID_BtSaveFrmCadHashtags;
	static const long ID_BtDeleteFrmCadHashtags;
	//*)

private:
	//(*Handlers(FrmCadHashtags)
	void OnBtSaveFrmCadHashtagsClick(wxCommandEvent& event);
	//*)
};

#include <wx/app.h>
class MyProgram: public wxApp {
public:
   bool OnInit();
};
Tips.cpp PARTIAL

Code: Select all

#include "Tips.h"
#include <wx/msgdlg.h> // wxMessageBox
#include <wx/intl.h>
#include <wx/string.h>

//(*AppHeaders
#include <wx/intl.h>
#include <wx/string.h>
//*)
//(*InternalHeaders(FrmTips)
#include <wx/intl.h>
#include <wx/string.h>
//*)
//(*InternalHeaders(FrmCadTips)
#include <wx/intl.h>
#include <wx/string.h>
//*)
//(*InternalHeaders(FrmHashtags)
#include <wx/intl.h>
#include <wx/string.h>
//*)
//(*InternalHeaders(FrmCadHashtags)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(FrmTips)
const long FrmTips::ID_EdSearchFrmTips = wxNewId();
const long FrmTips::ID_GridTips = wxNewId();
const long FrmTips::ID_BtAddFrmTips = wxNewId();
//*)

//(*IdInit(FrmCadTips)
const long FrmCadTips::ID_LbCodFrmCadTips = wxNewId();
const long FrmCadTips::ID_EdCodFrmCadTips = wxNewId();
const long FrmCadTips::ID_LbRegisteredFrmCadTips = wxNewId();
const long FrmCadTips::ID_EdRegisteredFrmCadTips = wxNewId();
const long FrmCadTips::ID_LbModifiedFrmCadTips = wxNewId();
const long FrmCadTips::ID_EdModifiedFrmCadTips = wxNewId();
const long FrmCadTips::ID_LbTipTitleFrmCadTips = wxNewId();
const long FrmCadTips::ID_EdTipTitleFrmCadTips = wxNewId();
const long FrmCadTips::ID_LbHashtagFrmCadTips = wxNewId();
const long FrmCadTips::ID_EdHashtagFrmCadTips = wxNewId();
const long FrmCadTips::ID_LbLinkFrmCadTips = wxNewId();
const long FrmCadTips::ID_EdLinkFrmCadTips = wxNewId();
const long FrmCadTips::ID_EdTipFrmCadTips = wxNewId();
const long FrmCadTips::ID_BtSaveFrmCadTips = wxNewId();
const long FrmCadTips::ID_BtHashtagsFrmCadTips = wxNewId();
//*)

//(*IdInit(FrmHashtags)
const long FrmHashtags::ID_EdSearchFrmHashtgs = wxNewId();
const long FrmHashtags::ID_GridHashtags = wxNewId();
const long FrmHashtags::ID_BtAddFrmHashtags = wxNewId();
//*)

//(*IdInit(FrmCadHashtags)
const long FrmCadHashtags::ID_LbHashtagFrmCadHashtags = wxNewId();
const long FrmCadHashtags::ID_EdHashtagFrmCadHashtags = wxNewId();
const long FrmCadHashtags::ID_LbSynonymsFrmCadHashtags = wxNewId();
const long FrmCadHashtags::ID_EdSynonymsFrmCadHashtags = wxNewId();
const long FrmCadHashtags::ID_BtSaveFrmCadHashtags = wxNewId();
const long FrmCadHashtags::ID_BtDeleteFrmCadHashtags = wxNewId();
//*)

FrmTips::FrmTips(wxWindow *parent, wxWindowID id) {
   //(*Initialize(FrmTips)
   Create(parent, wxID_ANY, _("Sistema One 2019"), wxDefaultPosition, wxDefaultSize, wxCLOSE_BOX|wxMINIMIZE_BOX, _T("wxID_ANY"));
   SetClientSize(wxSize(800,600));
   EdSearchFrmTips = new wxSearchCtrl(this, ID_EdSearchFrmTips, wxEmptyString, wxPoint(5,5), wxSize(600,30), 0, wxDefaultValidator, _T("ID_EdSearchFrmTips"));
   GridTips = new wxGrid(this, ID_GridTips, wxPoint(5,40), wxSize(790,555), 0, _T("ID_GridTips"));
   GridTips->CreateGrid(10,1);
   GridTips->EnableEditing(false);
   GridTips->EnableGridLines(true);
   GridTips->SetColLabelSize(20);
   GridTips->SetRowLabelSize(1);
   GridTips->SetDefaultColSize(775, true);
   GridTips->SetColLabelValue(0, _("Tips"));
   GridTips->SetDefaultCellFont( GridTips->GetFont() );
   GridTips->SetDefaultCellTextColour( GridTips->GetForegroundColour() );
   BtAddFrmTips = new wxButton(this, ID_BtAddFrmTips, _("Add"), wxPoint(710,5), wxSize(85,30), 0, wxDefaultValidator, _T("ID_BtAddFrmTips"));
   Center();

   Connect(ID_BtAddFrmTips,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&FrmTips::OnBtAddFrmTipsClick);
   //*)
}

FrmCadTips::FrmCadTips(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size) {
	//(*Initialize(FrmCadTips)
	Create(parent, wxID_ANY, _("Sistema One 2019"), wxDefaultPosition, wxDefaultSize, wxCLOSE_BOX|wxMINIMIZE_BOX, _T("wxID_ANY"));
	SetClientSize(wxSize(800,600));
	LbCodFrmCadTips = new wxStaticText(this, ID_LbCodFrmCadTips, _("Cod:"), wxPoint(5,5), wxDefaultSize, 0, _T("ID_LbCodFrmCadTips"));
	EdCodFrmCadTips = new wxStaticText(this, ID_EdCodFrmCadTips, _("14082019163000"), wxPoint(35,5), wxDefaultSize, 0, _T("ID_EdCodFrmCadTips"));
	LbRegisteredFrmCadTips = new wxStaticText(this, ID_LbRegisteredFrmCadTips, _("| Registered:"), wxPoint(138,5), wxDefaultSize, 0, _T("ID_LbRegisteredFrmCadTips"));
	EdRegisteredFrmCadTips = new wxStaticText(this, ID_EdRegisteredFrmCadTips, _("14/08/2019 00:25:00"), wxPoint(212,5), wxDefaultSize, 0, _T("ID_EdRegisteredFrmCadTips"));
	LbModifiedFrmCadTips = new wxStaticText(this, ID_LbModifiedFrmCadTips, _("| Modified:"), wxPoint(335,5), wxDefaultSize, 0, _T("ID_LbModifiedFrmCadTips"));
	EdModifiedFrmCadTips = new wxStaticText(this, ID_EdModifiedFrmCadTips, _("14/08/2019 00:25:00"), wxPoint(395,5), wxDefaultSize, 0, _T("ID_EdModifiedFrmCadTips"));
	LbTipTitleFrmCadTips = new wxStaticText(this, ID_LbTipTitleFrmCadTips, _("Tip:"), wxPoint(20,40), wxDefaultSize, 0, _T("ID_LbTipTitleFrmCadTips"));
	EdTipTitleFrmCadTips = new wxTextCtrl(this, ID_EdTipTitleFrmCadTips, wxEmptyString, wxPoint(60,35), wxSize(600,30), 0, wxDefaultValidator, _T("ID_EdTipTitleFrmCadTips"));
	EdTipTitleFrmCadTips->SetMaxLength(100);
	LbHashtagFrmCadTips = new wxStaticText(this, ID_LbHashtagFrmCadTips, _("Hashtag:"), wxPoint(5,80), wxDefaultSize, 0, _T("ID_LbHashtagFrmCadTips"));
	EdHashtagFrmCadTips = new wxTextCtrl(this, ID_EdHashtagFrmCadTips, wxEmptyString, wxPoint(60,75), wxSize(600,30), 0, wxDefaultValidator, _T("ID_EdHashtagFrmCadTips"));
	EdHashtagFrmCadTips->SetMaxLength(250);
	LbLinkLbFrmCadTips = new wxStaticText(this, ID_LbLinkFrmCadTips, _("Link:"), wxPoint(15,120), wxDefaultSize, 0, _T("ID_LbLinkFrmCadTips"));
	EdLinkFrmCadTips = new wxTextCtrl(this, ID_EdLinkFrmCadTips, wxEmptyString, wxPoint(60,115), wxSize(600,30), 0, wxDefaultValidator, _T("ID_EdLinkFrmCadTips"));
	EdLinkFrmCadTips->SetMaxLength(150);
	EdTipFrmCadTips = new wxTextCtrl(this, ID_EdTipFrmCadTips, wxEmptyString, wxPoint(5,155), wxSize(790,440), wxTE_MULTILINE, wxDefaultValidator, _T("ID_EdTipFrmCadTips"));
	BtSaveFrmCadTips = new wxButton(this, ID_BtSaveFrmCadTips, _("Save"), wxPoint(670,35), wxSize(90,30), 0, wxDefaultValidator, _T("ID_BtSaveFrmCadTips"));
	BtHashtagsFrmCadTips = new wxButton(this, ID_BtHashtagsFrmCadTips, _("Hashtags"), wxPoint(670,75), wxSize(90,30), 0, wxDefaultValidator, _T("ID_BtHashtagsFrmCadTips"));
	Center();

	Connect(ID_BtHashtagsFrmCadTips,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&FrmCadTips::OnBtHashtagsFrmCadTipsClick);
	Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&FrmCadTips::OnCloseFrmCadTips);
	//*)
}

FrmHashtags::FrmHashtags(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size) {
	//(*Initialize(FrmHashtags)
	Create(parent, wxID_ANY, _("Sistema One 2019"), wxDefaultPosition, wxDefaultSize, wxCLOSE_BOX|wxMINIMIZE_BOX, _T("wxID_ANY"));
	SetClientSize(wxSize(800,600));
	EdSearchFrmHashtgs = new wxSearchCtrl(this, ID_EdSearchFrmHashtgs, wxEmptyString, wxPoint(5,5), wxSize(600,30), 0, wxDefaultValidator, _T("ID_EdSearchFrmHashtgs"));
	GridHashtags = new wxGrid(this, ID_GridHashtags, wxPoint(5,40), wxSize(790,555), 0, _T("ID_GridHashtags"));
	GridHashtags->CreateGrid(10,2);
	GridHashtags->EnableEditing(true);
	GridHashtags->EnableGridLines(true);
	GridHashtags->SetColLabelSize(20);
	GridHashtags->SetRowLabelSize(1);
	GridHashtags->SetDefaultColSize(385, true);
	GridHashtags->SetColLabelValue(0, _("Hashtag"));
	GridHashtags->SetColLabelValue(1, _("Synonyms"));
	GridHashtags->SetDefaultCellFont( GridHashtags->GetFont() );
	GridHashtags->SetDefaultCellTextColour( GridHashtags->GetForegroundColour() );
	BtAddFrmHashtags = new wxButton(this, ID_BtAddFrmHashtags, _("Add"), wxPoint(710,5), wxSize(85,30), 0, wxDefaultValidator, _T("ID_BtAddFrmHashtags"));
	Center();

	Connect(ID_BtAddFrmHashtags,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&FrmHashtags::OnBtAddFrmHashtagsClick);
	//*)

   // 775 é o tamanho total que tenho pra usar no grid
   GridHashtags->SetColSize(0,100); // Column Hashtags
   GridHashtags->SetColSize(1,675); // Column Synonyms
}

FrmCadHashtags::FrmCadHashtags(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size) {
	//(*Initialize(FrmCadHashtags)
	Create(parent, id, _("Sistema One 2019"), wxDefaultPosition, wxDefaultSize, wxCLOSE_BOX|wxMINIMIZE_BOX, _T("id"));
	SetClientSize(wxSize(510,165));
	Move(wxDefaultPosition);
	LbHashtagFrmCadHashtags = new wxStaticText(this, ID_LbHashtagFrmCadHashtags, _("Hashtag:"), wxPoint(5,5), wxDefaultSize, 0, _T("ID_LbHashtagFrmCadHashtags"));
	EdHashtagFrmCadHashtags = new wxTextCtrl(this, ID_EdHashtagFrmCadHashtags, wxEmptyString, wxPoint(5,25), wxSize(500,30), 0, wxDefaultValidator, _T("ID_EdHashtagFrmCadHashtags"));
	EdHashtagFrmCadHashtags->SetMaxLength(20);
	LbSynonymsFrmCadHashtags = new wxStaticText(this, ID_LbSynonymsFrmCadHashtags, _("Synonyms:"), wxPoint(5,60), wxDefaultSize, 0, _T("ID_LbSynonymsFrmCadHashtags"));
	EdSynonymsFrmCadHashtags = new wxTextCtrl(this, ID_EdSynonymsFrmCadHashtags, wxEmptyString, wxPoint(5,80), wxSize(500,30), 0, wxDefaultValidator, _T("ID_EdSynonymsFrmCadHashtags"));
	EdSynonymsFrmCadHashtags->SetMaxLength(250);
	BtSaveFrmCadHashtags = new wxButton(this, ID_BtSaveFrmCadHashtags, _("Save"), wxPoint(320,120), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BtSaveFrmCadHashtags"));
	BtDeleteFrmCadHashtags = new wxButton(this, ID_BtDeleteFrmCadHashtags, _("Delete"), wxPoint(420,120), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BtDeleteFrmCadHashtags"));
	Center();

	Connect(ID_BtSaveFrmCadHashtags,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&FrmCadHashtags::OnBtSaveFrmCadHashtagsClick);
	//*)
}

Code: Select all

bool MyProgram::OnInit() {
   LoadFiles();

   bool wxsOK = true;
   wxInitAllImageHandlers();

   if (wxsOK) {
      FrmCadTips *FrameFrmCadTips = new FrmCadTips(0);
      FrmHashtags *FrameFrmHashtags = new FrmHashtags(0);
      FrmCadHashtags *FrameFrmCadHashtags = new FrmCadHashtags(0);
      
      FrmTips *FrameFrmTips = new FrmTips(0);
      FrameFrmTips->Show();
      SetTopWindow(FrameFrmTips);
    }
    //*)
    return wxsOK;
}
Where is giving error.

Code: Select all

void FrmCadTips::OnCloseFrmCadTips(wxCloseEvent& event) {
   wxGetApp().FrameFrmTips->BtAddFrmTips->Show(); /// error: ‘class MyProgram’ has no member named ‘FrameFrmTips’
}
What I think I understand is that I should declare all other forms within FrmTips
And if that's the case, I really don't know how to do that.
What I know to do is put a button inside a Panel that is inside a frame.

Note the repeated includes is Codeblocks creating automatic, I have to be removing all the time manually.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple wxFrame Doubt II

Post by doublemax »

Code: Select all

      FrmCadTips *FrameFrmCadTips = new FrmCadTips(0);
      FrmHashtags *FrameFrmHashtags = new FrmHashtags(0);
      FrmCadHashtags *FrameFrmCadHashtags = new FrmCadHashtags(0);
Yes, they all will be in memory.

FrameFrmCadTips , FrameFrmHashtags , etc. must be member variables of "MyProgram", so you can access them later.

Code: Select all

wxGetApp().FrameFrmTips->BtAddFrmTips->Show()
Even if it may seems useless, i highly recommend to use dedicated methods in MyProgram for this. Don't access member variables directly.
Use the source, Luke!
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Multiple wxFrame Doubt II

Post by Nick »

doublemax wrote: Tue Aug 20, 2019 7:12 pm I'd still use the wxApp object as global "manager" for the display of all frames and the communication between them.
I'm sorry it took so long to close this topic. But only now have I understood your answer! That's why I didn't close it before! #-o
Post Reply