How to make a dynamic modal dialog.
-
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.
-
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.
-
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...
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.
-
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.
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... -
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.
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