Originally posted by: CodeBuddy
and call to construct:
and dont forget to delete the dialog when it is no longer used.
Ask the Author to change in the DoModal() function:
//////////////////////////////////////////////////////////
//InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd);
//int iRet = CDialog::DoModal();
int iRet = CreateIndirect((LPDLGTEMPLATE)pBuffer,m_pParentWnd);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
CDynDialogEx* Dlg = new CDynDialogEx;
m_Dlg = Dlg // save "Dlg" pointer
Dlg->SetWindowTitle(_T("Operation 1"));
...
some dialog items
...
Dlg->DoModal();
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
if (m_Dlg && ::IsWindow(m_Dlg->GetSafeHwnd())) {
m_Dlg->EndDialog(IDCANCEL);
m_Dlg->DestroyWindow();
}
//////////////////////////////////////////////////////////
Reply
Originally posted by: Michael Pliam
This code seems to work quite well. One problem I am having is that if I call my CDynDialogEx derived class from an instance of itself, the second instance has changed the size of the dialog.
Any clue to what's going on here? All the rect parameters for the secondary dialog check out.
Any comments greatly appreciated.
Reply
Originally posted by: Michael Pliam
Thank you for this wonderful code. Exactly what I have been looking for. No memory leaks. Pretty bomb-proof. Easy to use. But I can't figure out how to initialize combobox controls. Generally, I have used something like
[ccode]
CComboBox *m_pCombo;
m_pCombo = (CComboBox*)GetDlgItem(IDC[0]);
ASSERT(m_pCombo != NULL);
m_pCombo->AddString("MAX");
m_pCombo->AddString("MIN");
[/ccode]
where IDC[0] is a unique UINT ID that was used in the dlg.AddDlgControl(...)creation of the control. But this technique violates the assertion.
I am certain there is some simple answer to this problem, but I cant figure it out.
Originally posted by: David Shevin
//Prework for setting font in dialog...
if (m_wFontSize == 0) {
//Prework for setting caption in dialog..., must be in Unicode ! david
Suggest you use the following instead of creating Wide chars yourself in Dialog template. This allows National language sets to work in the caption and font name.
int cWC = MultiByteToWideChar(CP_ACP, 0, LogFont.lfFaceName, -1, NULL, 0);
int nFontNameLen = cWC + 1;
WCHAR *szFontName = new WCHAR[nFontNameLen];
// Copy the string
MultiByteToWideChar(CP_ACP, 0, LogFont.lfFaceName, -1, (LPWSTR) szFontName, cWC);
szFontName[cWC] = 0;
nFontNameLen = (cWC) * sizeof(WCHAR);
m_wFontSize = (unsigned short)LogFont.lfHeight;
}
cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0);
int szBoxLen = cWC + 1;
WCHAR *szBoxCaption = new WCHAR[szBoxLen];
// Copy the string
MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR) szBoxCaption, cWC);
szBoxCaption[cWC] = 0;
szBoxLen = (cWC) * sizeof(WCHAR);
Originally posted by: Nathan Cook
I have attempted to place a regular pushbutton with the
owner draw style (BS_OWNERDRAW) in the dynamic dialog.
Problem is, apparently, the BS_OWNERDRAW style contains all
of the bits that the BS_AUTORADIOBUTTON style has!
(BS_OWNERDRAW in binary turns out to be 1011, while
BS_AUTORATIOBUTTON is 1001.) The way you are checking for a
radio button is:
if ((m_dwStyle & BS_AUTORADIOBUTTON) == BS_AUTORADIOBUTTON)
{
do the DDX stuff
}
And becuase of the above, an ordinary radio button will
trigger the DDX test!
I have not been able to find a fix for this... anyone else
know of anything? There has to be a fix, becuase owner-draw
buttons and radio buttons can co-exist in standard dialogs!
Reply
Originally posted by: Bernd Giesen
How can I update an existing dialog (created by a template in the .rc file) with dynamical items? For example I've already a fix dialog (CDialog!) window containing some pushbuttons (that should always appear) where I arbitrary want to add and remove a dynamical listbox at runtime. Is this possible at all using this lib?
Bernd
Reply
Originally posted by: macro
the CDynDialogEx only have DoModal() to modal a dialog,
but how to modalless?
Originally posted by: Bernd Giesen
The solution:
m_nCurRow += (ROWSTEPSIZE);
//Update dialogtemplate boundaries
Be aware that there are TWO CDynDialogEx::AddDlgControl
Moreover, I strongly recommend to define the "Rect"
Bernd
When I enlarged for some experimental reasons the vertical
size of the most upper push button of the "(Show) Dynamic
Dialog" Window (that appears when the upper button is
selected in the main dialog) in the OnCommand1() method
(e.g. by CRect rect(10,5,60,39);) of the demo project, I
encountered the problem that this button overwrites parts
of the radiobuttons following below. I expected that simply
changing its size would automatically update the startup
position for following items!
-------------
Add the the following "else" statement to the "if"
statement at the beginning of the
CDynDialogEx::AddDlgControl(...) methods:
//if no Rectangle given create our own...
if (pRect == NULL) {
CRect Rect(FIXEDCOL1, m_nCurRow, FIXEDCOL2, m_nCurRow + ROWSTEPSIZE);
pRect = &Rect
Rect.right += INPUTCOL;
}
else
m_nCurRow = max(m_nCurRow, pRect->bottom) - m_nCurRow;
SetDlgRectangle(pRect);
The "else" statement calculates a proper adaptation of the
m_nCurRow value, which is the base for calculating the
start position of any following dialog item.
(...) methods where these changes have to be made!
identifier outside of the scope of the "if" branch.
Otherwise it may cause undefined behaviour since the CRect
object, where pRect possibly points to, is no longer valid
while used by the SetDlgRectangle (...) call!
Originally posted by: Igor Rabinovich
Thanks, it's a good code for creating dialog and controls on the fly. I need to create PropertyPage on the fly without the resource id and put it into the PropertySheet.
How I can do that?
I cannot find the class name for the PropertyPage. Maybe it's like creating dialog on the fly.
Thank you,
Igor.
Originally posted by: Sergiu Frishling
That's OK as long as you're working with standard classes
as "buton", "listbox", etc., and add them as shown in your
code.
The problem, is when you want to build a dynamic dialog
from a dialog template, which includes ActiveX controls
as well. (e.g. when you have a base dialog with basic
controls on it, and, at run time you have to populate it
or to add to the existing controls, ather controls from
dialogs template, which includes ActiveX, created also with
the dialog editor and saved as nomaly into the *.rc file)
If you have any sugestions how to make it, please let me know, Sergiu.