Showing results for Code - The Old New Thing

Jun 17, 2011
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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 the w...

Code
Jun 16, 2011
Post comments count0
Post likes count0

How do I create a right-aligned toolbar button?

Raymond Chen
Raymond Chen

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 common c...

Code
Jun 15, 2011
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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 doub...

Code
Jun 13, 2011
Post comments count0
Post likes count0

You don't need to steal focus if you can just arrange for someone to give it to you

Raymond Chen
Raymond Chen

Commenter doesn't matter proposes a scenario where focus-stealing is necessary: There are two applications A and B, Application B exposes an interface, and Application A connects to application B via that interface, When some sort of even occurs in application B, it notifies application A, which wants to steal fo...

Code
Jun 10, 2011
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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 with...

Code
Jun 3, 2011
Post comments count0
Post likes count0

Swamping the thread pool with work faster than it can drain

Raymond Chen
Raymond Chen

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 wind...

Code
Jun 2, 2011
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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 exposed ...

Code
Jun 1, 2011
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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 taskbar...

Code
May 26, 2011
Post comments count0
Post likes count0

How do IsThemeActive, IsAppThemed, and IsCompositionActive differ?

Raymond Chen
Raymond Chen

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 visual-sty...

Code
May 25, 2011
Post comments count0
Post likes count1

WinMain is just the conventional name for the Win32 process entry point

Raymond Chen
Raymond Chen

is the conventional name for the user-provided entry point in a Win32 program. Just like in 16-bit Windows, where the complicated entry point requirements were converted by language-provided startup code into a call to the the user's function, the language startup code for 32-bit programs also does the work of converting the raw entry point in...

Code