Date: | August 31, 2006 / year-entry #296 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20060831-22/?p=29903 |
Comments: | 15 |
Summary: | An anonymous commenter wanted to know how to create a dialog box with CreateWindow. The window class for dialog boxes is WC_DIALOG. I'm not quite sure why anybody would want to create a dialog box this way, but there you have it. |
An anonymous commenter wanted to know how to create a dialog box with |
Comments (15)
Comments are closed. |
Well, It’s usefull for writing tutorials for win32 api programming where you don’t want to shock the developer with the class function in the hello world example.
But I most admit, I used the button class for this:-)
For one of our products, I was forced to create a CNonDialog class which would SIMULATE the entire functionality of the dialog. This is because the CDialog painter would assume a rectangular region for the window (for the purposes of background filling) which would make it look like my oval dialog had smudges around the edge. I am sure this happened in Win2k. Haven’t tried it in XP.
I’ve always used "#32770". Is that the same?
Perhaps they’re writing a 4k or 64k demo, and they want to save a few bytes in the exe by not needing to link against the CreateDialog function.
Sorry for the mistake. It was CButton class that had the problem with non-rectangular window regions. So, I came up with CNonButton class.
I didn’t actually use the approach of creating a dialog directly, but when I wrote an application framework that used a different resource format for describing dialog boxes, I effectively abandoned the use of the DialogBox (etc) functions.
In the first version I just used DialogBox (or CreateDialog) with a constructed template that created a dialog of the right size, then created controls in response to WM_CREATE. I eventually abandoned this approach because you can’t get pixel-resolution sizing this way, as the size of a dialog is specified in dialog units (of course).
So, in the second version, I created dialogs by using CreateWindow and used my own implementation of modality to provide an ‘execute()’ method on my dialog class. I didn’t use the standard Windows’ dialog class, cause I figured that by the time I’d done this, and called IsDialogMessage, and so on, there was nothing left in the standard class that was useful to me. So I just registered my own class for dialog boxes and let it go from that.
The Windows dialog template system is showing its age a bit, I think. Last time I used it, it was showing signs of stress around the edges, particularly when it came to creating the C++ objects that managed the custom controls that were created by it.
Maybe its just me, but I prefer a dialog-creation system that’s completely integrated into my framework and which does the object creation too.
A proper dialog system should not rely on a existing GUI. And most important, a dialog system should not dictate program flow.
Thursday, August 31, 2006 3:23 PM by Jules
> I eventually abandoned this approach because
> you can’t get pixel-resolution sizing this
> way, as the size of a dialog is specified in
> dialog units (of course).
I think that there are APIs that will figure out how many pixels you have and how many you need for each control, but … well, maybe this would be a candidate for the suggestion box. As far as I could tell, for each control that uses a different font from the dialog box’s main font, I would have to create a new separate invisible dialog box, set that one’s font to the one we do computations with, call the APIs and do some computations, etc. I gave up. I think it’s possible, but if I tried it I’d probably get fired for wasting the amount of time that would take.
Meanwhile some header files declare a constant named
DS_USEPIXELS
Now what would that be for? We don’t know any company that would dare to make internal use of such an enormously useful feature while preventing everyone else from using such an enormously useful feature. And it is 100% fully undocumented, as far as I can find. So what in the world is this declaration doing in some header files?
It should be blatantly obvious from the
#if
that this is a Windows CE-only style. You can take this up with the Windows CE folks. It boggles the mind that that seeing a Windows CE-only style not documented in the Platform SDK (which covers Windows NT not CE) can lead to accusations that this “undocumented” style is being used “secretly” by a platform that doesn’t even support it! You owe me two hours of my life back. -Raymond]"Meanwhile, if Microsoft weren’t using DS_USEPIXELS, and since no one else can use it, I still wonder how that declaration got into some header files."
It would be nice to get a clear answer – or, better still, a documented API for doing it – but it seems the explanation is just "It’s something used in WinCE but not Win32", which is why it’s #ifdefed out in the SDK. Rather like the internal build test script written in Perl which managed to sneak into the WinXP CDs: accidental leakage, rather than proof MS is part of the alien conspiracy to distract us from UFO sightings with their fake crop circles.
MAKEINTRESOURCE(32770) used to work too.
"You owe me two hours of my life back. -Raymond]"
Well, you could have saved an hour and three quarters of that by reading my post (fifteen minutes after Norman’s) where I pointed out it’s WinCE-only and if’ed out in the SDK headers… :-)
"Do your dialog contents copy with Ctrl-C?"
If an edit control has focus, the usual shortcuts like this work. I can’t find any other system behaviour related to this, so I assume this must be what you’re talking about, so the answer is yes.
"Are they readable with screen readers?"
Yes, at least with Narrator anyway. And I didn’t have to do anything special to make it work, either. Screen readers are quite smart, these days. They seem to infer a lot from tab order, but as long as you’re sensible with window creation order that’s fine.
"Do they make the system-wide user-defined event sounds when displayed?"
I’ll admit they don’t do that, and probably should.
"Do they use system-wide user-defined styles?"
They use standard Windows components. They’ll use user-defined styles as much as any other window does.
"Do they deal correctly with all fonts and things like BiDi text?"
As long as the Windows API functions for measuring the size of text work correctly, then yes. Probably better than the standard dialog manager, because a dialog layout could easily break if you changed a dialog using that between two fonts with wildly different character spacings (e.g. a proportional font to a monospaced one… most of your spaces aren’t going to be wide enough any more).
I had very good reasons for breaking from the standard dialog manager’s control creation mechanism, namely that it wouldn’t measure the size controls actually need to be, and relied on me specifying sizes, which I felt didn’t work very well for environments where such things could easily change (especially seeing as the library in question needs to work cross-platform).