May 05, 2024, 02:51:31 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Classes pointers

Started by ExMember001, July 20, 2006, 07:58:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

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?

Ionic Wind Support Team

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?
Ionic Wind Support Team

ExMember001

July 20, 2006, 10:41:39 PM #2 Last Edit: July 20, 2006, 10:49:28 PM by krypt
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 ?

Ionic Wind Support Team

Use the dialog editor, place your controls, and generate a full source skeleton.
Ionic Wind Support Team

Parker

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().

ExMember001

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 ;)

Ionic Wind Support Team

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.
Ionic Wind Support Team

ExMember001

i think i understand a bit.
ive lots to learn with that class type programing ;)

ExMember001

July 28, 2006, 11:56:51 PM #8 Last Edit: July 29, 2006, 12:03:48 AM by krypt
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 ;)

Ionic Wind Support Team

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;
}


Ionic Wind Support Team

ExMember001

July 29, 2006, 12:37:31 AM #10 Last Edit: July 29, 2006, 12:39:57 AM by krypt
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 ;)