Note that there are some explanatory texts on larger screens.

plurals
  1. PODialog using runtime-created template doesn't work on XP 32 bit
    primarykey
    data
    text
    <p>I have written a runtime-created dialog class that doesn't use any resource files based on this example: <a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/04/29/412577.aspx" rel="nofollow">http://blogs.msdn.com/b/oldnewthing/archive/2005/04/29/412577.aspx</a></p> <p>It is compiled on a Windows 7 x64 machine, but as an x86 application. The dialog is part of a larger program that at other places use normal dialogs with resource files (MFC).</p> <p>The dialog is launched by DialogBoxIndirectParam like this:</p> <pre><code>DialogBoxIndirectParam(NULL, m_template.GetTemplate(), NULL, DlgProc, reinterpret_cast&lt;LPARAM&gt;(this)); </code></pre> <p>The dialog shows fine on all Windows 7 x64 machines I have tried, but it doesn't work on Windows XP x86 machines. I don't know if it's the Windows version or the CPU bit part that is the culprit.</p> <p>Some interesting but strange things:</p> <ul> <li>Dialogs in the same program using normal resources work fine in both Win 7 and Win XP.</li> <li>When comparing the runtime-created dialog template byte by byte I can see no difference from the resource-constructed dialogs.</li> <li>As long as I don't add any controls what so ever to the dialog, it WILL display in XP, but if I add as much as a single static it won't.</li> <li>I have monitored the callback function and when it starts it sends WM_SETFONT, WM_DESTROY, WM_NCDESTROY and then dies. It's like it gives up somewhere between WM_SETFONT and WM_CREATE.</li> </ul> <p>I have found others with similar problems but none exactly like mine: <a href="http://social.msdn.microsoft.com/Forums/zh/vcgeneral/thread/45989a10-2785-486d-94ae-4f1f3e1ca651" rel="nofollow">http://social.msdn.microsoft.com/Forums/zh/vcgeneral/thread/45989a10-2785-486d-94ae-4f1f3e1ca651</a>, <a href="http://cboard.cprogramming.com/windows-programming/39218-createdialog-failure.html" rel="nofollow">http://cboard.cprogramming.com/windows-programming/39218-createdialog-failure.html</a></p> <p>I must say that I'm at my wits end about this, I'm just not good enough at win32 programming to figure out exactly what could be wrong here.</p> <p>Here is what the template code looks like:</p> <pre><code>DialogTemplate::DialogTemplate(const std::wstring&amp; title, WORD width, WORD height) : m_numControls(0) { AddHeader(title, width, height); AddFont(); } DialogTemplate::~DialogTemplate(void) { } void DialogTemplate::AddHeader(const std::wstring&amp; title, WORD width, WORD height) { // Write out the extended dialog template header m_data.Write&lt;WORD&gt;(1); // dialog version m_data.Write&lt;WORD&gt;(0xFFFF); // extended dialog template m_data.Write&lt;DWORD&gt;(0); // help ID m_data.Write&lt;DWORD&gt;(0); // extended style m_data.Write&lt;DWORD&gt;(WS_CAPTION | WS_SYSMENU | DS_SETFONT | DS_MODALFRAME); m_data.Write&lt;WORD&gt;(0); // number of controls (placeholder) m_data.Write&lt;WORD&gt;(32); // X m_data.Write&lt;WORD&gt;(32); // Y m_data.Write&lt;WORD&gt;(width); // width m_data.Write&lt;WORD&gt;(height); // height m_data.WriteString(L""); // no menu m_data.WriteString(L""); // default dialog class m_data.WriteString(title.c_str()); // title } bool DialogTemplate::AddFont() { // Write out font HDC hdc = GetDC(NULL); if (!hdc) return false; NONCLIENTMETRICSW ncm = { sizeof(ncm) }; if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 0, &amp;ncm, 0)) return false; if (ncm.lfMessageFont.lfHeight &lt; 0) ncm.lfMessageFont.lfHeight = -MulDiv(ncm.lfMessageFont.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY)); m_data.Write&lt;WORD&gt;((WORD)ncm.lfMessageFont.lfHeight); // point m_data.Write&lt;WORD&gt;((WORD)ncm.lfMessageFont.lfWeight); // weight m_data.Write&lt;BYTE&gt;(ncm.lfMessageFont.lfItalic); // Italic m_data.Write&lt;BYTE&gt;(ncm.lfMessageFont.lfCharSet); // CharSet m_data.WriteString(ncm.lfMessageFont.lfFaceName); return true; } void DialogTemplate::AddControl(LPCWSTR pszType, WORD x, WORD y, WORD width, WORD height, const std::wstring&amp; text, DWORD controlId, DWORD style) { m_data.AlignToDword(); m_data.Write&lt;DWORD&gt;(0); // help id m_data.Write&lt;DWORD&gt;(0); // window extended style m_data.Write&lt;DWORD&gt;(WS_CHILD | style); // style m_data.Write&lt;WORD&gt;(x); // x m_data.Write&lt;WORD&gt;(y); // y m_data.Write&lt;WORD&gt;(width); // width m_data.Write&lt;WORD&gt;(height); // height m_data.Write&lt;DWORD&gt;(controlId); // control ID m_data.WriteString(pszType); // control type (as string) m_data.WriteString(text.c_str()); // text m_data.Write&lt;WORD&gt;(0); // no extra data ++m_numControls; m_data.Overwrite&lt;WORD&gt;(m_numControls, NUM_CTRL_OFFS); } void DialogTemplate::AddControl(DWORD dwType, WORD x, WORD y, WORD width, WORD height, const std::wstring&amp; text, DWORD controlId, DWORD style) { m_data.AlignToDword(); m_data.Write&lt;DWORD&gt;(0); // help id m_data.Write&lt;DWORD&gt;(0); // window extended style m_data.Write&lt;DWORD&gt;(WS_CHILD | style); // style m_data.Write&lt;WORD&gt;(x); // x m_data.Write&lt;WORD&gt;(y); // y m_data.Write&lt;WORD&gt;(width); // width m_data.Write&lt;WORD&gt;(height); // height m_data.Write&lt;DWORD&gt;(controlId); // control ID m_data.Write&lt;DWORD&gt;(dwType); // control type (as DWORD) m_data.WriteString(text.c_str()); // text m_data.Write&lt;WORD&gt;(0); // no extra data ++m_numControls; m_data.Overwrite&lt;WORD&gt;(m_numControls, NUM_CTRL_OFFS); } </code></pre> <p>Wow, it's super annoying to paste code here if it's indented by tabs :-/</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload