Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to make a dynamic modal dialog.

How to make a dynamic modal dialog.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wormhole5230
    wrote on last edited by
    #1

    Dynamic dialog is a dialog of which controls can be created or removed manually depends on the situation. It is easy to make a dynamic modaless dialog as follows. //////////////// CDialog *menu; menu = new CDialog; menu->Create(IDD_MY_BLANK_DIALOG, this); // add a edit control if IsEdit is true if(IsEdit) { CEdit* pEdit = new CEdit(); RECT rctEdit = {5, 5, 100, 30}; pEdit->Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP, rctEdit, FromHandle(menu->m_hWnd), 1100); } // add a button control if IsBtn is true if(IsBtn) { CButton* pButton = new CButton(); RECT rctButton = {5, 35, 100, 60}; pButton->Create(_T("Button"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, rctButton, FromHandle(menu->m_hWnd), 1101); } menu->ShowWindow(SW_SHOW); /////////////// But I want to make a dynamic modal dialog. I heard about the InitModalIndirect function but it is somewhat complex to use. I want a compact code. Is there any simple method like an above code? Thanks.

    J W 2 Replies Last reply
    0
    • W Wormhole5230

      Dynamic dialog is a dialog of which controls can be created or removed manually depends on the situation. It is easy to make a dynamic modaless dialog as follows. //////////////// CDialog *menu; menu = new CDialog; menu->Create(IDD_MY_BLANK_DIALOG, this); // add a edit control if IsEdit is true if(IsEdit) { CEdit* pEdit = new CEdit(); RECT rctEdit = {5, 5, 100, 30}; pEdit->Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP, rctEdit, FromHandle(menu->m_hWnd), 1100); } // add a button control if IsBtn is true if(IsBtn) { CButton* pButton = new CButton(); RECT rctButton = {5, 35, 100, 60}; pButton->Create(_T("Button"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, rctButton, FromHandle(menu->m_hWnd), 1101); } menu->ShowWindow(SW_SHOW); /////////////// But I want to make a dynamic modal dialog. I heard about the InitModalIndirect function but it is somewhat complex to use. I want a compact code. Is there any simple method like an above code? Thanks.

      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #2

      well... When you call the DoModal function you must have the dialog created, then just before to call DoModal, you can add all the controls you want... Hope this helps...

      W 1 Reply Last reply
      0
      • J Joan M

        well... When you call the DoModal function you must have the dialog created, then just before to call DoModal, you can add all the controls you want... Hope this helps...

        W Offline
        W Offline
        Wormhole5230
        wrote on last edited by
        #3

        That's exactly what I want. But the question is how to implement it? I tried many ways, but I failed because of lack of knowledge about creating controls in blank dialog. Could you show me an example which is really working? The important thing is that it should be a modal dialog. Thanks.

        J 1 Reply Last reply
        0
        • W Wormhole5230

          That's exactly what I want. But the question is how to implement it? I tried many ways, but I failed because of lack of knowledge about creating controls in blank dialog. Could you show me an example which is really working? The important thing is that it should be a modal dialog. Thanks.

          J Offline
          J Offline
          Joan M
          wrote on last edited by
          #4

          In order to create dynamically a combobox, you should do this: CRect r; if (this->m_ccbParametritzacio.GetSafeHwnd() == NULL) { this->m_ccbParametritzacio.Create(WS_CHILD | WS_VSCROLL | WS_HSCROLL | CBS_DROPDOWNLIST, r, this, **UNIQUE_ID**); this->m_ccbParametritzacio.SetFont(this->GetFont()); } NOTE0: you should change "this->" for the parent dialog... (this is only supposed I've not tried it) NOTE1: there was an article referring on this topic here in CP or in codeguru (I don't remember exactly...) NOTE2: I recommend you to use a derived listctrl with buttons, comboboxes, editboxes... in order to do what you are searching for because this control is extendable and if there are lots of controls to be created dynamically you'll be able to go through them using the implemented scrollbars, and moreover you'll avoid to recalculate the place where to put the control and where to put the text referred to the same control... Hope this helps...

          1 Reply Last reply
          0
          • W Wormhole5230

            Dynamic dialog is a dialog of which controls can be created or removed manually depends on the situation. It is easy to make a dynamic modaless dialog as follows. //////////////// CDialog *menu; menu = new CDialog; menu->Create(IDD_MY_BLANK_DIALOG, this); // add a edit control if IsEdit is true if(IsEdit) { CEdit* pEdit = new CEdit(); RECT rctEdit = {5, 5, 100, 30}; pEdit->Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP, rctEdit, FromHandle(menu->m_hWnd), 1100); } // add a button control if IsBtn is true if(IsBtn) { CButton* pButton = new CButton(); RECT rctButton = {5, 35, 100, 60}; pButton->Create(_T("Button"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, rctButton, FromHandle(menu->m_hWnd), 1101); } menu->ShowWindow(SW_SHOW); /////////////// But I want to make a dynamic modal dialog. I heard about the InitModalIndirect function but it is somewhat complex to use. I want a compact code. Is there any simple method like an above code? Thanks.

            W Offline
            W Offline
            Wormhole5230
            wrote on last edited by
            #5

            Actually, I had found an article exactly matched to this topic before I post my first question. In that article, one can use similar method like dynamic modaless dialog to make a dynamic modal dialog by including supplied codes. Spending many times, I was finding other method to do that without the code. I decided to use that code and now it works well. If you have interests in this article, please refer this. http://www.codeproject.com/dialog/dynamicdialog.asp?target=dynamic|dialog|modal

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups