The evolution of dialog templates – Introduction

Date:June 17, 2004 / year-entry #239
Tags:history
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20040617-00/?p=38833
Comments:    10
Summary:In the history of Windows, there have been four versions of dialog templates. And despite the changes, you'll see that they're basically all the same. My secret goal in this six-part series is to address questions people have had along the lines of "I'm trying to generate a dialog template in code, and it's not...

In the history of Windows, there have been four versions of dialog templates. And despite the changes, you'll see that they're basically all the same.

My secret goal in this six-part series is to address questions people have had along the lines of "I'm trying to generate a dialog template in code, and it's not working. What am I doing wrong?"

As it turns out, that you can get the resource compiler to tell you what you're doing wrong. Take the template that you're trying to generate, create an *.rc file for it and run it through the resource compiler. Attach the resource to a dummy program and dump the bytes! Compare the compiler-generated template against the one you generated. Look for the difference.

In other words: To see what you're doing wrong, take somebody who does it right and compare. Clearly there's a difference somewhere. It's just bytes.

Anyway, enough of the rant against laziness. The next several days will cover the evolution of the dialog template, with annotated byte dumps for people who are trying to figure out why their dialog template isn't working.

Non-geeks may want to go into hibernation for a while, since this will take over a week to play out. I'll try to keep you amused with the non-technical side-postings.


Comments (10)
  1. asdf says:

    Because the sample code on MSDN (even after you correct all the errors to get it to compile) and documentation are incorrect. I should know, I spent a few days days reverse engineering dialog templates and the undocumented hack in windows that prevents you from getting message box fonts to work unless you use their little font size hack. When I get back home I’ll post an article about dialog templates too so the rest of the people can play along at home.

  2. Mike Dimmick says:

    Maybe I was reading different documentation to you, then, because it worked fine for me.

    One of my creations (Large Keyboard for Pocket PCs – http://www.handango.com/PlatformProductDetail.jsp?siteId=1&jid=53C4C228D39FF8X1AX7A731117346483&platformId=2&productType=2&catalog=0&sectionId=0&productId=92315) parses dialog templates to draw the keyboard ‘tabs’ so that the developer adapting it can use the resource editor to draw a keyboard. It isn’t actually used as a dialog resource, for two reasons: firstly, the rounding errors in the font mapping can lead to overlaps, odd line thicknesses or gaps, and secondly that an array of buttons is slow and doesn’t work too well when embedded in a Pocket PC input method (not to mention weird focus behaviour).

    Yep, I could have written my own editor. Indeed, it’s actually easier to punch in the numbers so I edit the resource script by hand to make changes.

    I’d previously used dialog template construction (successfully) in a build-your-own-forms-style application; however, I realise now that it’s simpler to just create the child controls and use IsDialogMessage to provide the standard dialog navigation behaviour. There was a certain amount of fudging of sizes involved, again due (I think) to the dialog unit mapping rounding problem.

  3. asdf says:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/usingdialogboxes.asp

    "Creating a template in memory" specifically. But there were lots of incorrect statements scattered around MSDN from what I rememeber.

    I agree with you on the build your own dialogs and use IsDialogMessage but you still have to write code to remember the focus, set the fonts, use the dialog units code I posted on this blog a while ago (which I highly recomend because doing it in dlgu makes the dialog look so much better especially if you support resizing), and optionally make your own modal message loop. Should take an hour or two.

  4. mschaef says:

    " agree with you on the build your own dialogs and use IsDialogMessage but you still have to write code to remember the focus, set the fonts, use the dialog units code "

    So why were templates done originally? Were they the best way to implement the functionality you mention, or was it primarily for programmer convenience?

    Part of the reason I ask is that I’ve spent way too much time trying to develop libraries of reusable windows using MFC and Visual Studio. VS seems to work really well if the assumption holds true that all resources (and compiled dialog templates) are in the same file. Once that assumption changes, things seem to get pretty tricky. Life seemd like it would be easier in this respect if it was done programatically by explicitly creating windows.

  5. asdf says:

    Two main reasons (three if you count ripping off the Mac). The first one is so you can use a UI editor. The second one is to support different languages with the same binary. These both take advantage of dialog units because if you change the the size of the fonts, the dialog box should look the same (in theory). Set your fonts to use a large dpi and see how many apps get this part wrong.

    Programming dialog boxes is a different beast than programming a real window (there is a really old blog entry somewhere here that shows how to get it DefWindowProc style instead of dialog box style). Most of the time dialogs are just copy and paste coding with validation thrown in and doing it dialog style with templates is easier and less code (if you’ve ever done tabs manually vs property pages with dialog templates, you’d know). If you want to support resizing, custom fonts, or anything else fancy it’s much easier to use IsDialogMessage and roll your own. It’s another hour or two of work if you want to parse the dialog templates and create the windows yourself.

  6. Mike Dunn says:

    Life seemd like it would be easier in this respect if it was done programatically by explicitly creating windows.

    That’s how it’s done in Windows Forms and personally I find it much uglier than using an rc file.

    For resizing (in normal C++) WTL’s CDialogResize is da bomb.

  7. asdf says:

    http://www.kkow.net/etep/code/dlgtemplate.html

    Sorry for the half assed documentation, I’m tired as hell. The code is pretty self explanatory with just the sample code that shows what’s going on.

  8. Ben Hutchings says:

    asdf: I thought a major reason for using templates was to save on code size. A bunch of dialog resources plus some generic code to instantiate them is surely smaller than the specific code to create the controls for each dialog.

  9. Trying to capture the changes in a table.

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index