Example 1: Using Paulo Messina’s Code Project sample
A minimalist use of the CResizeableDialog class as described by Paulo Messina at CodeProject . Hope you find the following recipe useful. Visual Studio 2003 source code is downloadable from here.
1. Create a new MFC Project
3. Download the CodeProject library to a location of your choice.
6. In the Dialog code make sure CDialog is replaced with CResizeableDialog at the following appropriate points.
#include "ResizableDialog.h"
// CDialogDlg dialog
class CDialogDlg : public CResizableDialog
{
// Construction
public:
CDialogDlg(CWnd* pParent = NULL); // constructor
// Dialog Data
enum { IDD = IDD_DIALOG_DIALOG };
protected:
// DDX/DDV support
virtual void DoDataExchange(CDataExchange* pDX);
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
};
Basically replace all instances of CDialog with CResizableDialog, except in CAboutDlg of course.
7. Add the dependencies needed to build the project. In Project Properties-> C/C++ -> General -> Additional Include Directories:
// Initialize anchor points AddAnchor(IDOK, BOTTOM_RIGHT); AddAnchor(IDCANCEL, BOTTOM_RIGHT); AddAnchor(IDC_EDIT1, TOP_LEFT, BOTTOM_RIGHT); // Set max tracking size to half a screen CRect rc; GetDesktopWindow()->GetClientRect(&rc); SetMaxTrackSize(CSize(rc.Width(), rc.Height())); // Set max. position and size on top of the screen rc.bottom = 200; SetMaximizedRect( rc );
Example 2: Stack Overflow posting
Courtesy of Mark Ransom. Some things things needed to use this class are:
1. Set your dialog style to include WS_THICKFRAME:
IDD_DIALOGRESIZE_DIALOG DIALOGEX 0, 0, 215, 178
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP |
WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "DialogResize"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
LISTBOX IDC_LIST1,35,35,143,99,LBS_SORT |
LBS_NOINTEGRALHEIGHT |
WS_VSCROLL | WS_TABSTOP
END
2. Make your dialog class derives from the CResizableDialog base class:
// CDialogResizeDlg dialog class CDialogResizeDlg : public CResizableDialog
3. In your InitDialog function call the AutoMove function for each child control to define how much it should move and how much it should resize relative to the parent dialog. Use this example to ‘stretch’ the dialog child controls from a fixed position:
AutoMove( IDC_LIST1, 0, 0, 100, 100 );
4. In the dialog class you are using (not the CResizable base class), replace all instances of CDialog with CBaseDialog.
Example VS2003 code downloadable from here.
In Example 2, CDialog should be replaced with “CBaseDialog”, and not “CResizableDialog”, of course.
Thanks for the good directions for both examples.
Yep, you’re right. WIll update this. Cheers!
Andy
The links to the VS2003 code are broken, by the way. (Not that it’s much of a problem, since the “hand-holding” {grin} is so well done for the examples – I built the two examples in VC6 anyway.)
Download links now fixed. Thanks for pointing this out! Andy