Child Dialogs Pt II (params) 
Author Message
 Child Dialogs Pt II (params)

Is it possible to send parameters to a child dialog ?

e.g.  dlg.DoModal(v_Number).

--
Lordy
http://www.*-*-*.com/



Wed, 05 Nov 2003 23:45:37 GMT  
 Child Dialogs Pt II (params)

Quote:

> Is it possible to send parameters to a child dialog ?

> e.g.  dlg.DoModal(v_Number).

> --
> Lordy
> http://www.overlord-uk.com/

Sure.  Modify the constructor to accept the parameters:

dlg.DoModal(this, v_Number, v_Number);

CResetDlg::CResetDlg(CWnd* pParent, int x, int y)
        : CDialog(CResetDlg::IDD, pParent)
{
        m_x = x;
        m_y = y;

--
Scott McPhillips [VC++ MVP]



Wed, 05 Nov 2003 23:53:25 GMT  
 Child Dialogs Pt II (params)

Quote:
> > Is it possible to send parameters to a child dialog ?

> Sure.  Modify the constructor to accept the parameters:

Almost there, still getting a DoModal function does not accept 2
parameters error tho with the following;

Calling code;

        CConfirmDeleteDlg dlg;
        int nResponse = dlg.DoModal(this, v_BadgeArrayIndex);

(tried with or without 'this', not sure what that is/does yet).

---------------------------------
CConfirmDeleteDlg.cpp

        CConfirmDeleteDlg::CConfirmDeleteDlg(CWnd* pParent, int v_Param)
        : CDialog(CConfirmDeleteDlg::IDD, pParent)
        {
          //{{AFX_DATA_INIT(CConfirmDeleteDlg)
          // NOTE: the ClassWizard will add member initialization here
          //}}AFX_DATA_INIT
        }

---------------------------------
CConfirmDeleteDlg.h

        class CConfirmDeleteDlg : public CDialog

        // Construction
        public:
                ConfirmDeleteDlg(CWnd* pParent=NULL, int v_Param=NULL);  
        // standard constructor

--
Lordy



Thu, 06 Nov 2003 03:13:32 GMT  
 Child Dialogs Pt II (params)

Quote:

> > > Is it possible to send parameters to a child dialog ?

> > Sure.  Modify the constructor to accept the parameters:

> Almost there, still getting a DoModal function does not accept 2
> parameters error tho with the following;

> Calling code;

>         CConfirmDeleteDlg dlg;
>         int nResponse = dlg.DoModal(this, v_BadgeArrayIndex);

> (tried with or without 'this', not sure what that is/does yet).

> ---------------------------------
> CConfirmDeleteDlg.cpp

>         CConfirmDeleteDlg::CConfirmDeleteDlg(CWnd* pParent, int v_Param)
>         : CDialog(CConfirmDeleteDlg::IDD, pParent)
>         {
>           //{{AFX_DATA_INIT(CConfirmDeleteDlg)
>           // NOTE: the ClassWizard will add member initialization here
>           //}}AFX_DATA_INIT
>         }

No, like this:
         CConfirmDeleteDlg dlg(this, v_BadgeArrayIndex); // line 1
         int nResponse = dlg.DoModal();                  // line 2

line 1 calls the dialog's constructor function. It is passing 'this'
as the pParent and v_BadgeArrayIndex as the v_Param.  Then you want to
save the v_Param inside the constructor function, with a line like
m_Param = v_Param, so you will be able to use it later in other dialog
functions.

--
Scott McPhillips [VC++ MVP]



Thu, 06 Nov 2003 05:40:37 GMT  
 Child Dialogs Pt II (params)

Quote:
> No, like this:
>          CConfirmDeleteDlg dlg(this, v_BadgeArrayIndex); // line 1
>          int nResponse = dlg.DoModal();                  // line 2

Ah, that did the trick.

Quote:
> line 1 calls the dialog's constructor function. It is passing 'this'
> as the pParent and v_BadgeArrayIndex as the v_Param.  Then you want to
> save the v_Param inside the constructor function, with a line like
> m_Param = v_Param, so you will be able to use it later in other dialog
> functions.

Yup, got it working perfectly now, much appreciated  (as always  :)

--
Lordy
http://www.overlord-uk.com/



Thu, 06 Nov 2003 07:53:37 GMT  
 Child Dialogs Pt II (params)

Quote:
> Yup, got it working perfectly now, much appreciated  (as always  :)

Gah, one more dopey problem, I'd assumed that the child dialogs would be
able to access a CStringArray declared in the main dialog that holds all
the information I need, but it appears they can't.

Where would I have to shift the declaration for the array to in order
that every child dialog in the program is able to see it ?

--
Lordy
http://www.overlord-uk.com/



Thu, 06 Nov 2003 10:14:09 GMT  
 Child Dialogs Pt II (params)
One possibility is the application, which you can always get with
AfxGetApp().


Quote:
> > Yup, got it working perfectly now, much appreciated  (as always  :)

> Gah, one more dopey problem, I'd assumed that the child dialogs would be
> able to access a CStringArray declared in the main dialog that holds all
> the information I need, but it appears they can't.

> Where would I have to shift the declaration for the array to in order
> that every child dialog in the program is able to see it ?

> --
> Lordy
> http://www.overlord-uk.com/



Thu, 06 Nov 2003 11:07:07 GMT  
 Child Dialogs Pt II (params)
Allyou haveto do is include the main dialog's .h file, and declare the class:

#include whatever.h //goes at the top

CMainDialogclass d;
CConfirmDeleteDlg dlg(d.array);
int nResponse = dlg.DoModal();



Thu, 06 Nov 2003 11:08:23 GMT  
 Child Dialogs Pt II (params)

Quote:
> Allyou haveto do is include the main dialog's .h file, and declare the =
> class:

> #include whatever.h //goes at the top

> CMainDialogclass d;
> CConfirmDeleteDlg dlg(d.array);=20
> int nResponse =3D dlg.DoModal();

Must be having a particularly stupid morning today as neither of these
are making much sense to me at the mo (and msdn help is as typically
ambiguous as possible)   :(

--
Lordy
http://www.overlord-uk.com/



Thu, 06 Nov 2003 21:34:23 GMT  
 Child Dialogs Pt II (params)

Quote:
> Must be having a particularly stupid morning today as neither of these
> are making much sense to me at the mo (and msdn help is as typically
> ambiguous as possible)   :(

Any more pointers to get me going in the right direction (pref a
working example, heh)... ?

--
Lordy
http://www.overlord-uk.com/



Sat, 08 Nov 2003 01:27:06 GMT  
 Child Dialogs Pt II (params)

Quote:
> One possibility is the application, which you can always get with
> AfxGetApp().

Which part of AfxGetApp  ?

--
Lordy
http://www.overlord-uk.com/



Sat, 08 Nov 2003 04:30:19 GMT  
 Child Dialogs Pt II (params)
The return value.


Quote:
> > One possibility is the application, which you can always get with
> > AfxGetApp().

> Which part of AfxGetApp  ?

> --
> Lordy
> http://www.overlord-uk.com/



Sat, 08 Nov 2003 05:01:43 GMT  
 Child Dialogs Pt II (params)

Quote:
> > > One possibility is the application, which you can always get with
> > > AfxGetApp().

> > Which part of AfxGetApp  ?

> The return value.

You're being cryptic on purpose now   :)

As far as I can see, there are numerous ways to use it,
e.g. AfxGetApp()->DoMessageBox etc.
The pop up box that appears (intellisense?) does actually contain the
name of the CstringArray that I want (e.g. AfxGetApp()->a_BadgeDataArray)
, but using that brings back an error that it's not part of CWinApp.
I can't seem to work out a way to use it that will let me read and
(importantly) alter the contents of the main dialog's array.

Surely there's a way to declare a variable initially so that it is
visible throughout the whole program ?

--
Lordy
http://www.overlord-uk.com/



Sat, 08 Nov 2003 06:14:30 GMT  
 Child Dialogs Pt II (params)

Quote:

> > > > One possibility is the application, which you can always get with
> > > > AfxGetApp().

> > > Which part of AfxGetApp  ?

> > The return value.

> You're being cryptic on purpose now   :)

> As far as I can see, there are numerous ways to use it,
> e.g. AfxGetApp()->DoMessageBox etc.
> The pop up box that appears (intellisense?) does actually contain the
> name of the CstringArray that I want (e.g. AfxGetApp()->a_BadgeDataArray)
> , but using that brings back an error that it's not part of CWinApp.
> I can't seem to work out a way to use it that will let me read and
> (importantly) alter the contents of the main dialog's array.

> Surely there's a way to declare a variable initially so that it is
> visible throughout the whole program ?

Here is the way to declare the app object initially so that it is
visible throughout the whole program.

extern CYourAppClassHere theApp; // add to app.h after the class
declaration closes.

Now this will work:

  theApp.a_BadgeDataArray

--
Scott McPhillips [VC++ MVP]



Sat, 08 Nov 2003 09:08:11 GMT  
 Child Dialogs Pt II (params)
It was not my intent to be cryptic but I agree that my response was vague,
since I did not understand the question "Which part of AfxGetApp". I don't
mean to be critical either, since I know that sometimes asking a good
question sometimes requires knowing the answer.

I am still not sure what you are asking, but I think I understnad now. I
think that the problem is that AfxGetApp() returns a pointer to a CWinApp
class, not your derived CWinApp class. So you just need to do one of the
following, or an equivalent (where CLordyApp is your):

((CLordyApp *)AfxGetApp())->a_BadgeDataArray;

CLordyApp *pApp = (CLordyApp *)AfxGetApp();
pApp->a_BadgeDataArray;


Quote:
> > > > One possibility is the application, which you can always get with
> > > > AfxGetApp().

> > > Which part of AfxGetApp  ?

> > The return value.

> You're being cryptic on purpose now   :)

> As far as I can see, there are numerous ways to use it,
> e.g. AfxGetApp()->DoMessageBox etc.
> The pop up box that appears (intellisense?) does actually contain the
> name of the CstringArray that I want (e.g. AfxGetApp()->a_BadgeDataArray)
> , but using that brings back an error that it's not part of CWinApp.
> I can't seem to work out a way to use it that will let me read and
> (importantly) alter the contents of the main dialog's array.

> Surely there's a way to declare a variable initially so that it is
> visible throughout the whole program ?

> --
> Lordy
> http://www.overlord-uk.com/



Sun, 09 Nov 2003 04:39:04 GMT  
 
 [ 24 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Hide Taskbar Programmatically Pt. II

2. Raffle Pentium II 266 - Dream Machine - Benefits Children's Hospital

3. Pentium II 266 Copmuter Raffle - Dream Machine - Benefits Children's Hospital

4. Modal Dialogs II: Got the beeps, now want to handle WM_CHAR

5. Accessing a parent dialog's controls from a child modeless dialog

6. Problem: React on Child-Dialog from Parent-Dialog

7. who to control a main dialog by a child dialog

8. Passing values from Child dialog to Calling Dialog

9. Q: making a child dialog and dialog resources

10. How do I derive a child dialog from parent dialog

11. Closing dialog app from child dialog

12. Modeless Child Dialog of Modal Dialog

 

 
Powered by phpBB® Forum Software