|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
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 ApplicationThis 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 StepAdd the ResizableLib to your project's workspace, as explained in the relative article. Create a dialog resource and associate it with a 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 Your header file should appear like this: // MyDialog.h : header file // // ( Class Wizard stuff ) ///////////////////////////////////////////////////////////////////////////// // CMyDialog dialog #include "ResizableDialog.h" class CMyDialog : public CResizableDialog { // Construction public: CMyDialog(CWnd* pParent = NULL); // standard constructor // ( other stuff ) // ... } In your BOOL CMyDialog::OnInitDialog()
{
CResizableDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this
// automatically when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// preset layout
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);
// other initializations
// ...
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. // get desktop size CRect rc; GetDesktopWindow()->GetClientRect(&rc); // set max tracking size to half a screen SetMaxTrackSize(CSize(rc.Width(), rc.Height()/2)); // maximized position and size on top of the screen 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. // save/restore // (for dialog based app, default is a .INI file with // the application's name in the Windows directory) 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 ReferenceThis class inherits from CResizableGrip, CResizableLayout, CResizableMinMax, CResizableState and obviously from CDialog.
CResizableDialog::CResizableDialogCResizableDialog() CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL) CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL)
CResizableDialog::EnableSaveRestorevoid EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly = FALSE)
CResizable???::???
ConclusionI 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.
Updates25 May 2000
31 May 2000
9 Jun 2000
11 Jul 2000
27 Oct 2000
23 Nov 2000
13 Mar 2001
11 Jun 2001
15 Jul 2001
28 Oct 2001
|
||||||||||||||||||||||