CResizableDialog - What is it & Why?
I wrote my own class to implement resizable dialogs mostly as an exercise of
MFC and Windows programming. Later, I discovered that other people had written
similar classes, but I didn't find one I really like that was as simple as my
little projects.
Before you go any further, I have to warn you that I'm not a
"guru". Surely something could be done better, but I think this class
is at least easy to use.
The user will have the ability to resize the dialog, with consequent
rearrangement of child windows, and you can control the minimum and maximum
size allowed, as well as the maximized size and position of the dialog. The
size grip is displayed by default, but you may turn it off. Automatic Save/Restore
the dialog's size and position is also supported.
Conversion of a previously existant dialog should be very simple, as well as
creation of a new resizable dialog.
Now implemented with ResizableLib (see article).
The Sample Application
This is a view of the sample dialogs:

This is a composite view, where you can see the maximized position is not
the default:

You may see how to do this in the next section.
Usage - Step by Step
Add the ResizableLib to your project's workspace, as explained in the
relative article.
Create a dialog resource and associate it with a CDialog
derived class, for example using Class Wizard, or take a dialog you have
already made which you want to be resizable.
You no longer need to change the window style to have the dialog resizing.
Include 'ResizableDialog.h' in the associated header file.
Search and replace all CDialog occurrences with CResizableDialog
in both your .cpp and .h files, just as if your dialog class was derived from CResizableDialog
instead of CDialog. I think there's no way to let the Class Wizard
do this for you. Let me know if I'm wrong, please.
Your header file should appear like this:
#include "ResizableDialog.h"
class CMyDialog : public CResizableDialog
{
public:
CMyDialog(CWnd* pParent = NULL);
}
In your OnInitDialog override, add an anchor for each control
you want the size and/or position to be changed when the user resizes the
dialog.
BOOL CMyDialog::OnInitDialog()
{
CResizableDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
AddAnchor(IDOK, BOTTOM_RIGHT);
AddAnchor(IDCANCEL, BOTTOM_RIGHT);
AddAnchor(IDC_SPIN1, TOP_RIGHT);
AddAnchor(IDC_LABEL1, TOP_LEFT);
AddAnchor(IDC_EDIT1, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(IDC_RADIO1, BOTTOM_LEFT);
AddAnchor(IDC_RADIO2, BOTTOM_LEFT);
AddAnchor(IDC_GROUP1, BOTTOM_LEFT, BOTTOM_RIGHT);
Here you may also set a maximum size for your dialog (default is the
workspace area), a minimum size (default is the one you set in the resource
editor) and also a rectangle that the dialog occupies when maximized.
CRect rc;
GetDesktopWindow()->GetClientRect(&rc);
SetMaxTrackSize(CSize(rc.Width(), rc.Height()/2));
rc.bottom = 100;
SetMaximizedRect(rc);
After all this settings, you may wish the dialog's size and position to be
automatically saved and restored, as well as its maximized or minimized state.
Just provide a Section and an Entry name in your application's profile, in
which to save dialog's status.
EnableSaveRestore(_T("DemoDlg"));
You are ready to rebuild your project and you will have a resizable dialog
just as you wanted.
For further details, see the next section.
Class Reference
This class inherits from CResizableGrip, CResizableLayout, CResizableMinMax,
CResizableState and obviously from CDialog.

CResizableDialog::CResizableDialog
CResizableDialog()
CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL)
CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL)
-
The first is the default constructor.
The second and the third forms are needed to reproduce the
construction scheme of a CDialog derived class. Since the
dialog resource template is needed by the CDialog
constructor, you have to call one of these forms of the CResizableDialog
constructor. This is the reason why replacing one class with the other
will work.
CResizableDialog::EnableSaveRestore
void EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly = FALSE)
-
Enables automatic save/restore on dialog's open/close operations. The
arguments are the same as in CWinApp::WriteProfileString. If
bRectOnly is TRUE, the minimized/maximized
state is not saved/restored. Should be called after all the layout
settings.
If you want details on how this information is stored by your
application, look at CWinApp::SetRegistryKey, CWinApp::m_pszProfileName,
CWinApp::m_pszRegistryKey on MFC documentation.
CResizable???::???
- Implemented in the various base classes, see ResizableLib
article.
Conclusion
I would like to make this class more "integrated" with Class
Wizard, but I don't even know if it's possible. I hope this class can be useful
to other programmers that just want to have resizable dialogs with the minimum
effort.
I implemented a sort of percentage resizing. However, currently available
anchor types do not permit a high level of complexity, but should be enough in
many applications. If you want more flexibility or if your dialogs are very big
and full of controls, you may search CodeProject for another solution in this
same Section (see the top of the article).
The CVS tree is now on Source
Forge.
Updates
25 May 2000
- Initial public release.
31 May 2000
- Some unneeded code has been removed.
- Flickering has been reduced for Button, Static and ListBox controls.
- Save/Restore support has been added.
- Fixed a nasty bug that only came out with modeless dialogs.
9 Jun 2000
- Now compiles cleanly at warning level 4.
- Memory leak fixed. (I completely forgot to free memory)
- New type of anchorage now allowing more complex layouts. (compatible
with previous code)
- Fixed a bug with the size grip when hidden and when the dialog is
maximized.
- Better handling of controls that need repainting.
- Demo project updated to show new features.
11 Jul 2000
- Fixed a minor bug in save/restore functions. (standard maximized dialog
wasn't restored correctly)
27 Oct 2000
- Changed layout implementation (from CPtrList to CArray)
- Fixed a bug with controls that need refresh
23 Nov 2000
- Fixed a bug with multiple calls to DoModal()
- Removed doc from zip files (you simply save this page if you need it)
13 Mar 2001
- Fixed a bug with radio buttons and group boxes (thanks to Matt Philmon)
- Changed copyright note
11 Jun 2001
- New implementation and integration with ResizableLib
- Automatic resizing style (thanks to John Simmons)
- Added anti-flickering support
15 Jul 2001
- Updated to new ResizableLib release
- Demo project shows new grip implementation
28 Oct 2001
- Version 1.1 (CVS Tag: SF_1_1)
- Added static build configurations to all projects
| You must Sign In to use this message board. |
|
|
 |
|
 |
when parant dialog size is changed, child dialog size can change accordingly. is this class suitable for this case? if so, how to do? thanks Ricky
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Hi,
Now now am using CResizableFormView in my application.I need to set the size of the dialog according to the size of the main window.Because its an sdi application different dailogs are displayed at different times in the same window.So the dialog controls sholud be resized automatically.Please help..
Regards, thanks in advance,
John
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
Hi all, I am using resizablelib in my project.But while compiling it displays the message "Cannot open include file: 'ResizableDialog.h': No such file or directory".Please tell me what may be the reason???
regards, thanks in advance, john...
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
 |
when my app is set to use CDialog, all works fine. when i change CDialog to CResizableDialog, as described i get this error:
error C2440: 'type cast' : cannot convert from 'int (__thiscall MyDlg::*)(void)' to 'void (__thiscall CCmdTarget::*)(void)
why does it work with CDialog? Any ideas???
Thanks alot... Heiner
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
The function, where the error is pointed at, needs to be return type 'void' not 'int'.
Looks like some AFX_MSG ....
Hope that helps you.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, Great class, very useful. I want to create a few modeless dialogs at one time, can anyone see a problem with this?
Neil
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I try to use Windows XP Style , but the property pages have another size. any fix for Windows XP Style ?
Robert
|
| Sign In·View Thread·PermaLink | 2.50/5 |
|
|
|
 |
|
 |
Hi, Thanks for writing such a good library. I am using it and it works fine except When we minimize the window and then again maximize it the widht of the window increases by some amount. I am not able to figure it out. Please help!!
Sanat Tiwari
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Sanat,
A maximized window occupies all the screen. How can it grow in size? Or you mean minimize and then restore?
In this case, I can't figure out what happens there... Is it the main window size or the size of some controls?
Please add some details...
Paolo
------ Why spend 2 minutes doing it by hand when you can spend all night plus most of the following day writing a system to do it for you? - (Chris Maunder)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Yes u r correct.. minimize and then restore.. after restoring the widht of main window grows in size, also two group box controls grows in there width.
please help!!
Sanat
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This never happened to me. I really don't know...
Are you doing something unusual that could modify the window size?
Paolo
------ Why spend 2 minutes doing it by hand when you can spend all night plus most of the following day writing a system to do it for you? - (Chris Maunder)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This dialog class does not appear to have effect on the chris maunder grid control ? Or do I need to do some extra work on the grid class ?
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
 |
I've been using your CResizableDialog class for a couple months now, and I really appreciate how easy it makes it to make my program's main dialog dynamically resizable. Unfortunately, I've been getting reports from some people (both on ME and XP) that when starting up my program, it is only visible on the taskbar and they can't restore it. I'm using EnableSaveRestore with RectOnly=True, so I can't understand why that would be happening. As soon as the users deletes the registry key that saves the dialog's state, the program starts up fine. Please help; I'd rather not be forced to stop using this helpful class .
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Can you post the content of one of those registry keys and the ResizableLib version used? So I could try to reproduce it.
The suspect is that the saved position is invalid or off-screen, so maybe the problem is when the data is saved to the registry.
Paolo
------ Why spend 2 minutes doing it by hand when you can spend all night plus most of the following day writing a system to do it for you? - (Chris Maunder)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry about the delayed response; I had taken steps to avoid that problem (making window position remembering an option, defaulting to off), and didn't have a chance to find out a non-working registry key until now. Here's what the contents are of it:
-32000,-32000,-31287,-31475,1,0
I looked at all the source and header files of the ResizableLib code I'm using and couldn't find any version numbers; I was using the latest stable version (at least within a few weeks) at the time of my last post.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
 | Patch  Paolo Messina | 9:04 27 Jan '04 |
|
 |
Could it be a problem with multi-monitor systems only? If you attach a secondary monitor, move the window on it, close the application, remove the monitor and then open the app again, it may happen that your window looks like minimized, but it's actually out of the visible part of the screen. Someone reported this issue and that it doesn't happen with bRectOnly=FALSE. If you could confirm this I could think about a fix for the next (upcoming) version.
Otherwise it may be another bug. The fifth field in the registry key you reported should be 2 for SW_SHOWMINIMIZED. It may be that I'm saving the wrong position with bRectOnly=TRUE.
Thanks, Paolo
------ Temporary patch ------
BOOL CResizableState::SaveWindowRect(LPCTSTR pszSection, BOOL bRectOnly) { CString data; WINDOWPLACEMENT wp;
ZeroMemory(&wp, sizeof(WINDOWPLACEMENT)); wp.length = sizeof(WINDOWPLACEMENT); if (!GetResizableWnd()->GetWindowPlacement(&wp)) return FALSE; RECT& rc = wp.rcNormalPosition;
if (bRectOnly) { data.Format(PLACEMENT_FMT, rc.left, rc.top, rc.right, rc.bottom, SW_SHOWNORMAL, 0); } else { data.Format(PLACEMENT_FMT, rc.left, rc.top, rc.right, rc.bottom, wp.showCmd, wp.flags); }
return AfxGetApp()->WriteProfileString(pszSection, PLACEMENT_ENT, data); }
BOOL CResizableState::LoadWindowRect(LPCTSTR pszSection, BOOL bRectOnly) { CString data; WINDOWPLACEMENT wp;
data = AfxGetApp()->GetProfileString(pszSection, PLACEMENT_ENT); if (data.IsEmpty()) return FALSE; ZeroMemory(&wp, sizeof(WINDOWPLACEMENT)); wp.length = sizeof(WINDOWPLACEMENT); if (!GetResizableWnd()->GetWindowPlacement(&wp)) return FALSE;
RECT& rc = wp.rcNormalPosition;
if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top, &rc.right, &rc.bottom, &wp.showCmd, &wp.flags) == 6) { if (bRectOnly) { wp.showCmd = SW_SHOWNORMAL; wp.flags = 0; return GetResizableWnd()->SetWindowPlacement(&wp); } else { return GetResizableWnd()->SetWindowPlacement(&wp); } } return FALSE; }
It was actually a bug in the Load/SaveWindowRect functions. This is the fix, that will be included in the next version.
Paolo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I was just thinking to myself yesterday while I kicked and screamed at trying to get my stinking controls to stretch and grow the way I need them to that I really miss this class! MFC was my bread and butter for years and there are times when I really miss it. This class, to this day, remains the most heavily used piece of shared code I've ever downloaded.
Nowadays I'm 99.9% .NET (a pretty even mix of VB.NET and C#) with a little bit of old ATL COM still thrown into the mix on occasion and I'd give ANYTHING to have this project converted into a proper layout manager for Winforms for use in VB.NET and C#. The new features in Winforms for Docking and Anchoring are really great and do the job more often than not with very little effort... but there are so many times when they fall way short and I never came across a scenario with CResizableDialog that would not allow me to lay out my controls in the manner I frequently need to (more than 1 or 2 controls on a "line").
At any rate, if you do ever make the switch, PLEASE consider writing this for .NET.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Matt Philmon wrote: This class, to this day, remains the most heavily used piece of shared code I've ever downloaded.
Well, that's great. And thank you very much for showing your appreciation. 
Matt Philmon wrote: At any rate, if you do ever make the switch, PLEASE consider writing this for .NET.
Well, I must say that I still prefer the old VC++ 6.0 to the new .NET version and I'm not ready for the "switch" yet. What's more, the next version of this class library will be based on templates and I don't know to what extent I could use them on the .NET platform, if not at all. But, since MFC compatibility will be achieved with some adapter classes (and some specific for MFC) I suppose that there could be a way to build some .NET components with C++. Anyway, right now I wouldn't even know where to start. 
Paolo
------ Why spend 2 minutes doing it by hand when you can spend all night plus most of the following day writing a system to do it for you? - (Chris Maunder)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Paolo
Very useful implementation. However, I had the need to use an ActiveX Control (Component One's FlexGrid) in the dialog which caused an ASSERT failure when AddAnchor is called. Tested this with VideoSoft's Flexgrid with a similar result.
Is this known issue?
Thanks, Alex
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Please review the older posts about ActiveX controls, both in this and the ResizableLib article. Basically, you need to pass a HWND to the ActiveX control in the AddAnchor call.
Paolo
------ Why spend 2 minutes doing it by hand when you can spend all night plus most of the following day writing a system to do it for you? - (Chris Maunder)
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
 |
I've been using this for a while but I've found another class that I'd like to use for skinning the dialogs which also requires a find and replace of all the CDialog instances.
Is there a way to get them both working at the same time or a different way of doing it that might work?
If not, does anyone know how to get rid of the border if you set the dialog border property to resizable? If I'm using a transparent, or non-rectangular image for the dialog, I'd like to add a grip somewhere on the skin and hide the border.
Thanks, Don
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|