dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Changing font of Property Sheet dialog

  1. #1
    Join Date
    Mar 2001
    Location
    St. Petersburg, Russia
    Posts
    5

    Changing font of Property Sheet dialog

    Have you ever tried to play with dialog font settings in the Resorce Editor?
    If so, you have probably noticed that those settings have no effect on Property Pages. MFC simply ignores those settings and forces Property Pages to use the system font instead. But this is only half a problem. Unfortunately, the Windows Property Sheet control was designed so that it always uses the system font for the sheet. So the main problem is that we need to specify somehow the desired font for the Property Sheet itself!

    The only solution I have found so far is described in MSDN article "PRPFONT - How to Set CPropertySheet Fonts". But the weakness of this solution is that it changes font and size of Property Pages AFTER CPropertyPage::OnInitDialog() was called.

    Below is skeleton of my solution which is more compact and have no weakness I have just mentioned. But I doubt if it is allowed to modify Property Sheet dialog template as I did it in CMyPropertySheet::PropSheetProc()... and that is my question.

    Code:
    class CMyPropertySheet : public CPropertySheet
    {
        // ...
    public:
        virtual int DoModal();
    
    protected:
        virtual void BuildPropPageArray();
    
    protected:
        static int CALLBACK PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam );
    }
    
    class CMyDialogTemplate : public CDialogTemplate
    {
    public:
        void Attach( LPDLGTEMPLATE pTemplate );
    }
    
    LPCTSTR lpszFace = _T("Tahoma");
    const WORD wSize = 8;
    
    int CMyPropertySheet::DoModal() 
    {
        m_psh.dwFlags |= PSH_USECALLBACK;
        m_psh.pfnCallback = PropSheetProc;
    
        return CPropertySheet::DoModal();
    }
    
    void CMyPropertySheet::BuildPropPageArray()
    {
        CPropertySheet::BuildPropPageArray();
    
        AFX_OLDPROPSHEETPAGE* ppsp = ( AFX_OLDPROPSHEETPAGE* )m_psh.ppsp;
        for ( int nPage = 0; nPage < m_pages.GetSize(); nPage++ )
        {
            LPDLGTEMPLATE pTemplate = ( LPDLGTEMPLATE )ppsp[ nPage ].pResource;
    
            CMyDialogTemplate dlgTemplate;
            dlgTemplate.Attach( pTemplate );
            dlgTemplate.SetFont( lpszFace, wSize );
            dlgTemplate.Detach();
        }
    }
    
    int CALLBACK CMyPropertySheet::PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam )
    {
        switch ( uMsg )
        {
            case PSCB_PRECREATE:
            {
                LPDLGTEMPLATE pTemplate = ( LPDLGTEMPLATE )lParam;
    
                CMyDialogTemplate dlgTemplate;
                dlgTemplate.Attach( pTemplate );
                dlgTemplate.SetFont( lpszFace, wSize );
                dlgTemplate.Detach();
                break;
            }
            default:
                break;
        }
    
        return 0;
    }
    
    void CMyDialogTemplate::Attach( LPDLGTEMPLATE pTemplate )
    {
        m_hTemplate      = ::GlobalHandle( pTemplate );
        m_dwTemplateSize = GetTemplateSize( pTemplate );
        m_bSystemFont    = false;
    }
    Regards,
    Nikolay
    Last edited by cilu; February 5th, 2008 at 04:54 AM.

  2. #2
    Join Date
    Sep 2006
    Posts
    1

    Smile Re: Changing font of Property Sheet dialog

    Thank you

  3. #3
    Join Date
    Feb 2010
    Posts
    1

    Re: Changing font of Property Sheet dialog

    Hi Nikolay Denisov,
    Thanks for such a good article. Its really helpful in oneof my application.
    Your solution is working very fine with CPropertySheet. but unfortunately, this soultion is not working fine in CMFCPropertysheet.
    Do you have any idea how to set the font in CMFCPropertysheet? Please reply if you have any idea. Thanks

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Changing font of Property Sheet dialog

    Are you aware you are asking this in a 9 year old thread? You're saying the solution is not working "fine" with CMFCPropertysheet. Does something work, though?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)