Showing results for Code - The Old New Thing

Dec 19, 2013
Post comments count0
Post likes count0

How do I display an RTL string in a notification balloon on an LTR system?

Raymond Chen
Raymond Chen

Suppose you have a program that is written in Arabic or Hebrew and you want to render some text. No problem. You just call and pass the flag to say, "Please render this string in an RTL context." Many other text-rendering functions have a similar flag, such as for . But what if you don't control the call to or or whatever other function is ...

Code
Dec 16, 2013
Post comments count0
Post likes count0

Disabling the PrtSc key by blocking input

Raymond Chen
Raymond Chen

A customer asked how to disable the PrtSc key in the On-Screen Keyboard. There is no way to disable the PrtSc key in the On-Screen Keyboard. The On-Screen Keyboard shows a keyboard, and you can click any virtual key you like. There is no policy to remove specific keys from the On-Screen Keyboard. But this was a case of a customer breaking down...

Code
Dec 12, 2013
Post comments count0
Post likes count0

How do you intercept taskbar notification balloons?

Raymond Chen
Raymond Chen

A customer wanted to know how they could monitor and intercept taskbar notification balloons. In particular, they wanted to intercept the clicks on a particular balloon and take alternative action. There is no supported mechanism for intercepting taskbar notification balloons or redirecting clicks on them. Imagine if that were possible: Fabrikam ...

Code
Dec 9, 2013
Post comments count0
Post likes count0

Destroying all child processes (and grandchildren) when the parent exits

Raymond Chen
Raymond Chen

Today's Little Program launches a child process and then just hangs around. If you terminate the parent process, then all the children (and grandchildren and great-grandchildren, you get the idea) are also terminated. The tool for this is the Job Object. Specifically, we mark the job as "kill on job close" which causes all processes in the job ...

Code
Dec 6, 2013
Post comments count0
Post likes count0

Is it wrong to call SHFileOperation from a service?

Raymond Chen
Raymond Chen

A customer had a simple question: "Is it wrong to call from a service?" I don't know if I'd call it wrong, but I'd call it highly inadvisable. Update: See Is it wrong to call SHFileOperation from a service? Revised.

Code
Dec 4, 2013
Post comments count0
Post likes count0

What's the difference between the wParam of the WM_NOTIFY message and the idFrom in the NMHDR structure?

Raymond Chen
Raymond Chen

The message takes the following parameters: Notice that the identifier of the control sending the message appears in two places, once in the and again in the . What's the difference? There is no difference. It's just a convenience. The same value is passed in both places, and you can check whichever one is easier for you. You might use the ...

Code
Dec 2, 2013
Post comments count0
Post likes count0

Logging the foreground process as it changes

Raymond Chen
Raymond Chen

Today's Little Program simply logs all changes to the foreground window by recording the path to the application the user switched to. You might use this as part of a usability study to monitor what applications users spend most of their time in. Most of this code is just taking things we already know and snapping them together. Usin...

Code
Nov 29, 2013
Post comments count0
Post likes count0

Why can't I create my dialog with DialogBox, DialogBoxParam, CreateDialog, CreateDialogParam, or the indirect versions of same?

Raymond Chen
Raymond Chen

One of the purposes of my dialog manager series was to help people diagnose problems with their dialog boxes. But since I embedded the tips inside the series body, it's hard for people to find them, and I still end up answering the same questions over and over. So here it is in a separate article that hopefully people can find. Why your call ...

Code
Nov 28, 2013
Post comments count0
Post likes count0

If you try to declare a variadic function with an incompatible calling convention, the compiler secretly converts it to cdecl

Raymond Chen
Raymond Chen

Consider the following function on an x86 system: The function declares itself as , which is a callee-clean convention. But a variadic function cannot be callee-clean since the callee does not know how many parameters were passed, so it doesn't know how many it should clean. The Microsoft Visual Studio C/C++ compiler resolves this conflict by...

Code