Showing tag results for Code

Jun 23, 2014
Post comments count0
Post likes count1

Adding a sound to the Alt+Tab window

Raymond Chen
Raymond Chen

Today's Little Program plays a sound when the Alt+Tab window appears and disappears. The program registers an accessibility event hook for the and events. The Start event fires when an Alt+Tab operation begins, and the End event fires when an Alt+Tab operation completes. As noted in the documentation, you can get spurious End events, so we k...

Code
Jun 20, 2014
Post comments count0
Post likes count1

Once you go input-idle, your application is deemed ready to receive DDE messages

Raymond Chen
Raymond Chen

Feel free to stop using DDE. There was one customer who confessed that they were still using DDE, and they asked for help debugging a DDE problem. They found that sometimes, when their application was launched for DDE, it never received the message. Instead, the function returned . If launched from Explorer, the error message shown to the user ...

Code
Jun 16, 2014
Post comments count0
Post likes count1

Enumerating bit strings with a specific number of bits set (binomial coefficients strike again)

Raymond Chen
Raymond Chen

Today's Little Program prints all bit strings of length n subject to the requirement that the string have exactly k 1-bits. For example, all bit strings of length 4 with 2 bits set are 0011, 0101, 0110, 1001, 1010, and 1100. Let's write BitString(n, k) to mean all the bit strings of length n with exactly k bits set. Let's look at the last b...

Code
Jun 13, 2014
Post comments count0
Post likes count1

Non-classical processor behavior: How doing something can be faster than not doing it

Raymond Chen
Raymond Chen

Consider the following program: The program generates a lot of random integers in the range 0..9 and then counts how many are less than 0, less than 1, less than 2, and so on. It also prints how long the operation took in QPC units. We don't really care how big a QPC unit is; we're just interested in the relative values. (We print the number of...

Code
Jun 12, 2014
Post comments count0
Post likes count1

Can we continue to call FindNextFile() with the same handle that returned an error last time?

Raymond Chen
Raymond Chen

A customer wanted to know whether it was okay to call with the same handle that returned an error last time. In other words, consider the following sequence of events: The customer elaborated: Suppose that the directory contains four files, A, B, C, and D. We expect the following: After returns an error, can we continue to search with th...

Code
Jun 9, 2014
Post comments count0
Post likes count1

Improving the performance of CF_HDROP by providing file attribute information

Raymond Chen
Raymond Chen

The clipboard format is still quite popular, despite its limitation of being limited to files. You can't use it to represent virtual content, for example. For all of you still using , you can improve the performance of drag/drop operations by adding a little more information to your data object. Observe that the clipboard format is just a l...

Code
Jun 5, 2014
Post comments count0
Post likes count1

Closing over the loop variable is just as harmful in JavaScript as it is in C#, and more cumbersome to fix

Raymond Chen
Raymond Chen

Prerequisite reading: Closing over the loop variable considered harmful. JavaScript has the same problem. Consider: The most common case where you encounter this is when you are hooking up event handlers in a loop, so that's the case I used as an example. No matter which button you click, they all alert , rather than the respective button ...

Code
Jun 2, 2014
Post comments count0
Post likes count1

Obtaining information about the user's wallpaper on multiple monitors

Raymond Chen
Raymond Chen

Today we're going to dump information about the user's wallpaper settings on multiple monitors. The idea is simple. You use the interface on the object to get information about the desktop wallpaper. It will tell you the wallpaper positioning information, whether a single image is being used for all monitors, where those monitors are, and whic...

Code
May 30, 2014
Post comments count0
Post likes count1

Why does GetFileVersionInfo map the whole image into memory instead of just parsing out the pieces it needs?

Raymond Chen
Raymond Chen

Commenter acq responds (with expletive deleted), "the whole file is mapped into the process' memory only for version info that's certainly only a few kilobytes to be read?" Why not map only the parts that are needed? "I don't understand the necessity to map the whole file except that it was easier to write that code without thinking too much." Tha...

Code