The Old New Thing

Why doesn't my MessageBox wrap at the right location?

A customer reported that the function was wrapping text "at the wrong location." Our program displays a message with the function, and we use the '\n' character to force line breaks at positions we choose. But we've found that starting in Windows Vista, the line breaks we placed are not working. The function is inserting its own line ...

How do I make a window remain visible even when the user selects Show Desktop?

A customer had this question: I'd like to know how to get a window to remain visible, even when the user has selected Show Desktop. Right now, when the user picks Show Desktop, the desktop appears and covers my window. Um, yeah, because that's the whole point of Show Desktop: To show the desktop and get rid of all those windows that are in ...

How do I create a right-aligned toolbar button?

I didn't think this was all that common a request, but it came in twice from two different customers, so I guess there are still people creating toolbars, and creating them with right-aligned buttons (even though it violates Windows user interface guidelines, though I can't find a citation right now). You may have noticed that the toolbar ...

How do I convert a UTF-8 string to UTF-16 while rejecting illegal sequences?

By default, when you ask to convert a UTF-8 string to UTF-16 that contains illegal sequences (such as overlong sequences), it will try to muddle through as best as it can. If you want it to treat illegal sequences as an error, pass the flag. The MSDN documentation on this subject is, to be honest, kind of hard to follow and even includes a...

Generally speaking, if your function fails, you should return a failure code

A customer requested assistance with their shell namespace extension, and the request worked its way to me for resolution. The customer was at a loss because the customer's code was nowhere on the stack. What is wrong? The customer didn't provide a dump file or any other information beyond the stack trace. (Hint: When reporting a problem...

Swamping the thread pool with work faster than it can drain

This scenarios is real, but details have been changed to protect the guilty. Consider a window showing the top of a multi-page document. The developers found that when the user clicks the down-arrow button on the scroll bar, the program locks up for 45 seconds, over a dozen threads are created, and then suddenly everything clears up and the...

How do I control X-Mouse settings (active window tracking)?

For quite some time, Windows has had a setting officially called active window tracking but which informally goes by the name X-Mouse, because that was the name of the PowerToy which first exposed the feature. (The PowerToy was in turn so-named because it made the mouse behave in a manner similar to many X window managers.) The setting is ...

How do I prevent users from pinning my program to the taskbar?

A customer wanted to prevent users from pinning their application to the taskbar. I have an application that is launched as a helper by a main application. Users shouldn't be launching it directly, but rather should be launching the main application. But since the helper shows up in the taskbar, users may be tempted to right-click on the ...

How do IsThemeActive, IsAppThemed, and IsCompositionActive differ?

There are three functions which test very similar things, and sometimes applications pick the wrong one. Here's the rundown: Note that these functions do not answer the question "Is the application using the visual-styles-enabled version of the common controls library?" That question is harder to answer because the decision to use the ...