Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7492273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:24:26+00:00 2026-05-29T16:24:26+00:00

I have written a runtime-created dialog class that doesn’t use any resource files based

  • 0

I have written a runtime-created dialog class that doesn’t use any resource files based on this example: http://blogs.msdn.com/b/oldnewthing/archive/2005/04/29/412577.aspx

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).

The dialog is launched by DialogBoxIndirectParam like this:

DialogBoxIndirectParam(NULL, m_template.GetTemplate(), NULL, DlgProc, reinterpret_cast<LPARAM>(this));

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.

Some interesting but strange things:

  • Dialogs in the same program using normal resources work fine in both Win 7 and Win XP.
  • When comparing the runtime-created dialog template byte by byte I can see no difference from the resource-constructed dialogs.
  • 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.
  • 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.

I have found others with similar problems but none exactly like mine: http://social.msdn.microsoft.com/Forums/zh/vcgeneral/thread/45989a10-2785-486d-94ae-4f1f3e1ca651, http://cboard.cprogramming.com/windows-programming/39218-createdialog-failure.html

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.

Here is what the template code looks like:

DialogTemplate::DialogTemplate(const std::wstring& title, WORD width, WORD height) :
m_numControls(0)
{
    AddHeader(title, width, height);
    AddFont();
}

DialogTemplate::~DialogTemplate(void)
{
}

void DialogTemplate::AddHeader(const std::wstring& title, WORD width, WORD height)
{
    // Write out the extended dialog template header
    m_data.Write<WORD>(1); // dialog version
    m_data.Write<WORD>(0xFFFF); // extended dialog template
    m_data.Write<DWORD>(0); // help ID
    m_data.Write<DWORD>(0); // extended style
    m_data.Write<DWORD>(WS_CAPTION | WS_SYSMENU | DS_SETFONT | DS_MODALFRAME);
    m_data.Write<WORD>(0); // number of controls (placeholder)
    m_data.Write<WORD>(32); // X
    m_data.Write<WORD>(32); // Y
    m_data.Write<WORD>(width); // width
    m_data.Write<WORD>(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, &ncm, 0))
        return false;

    if (ncm.lfMessageFont.lfHeight < 0)
        ncm.lfMessageFont.lfHeight = -MulDiv(ncm.lfMessageFont.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY));

    m_data.Write<WORD>((WORD)ncm.lfMessageFont.lfHeight); // point
    m_data.Write<WORD>((WORD)ncm.lfMessageFont.lfWeight); // weight
    m_data.Write<BYTE>(ncm.lfMessageFont.lfItalic); // Italic
    m_data.Write<BYTE>(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& text, DWORD controlId, DWORD style)
{
    m_data.AlignToDword();
    m_data.Write<DWORD>(0); // help id
    m_data.Write<DWORD>(0); // window extended style
    m_data.Write<DWORD>(WS_CHILD | style); // style
    m_data.Write<WORD>(x); // x
    m_data.Write<WORD>(y); // y
    m_data.Write<WORD>(width); // width
    m_data.Write<WORD>(height); // height
    m_data.Write<DWORD>(controlId); // control ID
    m_data.WriteString(pszType);    // control type (as string)
    m_data.WriteString(text.c_str()); // text
    m_data.Write<WORD>(0); // no extra data

    ++m_numControls;
    m_data.Overwrite<WORD>(m_numControls, NUM_CTRL_OFFS);
}

void DialogTemplate::AddControl(DWORD dwType, WORD x, WORD y, WORD width, WORD height, const std::wstring& text, DWORD controlId, DWORD style)
{
    m_data.AlignToDword();
    m_data.Write<DWORD>(0); // help id
    m_data.Write<DWORD>(0); // window extended style
    m_data.Write<DWORD>(WS_CHILD | style); // style
    m_data.Write<WORD>(x); // x
    m_data.Write<WORD>(y); // y
    m_data.Write<WORD>(width); // width
    m_data.Write<WORD>(height); // height
    m_data.Write<DWORD>(controlId); // control ID
    m_data.Write<DWORD>(dwType);    // control type (as DWORD)
    m_data.WriteString(text.c_str()); // text
    m_data.Write<WORD>(0); // no extra data

    ++m_numControls;
    m_data.Overwrite<WORD>(m_numControls, NUM_CTRL_OFFS);
}

Wow, it’s super annoying to paste code here if it’s indented by tabs :-/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:24:28+00:00Added an answer on May 29, 2026 at 4:24 pm

    The code looks about right, but it does not show the produced template, which fails to instantiate.

    One thing I noticed weird is:

    m_data.Write<DWORD>(dwType);    // control type (as DWORD)
    

    This does not sound about right, you need 0xFFFF in front if it:

    If the first element is 0xFFFF, the array has one additional element
    that specifies the ordinal value of a predefined system class. The
    ordinal can be one of the following atom values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can
I have written a watir script that downloads files. One of the files it
i have written a library with some classes that make use of qt object
I have written a plugin system that uses an interface and for any plugins
I have written an AIR Application that downloads videos and documents from a server.
I have written a site in Prototype but want to switch to jQuery. Any
I have written a DLL that uses MS Word to spell check the content
I have written something that uses the following includes: #include <math.h> #include <time.h> #include
I have written an application that unit tests our hardware via a internet browser.
I have written a user control that captures some user input and has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.