Click here to Skip to main content
Click here to Skip to main content

Screen Designer Classes

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

Introduction

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 oinksoftware@aol.com.

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);
        FloatControlBar(&m_wndDynControlBar,x,CBRS_ALIGN_LEFT);
        BOOL bVisible = ((m_wndDynControlBar.GetStyle() & WS_VISIBLE) != 0);
        m_wndDynControlBar.m_bMakingVisible = TRUE;
        ShowControlBar(&m_wndDynControlBar, !bVisible, FALSE);
        m_wndDynControlBar.m_bMakingVisible = FALSE;
        RecalcLayout();
        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_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY 
            | CBRS_SIZE_DYNAMIC) ||
            !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
        {
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
        }
    
        if (!m_wndStatusBar.Create(this) ||
            !m_wndStatusBar.SetIndicators(indicators,
              sizeof(indicators)/sizeof(UINT)))
        {
            TRACE0("Failed to create status bar\n");
            return -1;      // fail to create
        }
    
        // Screen designer control bar
        if (!m_wndDynControlBar.CreateEx(this) ||
            !m_wndDynControlBar.LoadToolBar(IDR_DYNCONTROLBAR))
        {
            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
        m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
        EnableDocking(CBRS_ALIGN_ANY);
        DockControlBar(&m_wndToolBar);
    
        // screen Designer control bar
        m_wndDynControlBar.SetBarStyle(m_wndDynControlBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
        EnableDocking(CBRS_ALIGN_ANY);
        m_wndDynControlBar.EnableDocking(0);
        DockControlBar(&m_wndDynControlBar);
        CString strText("Screen Designer");
        m_wndDynControlBar.SetWindowText(strText);
        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.

History

  • 8 Mar 2004 - udpated sourcecode.

License

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

Share

About the Author

John Indigo
Web Developer
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pinmembersylvia_zs25-Jun-13 18:06 
GeneralI can't compile it with VS2005 Pinmembercnhnyu9-Nov-09 0:02 
Generalstatic linked mfc Pinmembergrandmasta19-Sep-07 2:14 
QuestionHow can I control the object created by drag and drop? Pinmembersadlion4-Jan-05 14:19 
Questionany mirrors of it? Pinmembertuldok23-May-04 11:25 
GeneralUpgrade 8th March 2004 PinmemberJohn Indigo9-Mar-04 7:39 
Generaldoesn't work with vs.net 2003 - please help me! Pinmemberalex-t.de15-Feb-04 4:07 
GeneralRe: doesn't work with vs.net 2003 - please help me! PinmemberJohn Indigo5-Mar-04 20:37 
Generalvery good!cool! Pinmemberlibinbj27-Jul-03 22:29 
Generalgood and powerful Pinmemberpsusong28-Mar-03 6:00 
GeneralA heavy version. PinmemberTW13-Jan-03 20:52 
Follow this link to a heavy weight version of screen designing:
 
Rose | [Rose] http://members.tripod.com/IUnknwn/controls.htm
GeneralRe: A heavy version. Pinmemberpsusong28-Mar-03 6:17 
GeneralRe: A heavy version. PinsussAnonymous29-Mar-03 1:24 
GeneralGood job! Pinmemberbillhao9-Jan-03 1:20 
GeneralRe: Good job! Pinmember.S.Rod.9-Jan-03 2:47 
General#import "msado15.dll" Pinmember.S.Rod.8-Jan-03 23:04 
General#import "msado15.dll" PinmemberRalph8-Jan-03 23:22 
GeneralRe: #import "msado15.dll" PinmemberHans VL14-Jan-03 3:43 
GeneralRe: #import &quot;msado15.dll&quot; Pinmembercheong0012-May-05 22:57 
GeneralActiveX support PinmemberA. Riazi8-Jan-03 22:58 
GeneralNice! PinmemberA. Riazi8-Jan-03 22:54 
GeneralExcellent work PinmemberBrian D8-Jan-03 22:15 
GeneralRe: Excellent work PinmemberObliterator9-Jan-03 7:10 
GeneralError... Help PinmemberDarren Schroeder8-Jan-03 15:52 
GeneralRe: Error... Help PinmemberJohn Indigo8-Jan-03 20:40 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 8 Mar 2004
Article Copyright 2003 by John Indigo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid