Dynamically changing a dialog template
-
Hi all, I wish to choose a dialog template resource dynamically. The problem is that i wish to do it for the application main dialog, so its a modal dialog and i cant choose it in a Create function. :~ Thanks Shimon
Check out CDialog's constructors, they look something like this:
CDialog::CDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
...
m_lpszTemplateName = lpszTemplateName;
if (IS_INTRESOURCE(m_lpszTemplateName))
m_nIDHelp = LOWORD((DWORD_PTR)m_lpszTemplateName);
...
}CDialog::CDialog(UINT nIDTemplate, CWnd* pParentWnd)
{
...
m_lpszTemplateName = MAKEINTRESOURCE(nIDTemplate);
m_nIDHelp = nIDTemplate;
...
}So probably all you have to do is change
m_lpszTemplateName
and maybem_nIDHelp
before calling DoModal to the apropriate value, so something like:INT_PTR CMyDialog::DoModalWithID(UINT nIDTemplate)
{
m_lpszTemplateName = MAKEINTRESOURCE(nIDTemplate);
m_nIDHelp = nIDTemplate;
return DoModal();
}Does this work for you?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
Check out CDialog's constructors, they look something like this:
CDialog::CDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
...
m_lpszTemplateName = lpszTemplateName;
if (IS_INTRESOURCE(m_lpszTemplateName))
m_nIDHelp = LOWORD((DWORD_PTR)m_lpszTemplateName);
...
}CDialog::CDialog(UINT nIDTemplate, CWnd* pParentWnd)
{
...
m_lpszTemplateName = MAKEINTRESOURCE(nIDTemplate);
m_nIDHelp = nIDTemplate;
...
}So probably all you have to do is change
m_lpszTemplateName
and maybem_nIDHelp
before calling DoModal to the apropriate value, so something like:INT_PTR CMyDialog::DoModalWithID(UINT nIDTemplate)
{
m_lpszTemplateName = MAKEINTRESOURCE(nIDTemplate);
m_nIDHelp = nIDTemplate;
return DoModal();
}Does this work for you?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
I just tested it, it works for me. Maybe there are "version based differences" that cause the trouble, i did the test on VC++ 2003, version 7.1.something, show your code and maybe we will see what might be the problem.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
I just tested it, it works for me. Maybe there are "version based differences" that cause the trouble, i did the test on VC++ 2003, version 7.1.something, show your code and maybe we will see what might be the problem.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
You were right your suggestion indeed changed the resource, the visualization of the dialog was dependent on another factor. ;P Thanks
:thumbsup: :)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <