Showing results for Code - The Old New Thing

Jul 19, 2012
Post comments count0
Post likes count0

Why do some font names begin with an at-sign?

Raymond Chen
Raymond Chen

It was a simple question. For some reason, my font selection dialog () shows a bunch of font names beginning with the at-sign (@). These fonts don't work correctly if I use them. Any idea what they are? (I tried searching the Internet, but search engines don't seem to let you search for so it's hard to make much headway.) (And that's why I...

Code
Jul 13, 2012
Post comments count0
Post likes count0

Why doesn't RealGetWindowClass return the real window class for my superclass?

Raymond Chen
Raymond Chen

A customer was reporting that the function was not reporting the base window class of their superclass. (Error checking has been elided for expository purposes.) The customer found that the assertion fails, returning a window class name of "AwesomeWindow" instead of "static". "I thought the point of RealGetWindowClass was to dig through the su...

Code
Jul 12, 2012
Post comments count0
Post likes count0

What happens when you mark a section as DISCARDABLE?

Raymond Chen
Raymond Chen

In the flags you pass to the linker, you can specify that a section be made discardable. What does that mean? If you are a kernel-mode driver, the discardable flag means that the contents will be removed from memory after initialization is complete. This is where you put your initialization code and data. But if you're writing user-mode code, t...

Code
Jul 5, 2012
Post comments count0
Post likes count0

How your taskbar auto-hide settings can keep getting overwritten

Raymond Chen
Raymond Chen

A customer reported that they were observing that some users were finding their taskbar set to auto-hide even though the standard configuration in the company is for the auto-hide feature to be disabled. Going into Taskbar Properties shows Auto-hide the taskbar checked. None of the users had changed their setting to auto-hide manually, so the quest...

Code
Jun 28, 2012
Post comments count0
Post likes count0

You still need the "safe" functions even if you check string lengths ahead of time

Raymond Chen
Raymond Chen

Commenter POKE53280,0 claims, "If one validates parameters before using string functions (which quality programmers should do), the 'safe' functions have no reason to exist." Consider the following function: What could possibly go wrong? You check the length of the string, and if it doesn't fit in the buffer, then you reject it. Therefore, y...

Code
Jun 21, 2012
Post comments count0
Post likes count0

When the default pushbutton is invoked, the invoke goes to the top-level dialog

Raymond Chen
Raymond Chen

One quirk of nested dialogs lies in what happens when the user presses Enter to invoke the default pushbutton: The resulting message goes to the top-level dialog, even if the default pushbutton belongs to a sub-dialog. Why doesn't it send the to the parent of the default pushbutton? I mean, the dialog manager knows the handle of the button, so...

Code
Jun 20, 2012
Post comments count0
Post likes count0

When embedding a dialog inside another, make sure you don't accidentally create duplicate control IDs

Raymond Chen
Raymond Chen

The extended style (known in dialog templates as ) instructs the dialog manager that the dialog's children should be promoted into the dialog's parent. This is easier to explain in pictures than in text. Given the following window hierarchy: The result of the extended style being set is that the children of B are treated as if they were di...

Code
Jun 19, 2012
Post comments count0
Post likes count0

It's not a good idea to give multiple controls on a dialog box the same ID

Raymond Chen
Raymond Chen

When you build a dialog, either from a template or by explicitly calling , one of the pieces of information about each control is a child window identifier. And it's probably in your best interest to make sure two controls on the dialog don't have the same ID number. Of course, one consequence of giving two control the same ID number is that the ...

Code
Jun 14, 2012
Post comments count0
Post likes count0

Now that Windows makes it harder for your program to block shutdown, how do you block shutdown?

Raymond Chen
Raymond Chen

Up until Windows XP, applications could intercept the message and tell Windows, "No, don't shut down." If they were polite about it, they would also inform the user which application blocked system shutdown and why. And if they were really polite about it, they would even provide a way for the user to say, "I don't care; shut down anyway." A...

Code
Jun 8, 2012
Post comments count0
Post likes count0

How can I determine the underlying cause of a EXCEPTION_IN_PAGE_ERROR exception?

Raymond Chen
Raymond Chen

A customer was using memory-mapped files and installed an exception handler to log in-page errors in the memory-mapped file region. They wanted to know how they could obtain the real disk error that resulted in the memory manager not being able to page-in the requested data. Finding the answer isn't that hard. A quick search for reveals that ...

Code