CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Aug 2002
    Posts
    173

    OnInitDialog not called

    Hello,

    I have a dialog in my application. I am bringing it up by calling DoModal method. The dialog does show up. However, OnInitDialog is never called. Any reason why would this happen?

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    This is virtually impossible...can you post your project here (excluding the debug and release directory)?

  3. #3
    Join Date
    Feb 2004
    Location
    Punalur Kerala
    Posts
    1
    This is impossible.. u pls use RebuildAll from the Build menu. and try to debug it.

    jim

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    Sounds to me like your OnInitDialog declaration in your dialog isn't the same as the virtual function in CDialog.

    It should be

    Code:
    BOOL OnInitDialog();
    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    How do you know it isn't called?
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #6
    Join Date
    Feb 2004
    Location
    Portland, OR
    Posts
    13
    In MFC Visual Studio, build the project in Debug mode and set a breakpoint in your OnInitDialog() function.

    Otherwise, use a MessageBox(NULL, "In InitDialog", 0, 0 ) as the first line in InitDialog() to see if it pops up when you run the program.
    Andrew Ferlitsch

  7. #7
    Join Date
    Aug 2002
    Posts
    173
    The declaration is as follows:

    virtual BOOL OnInitDialog();

    One reason I know it is not being called is that I have a break point in OnInitDialog method but it is never invoked. I have a break point in the constructor of the dialog which IS invoked.

    Another reason I know it is not being called is that the stuff I want to happen in OnInitDialog isn't happen. It is supposed to disable some controls, set context-sensitivie help IDs and initialize some member variables. All of that doesnt happen.

    The most bizarre thing is that the dialog does show up. All the controls are there, although the ones that should be disabled arent and they have no context-sensitive help (because OnInitDialog is never called)

    By the way, my dialog is dervied from CFileDialog and it is using a dialog template resource. Basically, what I am doing is adding a couple of controls to standard file dialog.

  8. #8
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by kzseattle
    By the way, my dialog is dervied from CFileDialog and it is using a dialog template resource. Basically, what I am doing is adding a couple of controls to standard file dialog.
    Well you did not tell us that. Of course OnInitDialog is not called.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  9. #9
    Join Date
    Aug 2002
    Posts
    173
    But OnInitDialog is a virtual function and CFileDialog is derived from CDialog and my dialog is derived from CFileDialog. So why wouldnt OnInitDialog be called? I dont thing it is a correct statement to say that OnInitDialog is not invoked for CFileDialog-derived classes. How else could one initialize the controls then?

  10. #10
    Join Date
    Sep 2003
    Location
    Sydney, Australia
    Posts
    80
    Originally posted by kzseattle
    But OnInitDialog is a virtual function and CFileDialog is derived from CDialog and my dialog is derived from CFileDialog. So why wouldnt OnInitDialog be called? I dont thing it is a correct statement to say that OnInitDialog is not invoked for CFileDialog-derived classes. How else could one initialize the controls then?

    Have you created a Message Map to WM_INITDIALOG in your CFileDialog-derived class? Maybe you added OnInitDialog() by hand. Try using the class wizard (Ctrl+W).

    Hope that helps.

    _msd_
    While memory is getting abundant, it is not an excuse for wasting it with bad programming design/practice.

  11. #11
    Join Date
    Aug 2002
    Posts
    173
    For OnInitDialog method, you dont need to add a message map entry of WM_INITDIALOG. The framework is supposed to call this method anyway.

  12. #12
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by kzseattle
    For OnInitDialog method, you dont need to add a message map entry of WM_INITDIALOG. The framework is supposed to call this method anyway.
    Yes, everything you say is correct. I am sorry I doubted you. I had forgotten that CFileDialog calls OnInitDialog like other dialogs do.

    So I don't know why OnInitDialog is not being called. The only possibility is that there are two instances of your CFileDialog.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  13. #13
    Join Date
    Sep 2010
    Posts
    29

    Re: OnInitDialog not called

    UP - I've got the same problem.

  14. #14
    Join Date
    Apr 2009
    Posts
    598

    Re: OnInitDialog not called

    We've got the same answers !
    (show your lines)

  15. #15
    Join Date
    Sep 2010
    Posts
    29

    Talking Re: OnInitDialog not called

    But I've got the answer!
    Set m_bVistaStyle to FALSE.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured