Click here to Skip to main content
15,881,812 members
Articles / Desktop Programming / MFC

Control Positioning and Sizing using a C++ Helper Class

Rate me:
Please Sign up or sign in to vote.
4.88/5 (43 votes)
20 Sep 2005CPOL11 min read 204.9K   4.1K   97  
Add layout management of controls to a CWnd or CDialog using a C++ helper class.
// Filename: TestCenteredDlg.h
// 2005-08-04 nschan Initial revision.

#ifndef TEST_CENTERED_DLG_INCLUDED
#define TEST_CENTERED_DLG_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// Forward class declarations.
class CLayoutHelper;
class CScrollHelper;

// CTestCenteredDlg is a resizable, scrollable dialog
// that uses both CScrollHelper and CLayoutHelper.
class CTestCenteredDlg : public CDialog
{
public:
    CTestCenteredDlg(CWnd* pParent = NULL);
    virtual ~CTestCenteredDlg();

    // Dialog data.
    //{{AFX_DATA(CTestCenteredDlg)
    //}}AFX_DATA

protected:
    virtual void PostNcDestroy();

    // ClassWizard generated virtual function overrides.
    //{{AFX_VIRTUAL(CTestCenteredDlg)
    virtual void DoDataExchange(CDataExchange* pDX);
    virtual BOOL OnInitDialog();
    virtual void OnOK();
    virtual void OnCancel();
    //}}AFX_VIRTUAL

    // Generated message map functions.
    //{{AFX_MSG(CTestCenteredDlg)
    afx_msg int  OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
    afx_msg void OnPaint();
    afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()

private:
    CLayoutHelper* m_layoutHelper;
    CScrollHelper* m_scrollHelper;
};

#endif // TEST_CENTERED_DLG_INCLUDED

// END

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions