CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2012
    Posts
    24

    Dialog like Window for settings parameters

    Hi guys,

    I got a main window with menu and the option settings. When I click settings a "dialog" should appear, where the user is able to set some parameters - into a global variable. This window will have something like 12 columns and 8/16/32 (this will vary) rows. This gives us plenty of controls, mostly Edit Controls, which can be filled by the user.

    My question is, how to make this window effectively. I was considering dialog box modal/modeless, the problem is the way you have to define a dialog box -> resource file. Defining all the controls in a resource makes the code somehow not very flexible, when I want to change something.
    I was trying to make some sort of child window, which is created as follows:

    Code:
    HWND GT_CreateWindowMaster(HWND hParent)
    {
        return CreateWindowEx(
                   WS_EX_DLGMODALFRAME | WS_EX_TOOLWINDOW,                   /* Extended possibilites for variation */
                   GA_WINDOW_MASTER,         /* Classname */
                   "Settings - LIN Master",       /* Title Text */
                   WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_CAPTION | WS_VSCROLL | WS_HSCROLL, /* default window */
                   0,       /* Windows decides the position */
                   0,       /* where the window ends up on the screen */
                   544,                 /* The programs width */
                   375,                 /* and height in pixels */
                   NULL,        /* The window is a child-window to desktop */
                   NULL,                /* No menu */
                   GetModuleHandle(0),       /* Program Instance handler */
                   NULL                 /* No Window Creation data */
               );
    }
    In the WM_CREATE section of the window procedure I call a function, which creates all the buttons, edit boxes etc.

    Code:
    void OnCreate(HWND hParent, int iOffsets[])
    {
        int i;
        for(i = 1; i < NUM_ROWS; i++)
        {
            CreateIDEdit      (hParent, i, 0, iOffsets[0]);
            CreateDelayEdit   (hParent, i, 1, iOffsets[1]);
            CreateLengthCombo (hParent, i, 2, iOffsets[2]);
            CreateByteEdit    (hParent, i, 3, iOffsets[3]);
        }
    }
    But it's not the child of the main window, which can probably cause trouble in the future (don't know right now). What is good approach to create such "complex" setting windows like in Code::Blocks for example or other pieces of SW? Is it done with dialog boxes through resources? What are the pros and cons of different approaches?
    Thank you for advices! :-)

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Dialog like Window for settings parameters

    In VC++ the simplest way to create a dialog is doing it in a resource editor.
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2012
    Posts
    24

    Re: Dialog like Window for settings parameters

    Quote Originally Posted by VictorN View Post
    In VC++ the simplest way to create a dialog is doing it in a resource editor.
    Thx for your reply Victor. Even when creating a window with cca 250 controls? When I want to change something, then I've to move all of them. Is Dialog the only way? No other techniques I should look for?

    Thx. :-)

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Dialog like Window for settings parameters

    Up to 255.
    But it seems to be too many!
    Perhaps you should redesign your dialog to use some other conrol types?
    Perhaps, ListView or grid control would have more sense than a lot of edit ones?
    Last edited by VictorN; September 18th, 2013 at 02:31 AM.
    Victor Nijegorodov

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Dialog like Window for settings parameters

    But it's not the child of the main window, which can probably cause trouble in the future
    I'm not sure I'm following what you mean. Any window created specifying a parent window is a child of that window. A child of the desktop is a top-level window.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Jul 2012
    Posts
    24

    Re: Dialog like Window for settings parameters

    2kaud, don't focus on that. The child window will be inside it's parent window, which is not wanted. The origin of my question is how to implement such setting dialogs. The dialog should be used by the user to setup some parameters, which will be then used by the HW. And because I want him to set as much as possible, the number of controls is high and dialog is probably not the best or the solution of the dialog is not the best.... So I'm investigating my possibilities.

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Dialog like Window for settings parameters

    Quote Originally Posted by HellMaster22 View Post
    Even when creating a window with cca 250 controls?
    It's very unlikely you have 250 unstructured settings. Those are always may be grouped somehow, and every group can be placed to a separate tab. The approach is known as property view or wizard.

    Another approach can be a list view with customized column where the setting value appears editable somehow: checkbox, dropdown box, textbox, etc.

    The two may be combined alright.
    Best regards,
    Igor

  8. #8
    Join Date
    Jul 2012
    Posts
    24

    Re: Dialog like Window for settings parameters

    Victor, thank you for the grid control, this led me to the following page of interesting dialog:

    http://www.codeproject.com/Articles/...View-Made-Easy

    and one important thing. I'm able to use a custom control in a dialog, I was not aware of that! So I can create a class, which can be then used in this dialog! What I was wondering was, how the guy in the project above overrided all the edit boxes in listview at once... Didn't have time yesterday to study it more in detail.

    Igor:
    I agree its unusual. I want a dialog, where the user is able to set a message, which will be sent over a bus. This means at least ID and up to 8 boxes (8 bytes) + delay time to wait for sending a next message. There are other options to be set, but this is the minumim => 10 columns. To represent a real situation, not only one message will be sent over the bus. The user should be able to set another other messages. So its some sort of setting dialog for a scheduler.

    Msgs; A (5ms, 8 bytes), B (10 ms, 8 bytes), C (5ms, 4 bytes), D (20 ms, 2bytes)

    These messages will be sent over a bus and will be repeated with a repeat time 40 ms (sum of all delays). So after 40 ms the scheduler will sent msg "A" again.

    That's why there is the need of so many control. Probably it can be solved differently.

    So the list view sounds possible. Could you help a bit, how to customize the columns so instead of edit there would be lets say a checkbox?

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Dialog like Window for settings parameters

    the resource editor is by far the easiest way to design a dialog but you can do it all by yourself.
    Create the dialog directly, then create all the individual controls you need to put on it.

    The dialog editor is limited to 255 controls. MS has hinted in the past that they aren't going to make any changes to this claiming "you should never have a dialog with that many controls".
    If you need more than 255 controls: make 2 separate templates. and either merge them at runtime
    or merge them manually in the resource file. (doing so will prevent you from further using the editor on that dialog).

    You are limited in the amount of controls on a dialog because there is a hard per-process-window limit. (16K iirc).

    If you have many controls, you'll also notice the dialog starts behaving slowly/sluggishly because of the window messages that need to be passed down to all child controls. It may also confuse users of your software.

    You really want to limit the amount of controls on a dialog. Instead of a lot of checkboxes, you could use a listbox/listcontrol with checkboxes. Instead of a lot of editboxes you could use a listcontrol or a grid. For large amounts of settings, there's the CMFCProperyGridControl.

    You can also customize another existing control, or even design your own control.

    Or rethink the UI entirely. Is what you're doing now really "the best" way, or is it simply the "easiest" way to do it. Or have you not given it much thought and is it simply the only possible solution you considered.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured