CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2004
    Posts
    31

    MFC Dialog Problem

    Hi there,
    Now I have a parent dialog which has a tab control in it and I have a child dialog with a combobox in it. And the child is linked to the parent and the child doesn't have OnInitDlg() function. So if I want to change the font size of the combobox in the child dialog, I would need to change it in the parent dialog (if I'm correct to say that). Now in the parent dialog, inside the OnInitDlg() function, I wrote this:

    CClientDC dc ( this ) ;
    LOGFONT lf ;
    memset ( &lf, 0, sizeof ( LOGFONT ) ) ;
    lf.lfHeight = 100 ;
    lf.lfWeight = FW_BOLD ;
    strcpy ( lf.lfFaceName, "Verdana" ) ;

    VERIFY ( m_font.CreatePointFontIndirect ( &lf, &dc ) );

    ( ( CStatic* ) GetDlgItem ( IDC_COMBO_TIME ) ) -> SetFont ( &m_font ) ;

    And when I run it, it gave me error message. Is there any way I could do to change the font of the combobox in the child dialog??

    Any help will be appreciated.

    Thanks.
    Cheers

    -one-

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    1. You don't need to use CClientDC dc;
    2. Why do you cast your GetDlgItem ( IDC_COMBO_TIME ) ) to CStatic* if you want "to change the font of the combobox"?
    3.
    And the child is linked to the parent and the child doesn't have OnInitDlg() function. So if I want to change the font size of the combobox in the child dialog, I would need to change it in the parent dialog
    If your child dialog "doesn't have OnInitDlg() function" - just to add it! Open Class Wizard and add the message handler WM_INITDIALOG for your child. The you could change the font of your child dialog controls in this OnInitDialog().

    Otherwise, you will have what you have had - nothing!

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: MFC Dialog Problem

    Originally posted by Rivaldo
    the child doesn't have OnInitDlg() function.
    Can't you just give it one? That would be the obvious place to do what you want. If you're trying to run your code from the parent dialog, it will be looking for a control called IDC_COMBO_TIME in the parent dialog (which doesn't have such a control, from your explanation).
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #4
    Join Date
    Mar 2004
    Posts
    31
    Thanks guys for all the helps.

    In the child dialog, there's no WM_INITDIALOG for me to select. So what do I have to do in order to change the font of the child?

    Thanks again.

    Cheers.

    -one-

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    In the child dialog, there's no WM_INITDIALOG for me to select
    Try to select "Dialog" in combobox "Filter for messages available to class" and the WM_INITDIALOG must appear.

  6. #6
    Join Date
    Jul 2003
    Posts
    116
    you can also subclass it..... but that wud be like sending forces to Iraq, a **** to manage....
    like y do it the other way when there are simple and easy ways for that..
    this is given as an option only....dont try it at home
    cheers

  7. #7
    Join Date
    Mar 2004
    Posts
    31
    Millions of thanks guys. I think create the OnInitDlg() in the child dialog works. Beer for everyone. Cheers

    -one-

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