Why isn't there a GetDlgItemFloat function?

Raymond Chen

Jonathan Wilson asks, “Do you know why there is a GetDlgItemInt and a SetDlgItemInt but not a GetDlgItemFloat and a SetDlgItemFloat?” Give people five dollars and they’ll ask why you didn’t give them ten. Let’s start with the first question. Why is there a GetDlgItemInt function? After all, GetDlgItemInt doesn’t do anything you couldn’t already do with GetDlgItemText and atoi. Well, reading integers out of dialog boxes is a rather common operation, something that the built-in Windows components do quite a lot of, so making this two-part helper function available more generally available seemed like a reasonable thing to do in the cause of reducing code size. On a 256KB machine, reducing code size is a big deal. So why stop there? Why not also do floating point? Well, the 8086 processor doesn’t have floating point support. If you wanted hardware floating point support, you had to shell out the extra bucks for an 8087 coprocessor. To run on computers that didn’t have an 8087 coprocessor, you had to include a floating point emulator, which is not a small library. It would have been excessive to add the entire floating point emulator to the window manager for the benefit of two functions most programs never call. “You’re telling me that over 10% of memory is being consumed by some math library that I never use?” Which leads to the next point: Most computer programs don’t use floating point anyway. I don’t think a single Windows program I’ve written in the past ten years has had need for floating point much less needed to read one from a dialog box. Sure, if you’re doing numerical work, then you need floating point, but most Windows programs are like Regedit and Notepad, not Excel. Adding GetDlgItemFloat to the window manager would have required adding the floating point emulator to the window manager (a big kick in the teeth since the window manager is always loaded), as well as atof (which is not an easy function to write). If you want GetDlgItemFloat you can write it yourself, and then you can shoulder the burden of runtime floating point support and handling floating point exceptions. (We’ll learn more about the scary world of floating point exceptions in a few months.) (For a similar reason, the wsprintf function does not support floating point.)

Pre-emptive Igor Levicki comment: “Windows Vista is a bloated piece of junk.”

0 comments

Discussion is closed.

Feedback usabilla icon