Click here to Skip to main content
Licence 
First Posted 3 Nov 2002
Views 39,086
Bookmarked 15 times

Self-centering WTL property sheet

By | 3 Nov 2002 | Article
A small class to automatically center a WTL property sheet.

Introduction

This is a very simple class that will automatically center a WTL property sheet. One frequently-asked question in the various WTL forums is "How do I centre a CPropertySheet object?". Most people tend to add a GetParent().CenterWindow() call to the first page in the property sheet, but in my mind this is a little awkward.

Instead, simply #include "propertysheetex.h" and use CPropertySheetEx as a drop in replacement for the standard WTL CPropertySheet class.

Code

The actual code for the class is straightforward:

class CPropertySheetEx : public CPropertySheet
{
private:
    bool m_bCentered;
public:    
    CPropertySheetEx(WTL::_U_STRINGorID title = 
          (LPCTSTR)NULL, UINT uStartPage = 0, HWND hWndParent = NULL)
        : CPropertySheet(title, uStartPage, hWndParent), m_bCentered(false)
    {
    }
    
    BEGIN_MSG_MAP(CPropertySheetEx)
        MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
        CHAIN_MSG_MAP(CPropertySheet)
    END_MSG_MAP()

    LRESULT OnShowWindow(UINT /*uMsg*/, WPARAM wParam, 
          LPARAM /*lParam*/, BOOL& bHandled)
    {
        // Centre?
        if (wParam == TRUE)
            Center();
        // Ensure base-class gets this message
        bHandled = FALSE;
        return 0;
    }

    void Center(void)
    {
        // Only do this once
        if (!m_bCentered)
        {
            CenterWindow();
            m_bCentered = true;
        }
    }
};

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Rob Caldecott

Architect

United Kingdom United Kingdom

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThanks Pinmemberyunfei4:17 22 Aug '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 4 Nov 2002
Article Copyright 2002 by Rob Caldecott
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid