15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CDialog inheritance

David Simpson -- dsimpson@cwb.com
Thursday, October 24, 1996

     Environment: Windows NT 3.51, VC 4.2a
     
     We are developing a client application as a front 
     end for a database.
     
     In this app we have a number of similar dialogs. 
     Being of O-O mind, I decided to create a base dialog 
     class derived from CDialog withan associted dialog 
     resource. In this class I carry out various common 
     operations like manipulating list controls.
     
     I then derived from this class a number of dialogs 
     that are used in the app. All dialogs use the same 
     dialog resource defined in CSearchDlg.
     
     
                 +-------------+
                 |   CDialog   |
                 +-------------+
                        |
                        ^                 this is my
                       / \                sad attempt
                       ---                at an OMT model
                        |                 in ASCII
                 +-------------+
                 | CSearchDlg  |
                 +-------------+
                        |
                        ^
                       / \
                       ---
              +---------|----------+ 
              |                    |
              |                    |
       +-------------+    +----------------+ 
       |   CSearch1  |    |    CSearch2    | 
       +-------------+    +----------------+
     
     The problem:
     Having instantiated for example CSearch1: when 
     OnInitDialog gets called for CSearchDlg the member 
     variables set up for say a list control in CSearchDlg 
     do not have an attached m_hWnd. ie. any calls to 
     manipulate the list via the member variable fail on an 
     assertion checking for m_hWnd != NULL.
     
     If I instantiate CSearchDlg directly - no problem.
     
     I can work round this using the old method of 
     GetDlgItem, and yes I know that maybe inheriting 
     dialog classes and expecting DDX to work through 
     the inheritance is pushing my luck.
     
     However, I was wondering if anyone can explain 
     this behavior.
     
     -----------------------------------
      David Simpson
      E-Mail - dsimpson@cwb.com
     -----------------------------------




Mike Blaszczak -- mikeblas@nwlink.com
Sunday, October 27, 1996

[Mini-digest: 2 responses]

At 18:06 10/24/96 GMT, David Simpson wrote:
>     Environment: Windows NT 3.51, VC 4.2a

There is no such product as VC 4.2a.  Do you mean that you're using MFC 4.2a?
If so, please upgrade to MFC 4.2b; MFC 4.2a is beta software, and since the
final MFC 4.2b release has hit the streets, 4.2a is unsupported and
inappropriate for use.
    
>     The problem:
>     Having instantiated for example CSearch1: when 
>     OnInitDialog gets called for CSearchDlg the member 
>     variables set up for say a list control in CSearchDlg 
>     do not have an attached m_hWnd. ie. any calls to 
>     manipulate the list via the member variable fail on an 
>     assertion checking for m_hWnd != NULL.

The simplest 
     
>     and yes I know that maybe inheriting 
>     dialog classes and expecting DDX to work through 
>     the inheritance is pushing my luck.

Why do you think that is pushing your luck?

>     However, I was wondering if anyone can explain 
>     this behavior.

Have you tried doing any debugging?  That is, have you tried putting
a breakpoint on CSearch1::DoDataExchange() to see what it does?  If
it, itself, doesn't do any DDX_ for the controls you're worried about
_and_ it doesn't call the base class implementation of DoDataExchange(),
this is exactly your problem.

The m_hWnd members of "has-a" control objects in a CDialog-derived object
are initialized DDX_Control() calls in DoDataExchange().

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.

-----From: "Doug Brubacher" 

     David,
     
     Until the base case function CDialog::OnInitDialog() is called the 
     dialog and its child windows have not really been created thus as you 
     have noticed all the Window handles are NULL.  The Class wizard 
     generated code automatically adds this call as the first call in your 
     class's override of OnInitDialog().  As we see from this sample.
     
     BOOL CTestdlg::OnInitDialog() 
     {
        CDialog::OnInitDialog();
        
        // TODO: Add extra initialization here
        
        return TRUE;  // return TRUE unless you set the focus to a control
                      // EXCEPTION: OCX Property Pages should return FALSE
     }
     
     Thus in your derived classes CSearch1 and CSearch2 you should either 
     explicitly call CSearchDlg:OnInitDialog() (which presumably will be 
     calling CDialog::OnInitDialog()) or if you wish to by-pass the code in 
     your base class completely, your override CSearch1::OnInitDialog() 
     needs to call CDialog::OnInitDialog() itself.
     
     Regards
     
     Doug Brubacher
     DouglasB@msn.com




Jim Barry -- Jim.Barry@ilp.com
Monday, October 28, 1996

[Mini-digest: 2 responses]


On 24 October 1996 18:06, David Simpson[SMTP:dsimpson@cwb.com] wrote:
>      Environment: Windows NT 3.51, VC 4.2a
>
>      We are developing a client application as a front
>      end for a database.
>
>      In this app we have a number of similar dialogs.
>      Being of O-O mind, I decided to create a base dialog
>      class derived from CDialog withan associted dialog
>      resource. In this class I carry out various common
>      operations like manipulating list controls.
>
>      I then derived from this class a number of dialogs
>      that are used in the app. All dialogs use the same
>      dialog resource defined in CSearchDlg.
>
>
>                  +-------------+
>                  |   CDialog   |
>                  +-------------+
>                         |
>                         ^                 this is my
>                        / \                sad attempt
>                        ---                at an OMT model
>                         |                 in ASCII
>                  +-------------+
>                  | CSearchDlg  |
>                  +-------------+
>                         |
>                         ^
>                        / \
>                        ---
>               +---------|----------+
>               |                    |
>               |                    |
>        +-------------+    +----------------+
>        |   CSearch1  |    |    CSearch2    |
>        +-------------+    +----------------+
>
>      The problem:
>      Having instantiated for example CSearch1: when
>      OnInitDialog gets called for CSearchDlg the member
>      variables set up for say a list control in CSearchDlg
>      do not have an attached m_hWnd. ie. any calls to
>      manipulate the list via the member variable fail on an
>      assertion checking for m_hWnd != NULL.
>
>      If I instantiate CSearchDlg directly - no problem.
>
>      I can work round this using the old method of
>      GetDlgItem, and yes I know that maybe inheriting
>      dialog classes and expecting DDX to work through
>      the inheritance is pushing my luck.
>
>      However, I was wondering if anyone can explain
>      this behavior.
>
>      -----------------------------------
>       David Simpson
>       E-Mail - dsimpson@cwb.com
>      -----------------------------------
>

Make sure you are calling CSearchDlg::DoDataExchange rather than   
CDialog::DoDataExchange during your CSearch1::DoDataExchange.

Cheers,

 - Jim  
-----From: Roger Onslow/Newcastle/Computer Systems Australia/AU

You need to call the base class OnInitDialog before trying to access and 
members.
Also you could try defining an OnInitDialog for CSearch1 that simply calls the 
base CSearchDlg::OnInitDialog.
And make sure that CSearchDlg::OnInitDialog calls its base class as well.

Roger



rick cameron -- rick_cameron@msn.com
Thursday, October 31, 1996

Hi, David

I've done this sort of thing successfully. You need to ensure that 
CSearch1::OnInitDialog calls CSearchDlg::OnInitDialog, and that 
CSearch1::DoDataExchange calls CSearchDlg::DoDataExchange.

- rick

owner-mfc-l@majordomo.netcom.com on behalf of David Simpson wrote:
>      Environment: Windows NT 3.51, VC 4.2a
>      
>      We are developing a client application as a front 
>      end for a database.
>      
>      In this app we have a number of similar dialogs. 
>      Being of O-O mind, I decided to create a base dialog 
>      class derived from CDialog withan associted dialog 
>      resource. In this class I carry out various common 
>      operations like manipulating list controls.
>      
>      I then derived from this class a number of dialogs 
>      that are used in the app. All dialogs use the same 
>      dialog resource defined in CSearchDlg.
>      
>      
>                  +-------------+
>                  |   CDialog   |
>                  +-------------+
>                         |
>                         ^                 this is my
>                        / \                sad attempt
>                        ---                at an OMT model
>                         |                 in ASCII
>                  +-------------+
>                  | CSearchDlg  |
>                  +-------------+
>                         |
>                         ^
>                        / \
>                        ---
>               +---------|----------+ 
>               |                    |
>               |                    |
>        +-------------+    +----------------+ 
>        |   CSearch1  |    |    CSearch2    | 
>        +-------------+    +----------------+
>      
>      The problem:
>      Having instantiated for example CSearch1: when 
>      OnInitDialog gets called for CSearchDlg the member 
>      variables set up for say a list control in CSearchDlg 
>      do not have an attached m_hWnd. ie. any calls to 
>      manipulate the list via the member variable fail on an 
>      assertion checking for m_hWnd != NULL.
>      
>      If I instantiate CSearchDlg directly - no problem.
>      
>      I can work round this using the old method of 
>      GetDlgItem, and yes I know that maybe inheriting 
>      dialog classes and expecting DDX to work through 
>      the inheritance is pushing my luck.
>      
>      However, I was wondering if anyone can explain 
>      this behavior.
>      
>      -----------------------------------
>       David Simpson
>       E-Mail - dsimpson@cwb.com
>      -----------------------------------
> 
> 





| Вернуться в корень Архива |