Re: CButton casts

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Stephen Howe (stephenPOINThoweATtns-globalPOINTcom)
Date: 03/27/04


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



Relevant Pages

  • Re: CLOS and C++
    ... > But Scott Meyers is not advocating making all class member variables ... (defclass-with-privates foo () ...
    (comp.lang.lisp)
  • Re: Visual C Cdialog.DoModal()
    ... The fast solution is to simply declare the dialog in the ... But unless this function needs access to class member variables (in which case ... Essentially, there is no need, as far as I can tell, to have the dialog member in the ... without a class instance there simply isn't ANY member variable you can talk about. ...
    (microsoft.public.vc.mfc)
  • Re: The reality of Topmind (Was: Topic-Organized Object-Oriented Programming)
    ... It is, simply, classifying all of a class' member variables and member ... suppose the class is "Human" (a class with member functions ... "hierarchy" and tree are the same goddam ...
    (comp.object)
  • Re: I want something weird
    ... > I now subclass it: ... > I do not wish to add a new member variable, ... Heightand other CRect member functions without having to ... There are no vertual member variables in C++, ...
    (microsoft.public.vc.mfc)
  • Re: class instances and threads
    ... >> I'd like to know if i need mutexs to lock the use of ... >> member methods of a class instance shared between ... Local variables of a method are not shared data, ...
    (comp.lang.cpp)