Re: Creating controls of modeless dialog in runtime

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Scott McPhillips [MVP] (scottmcp_at_mvps.org.nothere)
Date: 05/20/04


Date: Thu, 20 May 2004 08:26:39 -0500

Marco wrote:
> Hi,
> I have a modeless dialog that shows some editable properties of various
> types of objects.
> When the user selects an object (in another window) this dialog must update
> showing the object's properties (in static text and edit text fields).
>
> For example, object1 has 10 properties, so when the object1 is selected the
> dialog must show 10 static texts and 10 edit text.
>
> I know I can update the dialog controls created in the OnInitDialog
> function, but since the number of properties is arbitrary, I think I need to
> re-create the controls.
>
> What is the right way to implement this, without closing and re-creating the
> dialog?
>
> I hope my question is clear...
>
> Thank you in advance,
>
> Marco
>
>

One way is to have a separate dialog template for each type of object
and display it on top of the main dialog. For example, this is the way
tabbed dialogs display a different set of controls for each tab. You
create a modeless dialog (with no border and no titlebar) for each
template. You make only one of these modeless dialogs visible at a time.

If you really want to use just one common template you could consider
the simple expedient of putting the max number of controls on it, then
making the unneeded ones invisible each time the selection changes.

Re-creating the controls is the hardest (most work) approach, but it can
be done. To delete a control call its DestroyWindow. To create a
control call its Create function. (Some of them look better if you use
CreateWindowEx instead.)

-- 
Scott McPhillips [VC++ MVP]


Relevant Pages

  • Re: Modal dialog as thread
    ... threading and MFC experience of the person doing it. ... In this case setting controls values would be much easier. ... Convert modal dialogs to modeless by Jon S. Kyle ... ::PostMessageto post custom messages to the dialog. ...
    (microsoft.public.vc.mfc)
  • getting size of CWnd
    ... I have some controls within a dialog. ... I would like to resize the controls within the dialog if the dialog is ... MoveWindow you give a rect where the modeless dialog will occupy. ...
    (microsoft.public.vc.mfc)
  • Re: getting size of CWnd and putting modeless dialogs on FormViews
    ... I've now gotten the controls within the modeless dialog all ... I use these two rectangles to suitably scale the controls within the ... another FormView, the old FormView dutifully goes to the background, ... >> OnCreate function of the modeless dialog and capturing the size there. ...
    (microsoft.public.vc.mfc)
  • Re: Creating controls of modeless dialog in runtime
    ... > the simple expedient of putting the max number of controls on it, ... or if the changes to the controls are made "smoothly". ... >> I have a modeless dialog that shows some editable properties of various ... > One way is to have a separate dialog template for each type of object ...
    (microsoft.public.vc.mfc.docview)
  • Re: SDI resource dialog from menu - dumb newbie question
    ... Sounds to me like you want a modeless dialog. ... whatever controls I want on the modeless dialog and have them SendMessage user-defined ... It is a graphics based app that uses the full client rectangle. ... videomixingrenderer window that cannot share its window without flickering. ...
    (microsoft.public.vc.mfc)