The dynamic screen classes allow you to incorporate advanced screen functionality into your MFC applications.
The fundamental difference of these classes are that they work with the actual resource in your executable - this means that users of your applications can alter screens that have been designed by you using the MFC resource editor - they can make changes at run time.
These classes are ideal if you develop/are developing applications that require the ability to have additional fields that can be defined by users to store data that is unique to them, or perhaps to remove some of the fields which you have anticipated they may need.
The classes are designed so they are easily incorporated into your existing applications; this allows your existing programs to be modified quite quickly to incorporate the functionality. The classes based on templates and will work with dialogs, views and property pages.
Using the code
The classes are supplied with source code. Unfortunately like most V1.00 products, I have not spent an awful amount of time on the documentation, however I have explained the pertinent points – which are you will see when you run through building a sample program.
This version also has a lot of functionality that I am currently perfecting. For example:
- I am doing some work so the screen designer works with any type of derived window classes, Dialog, Property Pages, etc.
- I am working on storing the actual definition in a database or XML file so that changes that are made to the screens are permanent and returned when the application is next run.
- Controls can be configured to retrieve and save data from database field so users can decide at runtime where the data for a newly created control should be loaded and saved from.
- Make it work in Visual Studio .NET environment.
I know these are key features – but I thought that you might appreciate the code even if it was not fully “polished” – and it gives me an opportunity to get some feedback so I can improve the classes in line with demand.
If you do want to be notified when the “polished” version is finished or you have some useful comments for me then please drop me an e-mail at email@example.com.
There are a number of ways you can use the screen designer classes, I have written a small application that shows how you would use it in a
CFormView application. The sample is called FV and has been compiled with VC6.
The FV application is provided pre-built in EXE format. To use the program:
- Run it
- Choose screen designer from the view menu. Once you have re-arranged the screen or added new controls swap back to normal mode by choosing screen designer from the view menu again.
Build a new Application
The steps below re-create the functionality in the FV application; it takes about 10 minutes to run through and is worth it if you want to see what could be possible in your own applications. The example is also provided in full in the samples directory – so you can just follow the instructions below if you prefer.
Step 1 – MFC AppWizard
- Within VC6 create a new MFC AppWizard (exe). Call the project NewExample.
- On step 1 of the wizard, change the application to a single document.
- Leaver the other steps as default, but change step 6 so the base class for
Step 2 – Modify The Resource
- After the application has been created modify the resource for
IDD_NEWEXAMPLE_FORM – add some additional controls, so it resembles the screen below.
- Build and make sure the application runs.
Step 3 – Add Screen Designer Application to the sample program
- Copy all the files from AddToYourProject into your application's directory.
- Add the files to your project, use the menu option: Project, Add To Project, Files and choose all the files which match Dyn*.*.
- Open dynscreen.rc in the directory UseInYourProject and copy across the resource from this resource file into your own. If you have never done this before then switch to the resource tab on the left hand side, and drag and drop the resources from the right hand side a folder at a time.
- Close the dynscreen.rc window, be careful not to save the changes.
- In the file CnewExampleApp.cpp modify the
InitInstance() member function add the line
AfxOleInit(); as the first line.
- In stdafx.h add the following lines at the bottom:
- Build your project: it should build with no errors. If it errors check the previous steps have been completed in full.
- Add a new menu option called Screen Designer to the
- Add a command handler for
ID_SCREEN_DESIGNER to the
CMainFrame class. You can do this by holding the CTRL key and double clicking on the Screen Designer menu option when in the resource editor.
- In the command handler for
ID_SCREEN_DESIGNER add the following code:
BOOL bVisible = ((m_wndDynControlBar.GetStyle() & WS_VISIBLE) != 0);
m_wndDynControlBar.m_bMakingVisible = TRUE;
ShowControlBar(&m_wndDynControlBar, !bVisible, FALSE);
m_wndDynControlBar.m_bMakingVisible = FALSE;
SendMessageToDescendants(WM_SCREENDESIGNER, !bVisible, 0, TRUE, <BR> TRUE);
- In MainFrm.h add the following include:
- In MainFrm.h add the following line in the declaration, you can do it after the line which defines
- Change the MainFrm.cpp class so the
OnCreate function looks like the one shown below. The complete function is shown but only the sections marked "// Screen designer control bar" need to be inserted.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE
| CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY
| CBRS_SIZE_DYNAMIC) ||
TRACE0("Failed to create toolbar\n");
return -1; }
if (!m_wndStatusBar.Create(this) ||
TRACE0("Failed to create status bar\n");
return -1; }
if (!m_wndDynControlBar.CreateEx(this) ||
TRACE0("Failed to create toolbar\n");
return -1; }
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
CString strText("Screen Designer");
ShowControlBar(&m_wndDynControlBar, FALSE, FALSE);
- In CNewExampleView.h include the header file
- In CNewExampleView.h change the class declaration line to:
class CNewExampleView : public CDynWnd<CFormView>
- In CNewExampleView.cpp change the
BEGIN_MESSAGE_MAP line to
- In CNewExampleView.cpp change the constructor to read
CNewExampleView::CNewExampleView(): <BR> CDynWnd<CFormView>(CNewExampleView::IDD)
Rebuild the project. Once you have done this run the application. You will be able to toggle between normal mode and screen designer mode by choosing the screen designer option from the menu.
If you want to know when the next version is available and what’s planned or have some useful suggestions please post a message below.
- 8 Mar 2004 - udpated sourcecode.