The Old New Thing

Using WM_SETREDRAW to speed up adding a lot of elements to a control

Today's Little Program shows one way you can implement a better version of . Our first version doesn't use at all. Start with the scratch program and make the following changes: Most of this program was stolen from my scroll bar series. The interesting new bits are that you can add one new item by hitting 1, or you can add ten thousand...

It's bad enough for a guest to demolish the host's house; demolishing an unrelated person's house is taking it to a whole new level

"How do I destroy a window that belongs to another process?" The function will not destroy windows that belong to another thread, much less another process. The best you can do is post a message to the window to ask it nicely. The function response to the message by destroying the window, but the window is free to add a custom handler ...

A puzzle involving dynamic programming, or maybe it doesn't

Here's a programming challenge: Evaluate the following recurrence relation efficiently for a given array [x0, …, xn−1] and integer k. Hint: Use dynamic programming. In words: If the array has only two elements, then the result is the average of the two elements. If the array has more than two elements, then ...

The dangers of buffering up posted messages and then reposting them later

A customer wanted to check that their idea for solving a re-entrancy problem doesn't have any hidden gotchas. We have a window which processes incoming work. One of our work items enters a modal loop, and if new work gets posted to the window while the modal loop is running, our work manager gets re-entered, and Bad Things happen. Our ...

Functions that return GDI regions rarely actually return regions

For reasons I don't quite understand, the only functions in GDI and USER which create GDI regions are the functions with in their name, like or . All the other functions which return a region require you to pass an existing region to use as the output. I can see this being useful for , because you can set your output region to be equal to...

Can CoCreateGuid ever return GUID_NULL?

A customer asked whether the function can ever return . Their code uses for special purposes, and it would be bad if that was ever returned as the GUID for an object. "Can we assume that never returns ? Or should we test the return value against , and if it is equal, then call and try again?" Some people started running a bunch of times ...

Going for the facts: Who is displaying this message box?

A customer wanted to know whether had a problem with Unicode. A problem with it? Quite the contrary. loves Unicode! In fact, if you call the ANSI version, it converts the strings to Unicode and then finishes the work in Unicode. Okay, here's the customer's problem. We have a custom application written in managed code. When we launch ...

How do I show the contents of a directory while respecting the user's preferences for hidden and super-hidden files as well as the user's language preferences?

A customer was writing a program in (and this is what they said) "32 bit C++ .Net 4.0" which displayed the contents of a directory, and they wanted to filter out items such as hidden files and protected operating system files (also known as super-hidden files) based on the user's current Explorer preferences. Furthermore, they wanted to show ...