Re: CButton casts
From: Stephen Howe (stephenPOINThoweATtns-globalPOINTcom)
Date: 03/27/04
- Next message: Stephen Howe: "Re: CButton casts"
- Previous message: Paul McLeish: "Tooltip trouble in win98"
- In reply to: Joseph M. Newcomer: "Re: CButton casts"
- Next in thread: Jeff Partch [MVP]: "Re: CButton casts"
- Reply: Jeff Partch [MVP]: "Re: CButton casts"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 27 Mar 2004 14:07:51 -0000
> I consider using GetDlgItem to be a design error. You can avoid the whole
problem by
> using control variables. See my essay "Avoiding GetDlgItem".
I have seen, and swapped. Thanks
> So the answer is, you don't have a problem if you don't use that
technique.
Oh yes, I do. It has it's problems.
In the traditional
>>>>>>>>>>>>>>>>>>>>>>>>>
CMyDialog dlg;
// Set dialog members here (or develop the constructor with extra
parameters - the C++ way: why bother initialising things twice?)
dlg.DoThis(var1);
dlg.DoThat(var2);
:
if (dlg.DoModal() == IDOK)
{
newvar1 = dlg.GetThis();
newvar2 = dlg.GetThat();
:
}
>>>>>>>>>>>>>>>>>>>>>>>>>
with
dlg.DoThis(var1);
I cannot directly intialise a control variable, because DoDataExchange()
which calls DDX_Control() has not been called; DoDataExchange() has not
been called because OnInitDialog() has not been called; OnInitDialog() has
not been called because it is only called when DoModal() is called. You
can't set any of this earlier as the hWnd of the control member variables
like CEdit, ClistBox is still 0.
So it seems it is necessary to intialise some temporary member variables
using
dlg.DoThis(var1);
so that in OnInitDialog() I can now initialise the _real_ control member
variables in OnInitDialog() - in essence a piggy back operation is required.
This seems a complete botch up.
What would be ideal would be
>>>>>>>>>>>>>>>>>>>>>>>>>
CMyDialog dlg(var1, var2, var3, ..., pParentWnd);
// and at this point, anything static in the dialog box is already
intialised, including all member controls. That would mean, that in your
article, there would be no need to test in On... Message handlers and
returning - if it is still in the initalisation phase, it would have been
done. The OnInitDialog() would be reserved for anything dynamic, not yet
initialised - it would be mostly empty, only CDialog::OnInitDialog() would
need calling.
if (dlg.DoModal() == IDOK)
{
newvar1 = dlg.GetThis();
newvar2 = dlg.GetThat();
:
}
>>>>>>>>>>>>>>>>>>>>>>>>>
Stephen Howe
- Next message: Stephen Howe: "Re: CButton casts"
- Previous message: Paul McLeish: "Tooltip trouble in win98"
- In reply to: Joseph M. Newcomer: "Re: CButton casts"
- Next in thread: Jeff Partch [MVP]: "Re: CButton casts"
- Reply: Jeff Partch [MVP]: "Re: CButton casts"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|