Showing tag results for 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
Jun 7, 2012
Post comments count0
Post likes count0

Eventually the window manager simply says that enough is enough

Raymond Chen
Raymond Chen

Many window manager operations are recursive, and eventually the window manager will simply say that enough is enough when the recursion goes too deep. We've seen this when you nest windows more than 50 levels deep or nest menus more than 25 levels deep, for example. (Note also that these limits may change in the future, so don't rely on being a...

Code
Jun 4, 2012
Post comments count0
Post likes count0

Why does PrintWindow hate CS_PARENTDC? Because EVERYBODY hates CS_PARENTDC!

Raymond Chen
Raymond Chen

Commenter kero wants to know why the function hates . (And , and .) Because everybody hates ! (And , and .) We saw earlier that these class styles violate widely-held assumptions about how drawing works. I mean, who would have thought that asking for two device contexts would give you the same one back twice? Or that changes to one device cont...

Code
Jun 1, 2012
Post comments count0
Post likes count0

How do I prefetch data into my memory-mapped file?

Raymond Chen
Raymond Chen

A customer created a memory mapping on a large file and found that when the memory manager wanted to page in data from that file, it did so in 32KB chunks. The customer wanted to know if there was a way to increase the chunk size for efficiency. The memory manager decides the chunk size for memory-mapped files, and the chunk size is currently set ...

Code
May 31, 2012
Post comments count0
Post likes count0

What happens if I call KillTimer with a NULL hwnd?

Raymond Chen
Raymond Chen

A customer discovered a bug in their code and wanted some information on how serious it was, so they could assess how urgently they need to issue a fix. We have code that calls with a valid window handle, but then we destroy the window before we get around to calling . When we finally do call , we do so with a window handle. The calls are proba...

Code
May 28, 2012
Post comments count0
Post likes count0

If my window hosts multiple windowless ActiveX controls, which one do I call IOleInPlaceActiveObject::TranslateAccelerator and IOleInPlaceObjectWindowless::OnWindowMessage on?

Raymond Chen
Raymond Chen

Commenter Farproc asks how one goes about hosting two windowless ActiveX controls in a single window. In particular, "none of the documentation explains how to choose which control to send and on?" Actually, the documentation does say. The documentation for says, "Active in-place objects must always be given the first chance at translating ac...

Code
May 25, 2012
Post comments count0
Post likes count0

The extern “C” specifier disables C++ mangling, but that doesn’t mean it disables mangling

Raymond Chen
Raymond Chen

The MSDN documentation on dllexport contains the following enigmatic paragraph, or at least did at the time I wrote this article: dllexport of a C++ function will expose the function with C++ name mangling. If C++ name mangling is not desired, either use a .def file (EXPORTS keyword) or declare the function as extern "C". I've seen this sente...

Code