Dynamic v.s. static Controls


  1. The need:

    When we get a model, a group of parameters need to talk to users through dialog box. What we want is adding them to a dialog box, and then poping out for data exchange. That’s it!

    When we get an object to draw, we need to collect its attribute or properties, so that the drawing will be interactive.

    When we have a system, we need a modifier to change its size, boundary conditions, and so on ...

    When we open a viewer, we need to set the view ...

    We need a dialog as a container, which is "ready" for adding, despite that we do not know in advance how many components and what are their data types.

  2. What does Microsoft provide?

    Under ResourceView, right-click click on Dialog, then Insert Dialog, you will see an empty dialog box with “Controls” (see screen snapshot). Then, you can drag a control and drop to your dialog. Cool! right?

    Quickly, you will find its limitation. First, when you add a CEdit Box control for a member variable, you have to specify its type (double, int, CString . . . ). Second, you have to know previously how many variables. When this dialog is finished, you build a "static" dialog to interact with user.

    It is ok for certain circumstances. Problems are how about if you do not previously know the number of variables, and you do not know the variable types, or even worse if there are too many dialog boxes are needed? These problems will drive you turn to a "dynamic" dialog box.

  3. A dynamic dialog box.

    Here is an example of an address dialog.

    ///////////////////////////////////////////////////////
    // Initial
    CString 	street	= "415 South Street";
    int 	 	apt		= 6;
    CString 	city	= "Waltham";
    CString 	state	= "Massachusetts";
    CString 	zip		= "02454";
    bool		rent	= true;
    CString		csRoom[]= {"1- ", "2- ", "3-bedroom apt", ""};
    int			nRoom	= 1;
    
    // Declaration 
    npMixPtr addr("Address Dialog Example");
    
    // Adding
    addr.add("Street name:",	&street);
    addr.add("Apt number:",		&apt);
    addr.add("City of living:",	&city);
    addr.add("State:",			&state);
    addr.add("Zip code:",		&zip);
    addr.add("Rent an apartment?",	&rent);
    addr.add("Number of bedroom:",&nRoom, csRoom, 0); // 0:Title-radio, 1:ComboBox
    // Pop-up
    addr.set();
    ///////////////////////////////////////////////////////
    

    Immediately, you will see the dialog below for data exchange. Notice that when you do adding, you don't need to take care how many parameters and what are their types. Just use the syntax "add(name,pointer);".

  4. How does it help?

    In PDEs, my software packet, such a type of dialog has been called more than three-hundred times (No one would expect using Microsoft’s drag-and-drop to build 300 dialog boxes one by one.) Why such a dialog is so frequently used, because every model has a group of parameters which you need to exchange with users, even for a simple plot of a sinusoid function, you have to tell things, such as, amplitude, period, initial phase, ranges of drawing, and so on.


Home | Qt | C/C++ | PDEs