Showing tag results for Code

Jun 29, 2011
Post comments count0
Post likes count1

What happens to WPARAM, LPARAM, and LRESULT when they travel between 32-bit and 64-bit windows?

Raymond Chen
Raymond Chen

The integral types , , and are 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. What happens when a 32-bit process sends a message to a 64-bit window or vice versa? There's really only one choice when converting a 64-bit value to a 32-bit value: Truncation. When a 64-bit process sends a message to a 32-bit window, the 64-bit ...

Code
Jun 28, 2011
Post comments count0
Post likes count1

How do I display the Find Printers dialog programmatically?

Raymond Chen
Raymond Chen

A customer wanted to display the Find Printers dialog programmatically to let the user pick a printer from Active Directory and wanted to know whether this was possible. Yes, it's possible, and there's more than one way to do it. There's the lazy way and the overachieving way. The overachieving way is to use the method. The sample function spe...

Code
Jun 24, 2011
Post comments count0
Post likes count1

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

Raymond Chen
Raymond Chen

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

Code
Jun 17, 2011
Post comments count0
Post likes count1

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 count1

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 count1

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 count1

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 count1

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 count1

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 count1

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