how can I open a Frame from another Frame ?

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
deuch
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Apr 12, 2005 2:10 pm
Location: france

how can I open a Frame from another Frame ?

Post by deuch »

Hello !

as you know i'm a new user and developper .I learn JAVA but actually ,I've to do a project in C++.So...

is somebody can help me to open a Frame from another Frame with a buttonclick ? like :
void prjMicrocobFrm::WxButtonFicheCliClick(wxCommandEvent& event)
{

Fcheclientfrm->Show(TRUE); (that doesn't work )

event.Skip();
}
Thank for help me .
I try to do my best !
GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT »

Try to use ShowModal() instead of Show(TRUE)
tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Post by tbreina »

I just tried this and it seems to work.

Just to be sure: you have Fcheclientfrm defined, right?

In my case, I tried added a button to the default frame with this code:

Code: Select all

/*
 * WxButton1Click
 */
void Project1Frm::WxButton1Click(wxCommandEvent& event)
{
	Project1Frm *Fcheclientfrm = new  Project1Frm(NULL);
  
	 Fcheclientfrm->Show(TRUE);
	// insert your code here
	event.Skip();
}
So a new main window is created every time the button is pressed.

NOTE: The event.Skip() is not needed and probably should be removed.

-Tony
deuch
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Apr 12, 2005 2:10 pm
Location: france

Post by deuch »

I did
void prjMicrocobFrm::WxButtonFicheCliClick(wxCommandEvent& event)
{
prjMicrocobFrm *Fcheclientfrm = new prjMicrocobFrm(Null);
Fcheclientfrm->show(true);
//event.Skip();
}

the compiler said :

In member function `void prjMicrocobFrm::WxButtonFicheCliClick(wxCommandEvent&)':
404 C:\PAE\projet Microcoob\prjMicrocobFrm.cpp `Null' undeclared (first use this function)
405 C:\PAE\projet Microcoob\prjMicrocobFrm.cpp 'class prjMicrocobFrm' has no member named 'show'

I try the showmodal too ,but the problem is before

so ...
I try to do my best !
krysa
Experienced Solver
Experienced Solver
Posts: 71
Joined: Wed Feb 16, 2005 9:23 pm
Location: Lithuania

Post by krysa »

deuch wrote:I did
void prjMicrocobFrm::WxButtonFicheCliClick(wxCommandEvent& event)
{
prjMicrocobFrm *Fcheclientfrm = new prjMicrocobFrm(Null);
Fcheclientfrm->show(true);
//event.Skip();
}

the compiler said :

In member function `void prjMicrocobFrm::WxButtonFicheCliClick(wxCommandEvent&)':
404 C:\PAE\projet Microcoob\prjMicrocobFrm.cpp `Null' undeclared (first use this function)
405 C:\PAE\projet Microcoob\prjMicrocobFrm.cpp 'class prjMicrocobFrm' has no member named 'show'

I try the showmodal too ,but the problem is before

so ...
C++ is case sensitive. You must write 'NULL' instead of 'Null' or you can simply write 0 (zero).
And, the method name is 'Show' (not 'show') so you must change it as well.
Good luck.
Platform: MSW (Windows XP Pro)
Compiler: msvc 13.10.3077 (Free Toolkit)
wxWidgets: v2.6.0
GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT »

It seems that ShowModal does not work. I looked my code, and it is Show(TRUE) which is written... :D

If you want to open a new frame and don't want to open the same frame again, you have to change

prjMicrocobFrm *Fcheclientfrm = new prjMicrocobFrm(NULL);

by

NameOfNewFrame *Fcheclientfrm = new NameOfNewFrame (NULL)
deuch
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Apr 12, 2005 2:10 pm
Location: france

Post by deuch »

first ,thanks to you help !

so

I try :
.......Fcheclientfrm(NULL); and (Null) ; but the answer was the same :

Null (or NULL) undeclared .
I retry with Fcheclientfrm(0) ;(zero) as you tald me and it was ok for compilation ..... BUT
it doesn't work when I click the button (GRRRRR !)
or exactly ,I think it re-open the same frame

maybe you know why ?
I'll move my little brain tonight .
I try to do my best !
tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Post by tbreina »

or exactly ,I think it re-open the same frame
Right. I think what's happening is that when you hit the button you are opening a new window that is exactly the same as the old one. This is because your command is:

Code: Select all

 prjMicrocobFrm *Fcheclientfrm = new prjMicrocobFrm(Null);
This means that you are creating a new frame called Fcheclientfrm, but that frame is of the class prjMicrocobFrm. Since your main frame is of the same class, then both windows look exactly the same. This is a basic concept of object oriented code like C++: you can use the same class over and over again.

If you want to have a different window frame appear when you click the button, then you'll have to declare a different window frame class. For example, go to New->New wxFrame. You see a new window frame be generated. You can modify that frame any way you like it (add controls, colors, etc). Then in your code:

Code: Select all

/*
 * WxButton1Click
 */
void Project1Frm::WxButton1Click(wxCommandEvent& event)
{
        Untitiled1Frm *Fcheclientfrm = new  Untitled1Frm(NULL);
 
        Fcheclientfrm->Show(TRUE);
        // insert your code here
        event.Skip();
}
where Untitled1Frm is the name of your new frame.

-Tony
deuch
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Apr 12, 2005 2:10 pm
Location: france

Post by deuch »

Hi everybody! Me again !
so
it's going better now :my mistake was between the of the class and the frame.wxform ,a confusion .
and I did something : I write an "Include" card ,with the name MySecondFram.h in the "MyFirstFrame.cpp" file ,and finally that work .BUT... there's always a 'BUT' ,when I click it open two or three frames ,and now I know why ,it's ok ?!? I made a third frame witch open with a bitmapButton and i have the same problem :two frame appears .
If someone know why ? and maybe you if I can get informations from a MySql database to wxTextCtrl.
Thanks
I try to do my best !
GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT »

You should post this again because I don't really understand what you mean. There seem to be missing words in your post. Plus you say that you now know why it opens 2 or 3 frames, so if you know why (I didn't understand why by the way) how can't you solve the problem? Try posting with a safe language if you want us to help you :wink:
Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

I have this same problem

Post by Bundy »

I have two identical function - one is executed when user click button in menuBar and second when user click normal button on panel. Its weird - when user click button in menu it shows dialog and disapear when I click Close button but when I click normal button and click close button dialog disapear and shows again. From where is that diffrent?
Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

I resolv my problem like this:

Post by Bundy »

Code: Select all

void klient::WxButton6Click(wxCommandEvent& event)
{
    static int zn=0;
    if(zn==0)
      {
	    Kal *kal = new Kal(NULL); 
            kal->ShowModal(); 
            //some instructions
	    delete kal;
	    zn++;
      }
    else
      zn--;
    event.Skip();
}
deuch
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Apr 12, 2005 2:10 pm
Location: france

Post by deuch »

I'm sorry ,I forgot some words and my english is bad .

I'll try to explain :
the problem is when I click the button to call my second frame ,two appears .so I tried to understand ,i read the code , I cleaned some comments etc... bur I didn't change anything .I retried and then all was ok , only one frame appear .Well . so I made another event from a bitmatButton and I had the same problem : When I click it ,two frame appear (a third frame ).
I said before , that I wrote in "myFirstFram.cpp" file ,where there is all Buttons and bitmapbuttons declaration and event ,an "#include MysecondFrame.h" instruction ,and for "mythirdFrame" too .And it work .
so ,I hope you 'll understand ,sorry for my bad english (if you speak french....).
Do you know why two frme appear ?
I try to do my best !
Post Reply