I want to use a class pointer defined in my main window class from Oncontrol of a child dialog.
example:
the pointer is defined here...
class PopotteMain : CWindow
{
int l,t,w,h;
declare TBWindow();
declare _TBWindow();
declare virtual OnClose(),int;
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare virtual OnCreate(),int;
declare virtual OnEraseBkgnd(),int;
declare virtual OnMenuPick(int nID),int;
declare virtual OnSize(int nType,int cx,int cy),int;
declare virtual OnMenuInit(unsigned int hMenu),int;
declare virtual InsertImage(string Path, CRichEdit *re1),void;
declare virtual OuvrirFichier(),void;
declare virtual OuvrirDlgLivres(CWindow *parent),void;
declare virtual OuvrirDlgSauvegarder(CWindow *parent),void;
declare virtual OuvrirDlgRechercher(CWindow *parent),void;
CToolBar m_tool;
CMenu m;
//create pointer to ComboBox class
CCOMBOBOX *m_Comb;
//create pointer to Richedit class
CRichEdit *m_Red; // <---- this is the pointer i want to use
}
and i want to use the richedit savefile from here:
Savedlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
int check;
string Livre,recette,description;
PopotteMain Win;
select nID
{
case SBUTTON_Sav:
if(nNotifyCode = 0)
{
check = Chk_Liv->Getcheck();
if check = 1
{
Livre = Ed_5->Gettext();
Recette = Ed_6->Gettext();
if Livre <> "" & Recette <> ""
{
createdir(RecetteDIR + Livre + "\\");
win.m_Red->SaveFile((RecetteDIR + Livre + "\\" + Recette + ".rtf"),1);
}
else
{
messagebox(this,"Vous devez remplir au moins le nom du livre et de la recette avant de sauvegarder","Popotte");
}
}
}
case SBUTTON_Ann:
if(nNotifyCode = 0)
{
CloseDialog(1);
}
case SEDIT_5:
/* respond to edit notifications here */
case SEDIT_6:
/* respond to edit notifications here */
case SCOMBO_7:
/* respond to control notifications here */
case SEDIT_8:
/* respond to edit notifications here */
case SCOMBO_9:
/* respond to control notifications here */
case SEDIT_10:
/* respond to edit notifications here */
case SEDIT_11:
/* respond to edit notifications here */
case SCOMBO_12:
/* respond to control notifications here */
case SCHECK_Liv:
check = Chk_Liv->Getcheck();
if check = 1
{
Chk_Exst->Setcheck(0);
Ed_10->Enable(0);
Ed_11->Enable(0);
SComb2->Enable(0);
SComb3->Enable(0);
Ed_5->Enable(1);
Ed_6->Enable(1);
Ed_8->Enable(1);
SComb1->Enable(1);
}
case SCHECK_Exst:
check = Chk_Exst->Getcheck();
if check = 1
{
Chk_Liv->Setcheck(0);
Ed_5->Enable(0);
Ed_6->Enable(0);
Ed_8->Enable(0);
SComb1->Enable(0);
Ed_10->Enable(1);
Ed_11->Enable(1);
SComb2->Enable(1);
SComb3->Enable(1);
}
}
return true;
}
the program that use this code compile without error but the rtf file saved contain nothing
am i doing something wrong? if i do, how can i do this please?
Savedlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
int check;
string Livre,recette,description;
PopotteMain Win;
...
'Win' is a local variable here, and not initialized to anything. It is not your main window.
Create a member variable in your dialog class named 'PopotteMain *m_pParent'
When you create the dialog set the variable to your main window and then use the pointer.
m_pPArent->m_red->SaveFile(....
Understand?
Quote from: Paul Turley on July 20, 2006, 08:21:24 PM
Understand?
Maybe ;)
its look simple the way you explain it
but it seems thats it lead me to another noobs questions...
what the best way to create a child dialog to a window?
i take my method from a code in this forum.. but it look like very complicated just for a simple child dialog
can you show me a very simple example ?
Use the dialog editor, place your controls, and generate a full source skeleton.
Now might be a good time to point out that member functions TBWindow() and _TBWindow() won't do anything because they don't share the same name as the class. They need to be named PopotteMain() and _PopotteMain().
Quote from: Paul Turley on July 20, 2006, 11:11:31 PM
Use the dialog editor, place your controls, and generate a full source skeleton.
yes i know how to use that... and to make a dialog program..
but where do i create the dialog as a child?
in my Sub main ?
whats the best procedure?
Quote from: Parker on July 21, 2006, 12:39:24 AM
Now might be a good time to point out that member functions TBWindow() and _TBWindow() won't do anything because they don't share the same name as the class. They need to be named PopotteMain() and _PopotteMain().
thanx for pointing that, Parker ;)
The design is up to you. If the dialog is a member variable of your main window I normally use OnCreate to set it up. The you can call DoModal anywhere.
i think i understand a bit.
ive lots to learn with that class type programing ;)
hi again,
i'm still trying to get this to works
Paul, i think i understand whats you tell me but it didnt works
i use the same way to show my dialog from the popottemain window.
ive include the full source in the attachement below
i put like you said "Popottemain *myparent;" in my dialog class, line 191
then i try to save my richedit control to rtf at line 1071 using "myparent->m_red->savefile(...);"
Program compile but crash when i click the button to save from my save dialog.
i really need to understand how this work coze my program will use this oftenly ;)
You're not setting the pointer. So that is why it is crashing. You can't just use a pointer without initializing it first.
Your code is a bit hard to follow, since I am not fluent in french. But this is what I mean:
PopotteMain::OuvrirDlgSauvegarder()
{
//Create pointer to the Dialog
Savedlg *sv;
sv = new(Savedlg,1);
//<<<<<SET THE POINTER
sv->myparent = this;
//<<<<<<
sv->Show(this);
sv->DoModal();
delete sv;
return true;
}
whoo hoo!
thanx Paul, working well now ;D
Quote from: Paul Turley on July 29, 2006, 12:21:58 AM
Your code is a bit hard to follow, since I am not fluent in french. But this is what I mean:
sorry about that, i'm programming billangualy ;)