Click here to Skip to main content
13,591,789 members
Click here to Skip to main content
Add your own
alternative version


107 bookmarked
Posted 7 Jan 2003

Screen Designer Classes

, 7 Mar 2004
Rate this:
Please Sign up or sign in to vote.
Screen Designer Classes for MFC applications


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

Getting Started

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 CNewExampleView is CFormView.

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:
    #include <afxole.h>
    #include "dynscreen.h"
  • 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 ID_MAINFRAME menu.

  • 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:
    void CMainFrame::OnScreenDesigner() 
        // TODO: Add your command handler code here
        CPoint x(500,100);
        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:
    #include "DynControlBar.h"
  • In MainFrm.h add the following line in the declaration, you can do it after the line which defines m_wndToolBar.
    CDynControlBar    m_wndDynControlBar;
  • 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)
            return -1;
        if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE 
            | CBRS_SIZE_DYNAMIC) ||
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
        if (!m_wndStatusBar.Create(this) ||
            TRACE0("Failed to create status bar\n");
            return -1;      // fail to create
        // Screen designer control bar
        if (!m_wndDynControlBar.CreateEx(this) ||
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
        // TODO: Delete these three lines if you don't want the toolbar to
        //  be dockable
        // screen Designer control bar
        m_wndDynControlBar.SetBarStyle(m_wndDynControlBar.GetBarStyle() |
        CString strText("Screen Designer");
        ShowControlBar(&m_wndDynControlBar, FALSE, FALSE);
        return 0;
  • In CNewExampleView.h include the header file
    #include "DynWnd.h"
  • In CNewExampleView.h change the class declaration line to:
    class CNewExampleView : public CDynWnd<CFormView>
  • In CNewExampleView.cpp change the BEGIN_MESSAGE_MAP line to
    BEGIN_MESSAGE_MAP(CNewExampleView, CDynWnd<CFormView>)
  • 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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

John Indigo
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionHow can I control the object created by drag and drop? Pin
sadlion4-Jan-05 14:19
membersadlion4-Jan-05 14:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180618.1 | Last Updated 8 Mar 2004
Article Copyright 2003 by John Indigo
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid