Click here to Skip to main content
15,894,630 members
Articles / Desktop Programming / MFC

MFC/C++ Helper Class for Window Resizing

Rate me:
Please Sign up or sign in to vote.
4.91/5 (139 votes)
21 Oct 2014CPOL25 min read 663.2K   18.2K   385  
Gives you total control when it comes to resizing windows
// Example05Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "WndResizerApp.h"
#include "Example05Dlg.h"


// CExample05Dlg dialog

IMPLEMENT_DYNAMIC(CExample05Dlg, CDialog)

CExample05Dlg::CExample05Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CExample05Dlg::IDD, pParent)
{

}

CExample05Dlg::~CExample05Dlg()
{
}

void CExample05Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CExample05Dlg, CDialog)
END_MESSAGE_MAP()


// CExample05Dlg message handlers

BOOL CExample05Dlg::OnInitDialog()
{
  CDialog::OnInitDialog();

  BOOL bOk = FALSE;
  bOk = m_resizer.Hook(this);
  ASSERT( bOk);
  
  bOk = m_resizer.CreateSplitContainer(_T("MainSpliter"), IDC_FRAME_DEMO_H, IDC_FRAME_DEMO_V);
  ASSERT( bOk);

  bOk = m_resizer.SetAnchor(_T("MainSpliter"), ANCHOR_ALL);
  ASSERT( bOk);

  bOk = m_resizer.SetShowSplitterGrip(_T("MainSpliter"), TRUE);
  ASSERT( bOk);


  bOk = m_resizer.CreateSplitContainer(_T("SpliterH"), IDC_FRAME_LEFT, IDC_FRAME_RIGHT);
  ASSERT( bOk);

  bOk = m_resizer.SetShowSplitterGrip(_T("SpliterH"), TRUE);
  ASSERT( bOk);


  bOk = m_resizer.SetParent(_T("SpliterH"), IDC_FRAME_DEMO_H);
  ASSERT( bOk);

  bOk = m_resizer.SetAnchor(_T("SpliterH"), ANCHOR_ALL);
  ASSERT( bOk);

  bOk = m_resizer.CreateSplitContainer(_T("SpliterV"), IDC_FRAME_TOP, IDC_FRAME_BOTTOM);
  ASSERT( bOk);

  bOk = m_resizer.SetShowSplitterGrip(_T("SpliterV"), TRUE);
  ASSERT( bOk);

  bOk = m_resizer.SetParent(_T("SpliterV"), IDC_FRAME_DEMO_V);
  ASSERT( bOk);

  bOk = m_resizer.SetAnchor(_T("SpliterV"), ANCHOR_ALL);
  ASSERT( bOk);

  bOk = m_resizer.SetMinimumSize(IDC_FRAME_DEMO_H, CSize(150, 0)); // cy is ignored here
  ASSERT( bOk);

  bOk = m_resizer.SetMinimumSize(IDC_FRAME_DEMO_V, CSize(150, 0)); // cy is ignored here
  ASSERT( bOk);

  bOk = m_resizer.SetMinimumSize(IDC_FRAME_LEFT, CSize(60, 0)); // cy is ignored here
  ASSERT( bOk);

  bOk = m_resizer.SetMinimumSize(IDC_FRAME_RIGHT, CSize(60, 0)); // cy is ignored here
  ASSERT( bOk);

  bOk = m_resizer.SetMinimumSize(IDC_FRAME_TOP, CSize(0, 60)); // cx is ignored here
  ASSERT( bOk);

  bOk = m_resizer.SetMinimumSize(IDC_FRAME_BOTTOM, CSize(0, 60)); // cx is ignored here
  ASSERT( bOk);

  bOk = m_resizer.SetAnchor(IDOK, ANCHOR_RIGHT | ANCHOR_BOTTOM);
  ASSERT( bOk);

  bOk = m_resizer.SetAnchor(IDCANCEL, ANCHOR_RIGHT | ANCHOR_BOTTOM);
  ASSERT( bOk);

  m_resizer.SetShowResizeGrip(TRUE);

  bOk = m_resizer.InvokeOnResized();
  ASSERT( bOk);

  return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}


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
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions