Click here to Skip to main content
15,881,173 members
Articles / Desktop Programming / MFC
Article

Screen Designer Classes

Rate me:
Please Sign up or sign in to vote.
4.93/5 (39 votes)
7 Mar 20045 min read 147.4K   3.9K   109   30
Screen Designer Classes for MFC applications

Image 1

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


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
sylvia_zs25-Jun-13 18:06
sylvia_zs25-Jun-13 18:06 
GeneralI can't compile it with VS2005 Pin
cnhnyu9-Nov-09 0:02
cnhnyu9-Nov-09 0:02 
Generalstatic linked mfc Pin
Taulie9-Sep-07 2:14
Taulie9-Sep-07 2:14 
QuestionHow can I control the object created by drag and drop? Pin
sadlion4-Jan-05 14:19
sadlion4-Jan-05 14:19 
Questionany mirrors of it? Pin
tuldok23-May-04 11:25
tuldok23-May-04 11:25 
GeneralUpgrade 8th March 2004 Pin
John Indigo9-Mar-04 7:39
John Indigo9-Mar-04 7:39 
Generaldoesn't work with vs.net 2003 - please help me! Pin
alex-t.de15-Feb-04 4:07
alex-t.de15-Feb-04 4:07 
GeneralRe: doesn't work with vs.net 2003 - please help me! Pin
John Indigo5-Mar-04 20:37
John Indigo5-Mar-04 20:37 
Generalvery good!cool! Pin
libinbj27-Jul-03 22:29
libinbj27-Jul-03 22:29 
Generalgood and powerful Pin
psusong28-Mar-03 6:00
psusong28-Mar-03 6:00 
GeneralA heavy version. Pin
TW13-Jan-03 20:52
TW13-Jan-03 20:52 
GeneralRe: A heavy version. Pin
psusong28-Mar-03 6:17
psusong28-Mar-03 6:17 
GeneralRe: A heavy version. Pin
Anonymous29-Mar-03 1:24
Anonymous29-Mar-03 1:24 
GeneralGood job! Pin
billhao9-Jan-03 1:20
billhao9-Jan-03 1:20 
GeneralRe: Good job! Pin
Stephane Rodriguez.9-Jan-03 2:47
Stephane Rodriguez.9-Jan-03 2:47 
General#import "msado15.dll" Pin
Stephane Rodriguez.8-Jan-03 23:04
Stephane Rodriguez.8-Jan-03 23:04 
General#import "msado15.dll" Pin
Ralph8-Jan-03 23:22
Ralph8-Jan-03 23:22 
GeneralRe: #import "msado15.dll" Pin
Hans VL14-Jan-03 3:43
Hans VL14-Jan-03 3:43 
GeneralRe: #import &quot;msado15.dll&quot; Pin
cheong0012-May-05 22:57
cheong0012-May-05 22:57 
GeneralActiveX support Pin
Abbas_Riazi8-Jan-03 22:58
professionalAbbas_Riazi8-Jan-03 22:58 
GeneralNice! Pin
Abbas_Riazi8-Jan-03 22:54
professionalAbbas_Riazi8-Jan-03 22:54 
GeneralExcellent work Pin
Brian D8-Jan-03 22:15
Brian D8-Jan-03 22:15 
GeneralRe: Excellent work Pin
Obliterator9-Jan-03 7:10
Obliterator9-Jan-03 7:10 
agreed! stunning!
I look forward to seeing the polished version!

--

The Obliterator
GeneralError... Help Pin
Darren Schroeder8-Jan-03 15:52
Darren Schroeder8-Jan-03 15:52 
GeneralRe: Error... Help Pin
John Indigo8-Jan-03 20:40
John Indigo8-Jan-03 20:40 

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.