The Old New Thing

What’s the difference between GetKeyState and GetAsyncKeyState?

I've seen some confusion over the difference between the function and the function. returns the virtual key state. In other words, reports the state of the keyboard based on the messages you have retrieved from your input queue. This is not the same as the physical keyboard state: When should you use and when should you use...

Simple things you can do with the ShellExecuteEx function

Here's a tiny little program: #include <windows.h> #include <shellapi.h> int __cdecl main(int argc, char **argv) { if (argc == 3) { SHELLEXECUTEINFO sei = { sizeof(sei) }; sei.fMask = SEE_MASK_FLAG_DDEWAIT; sei.nShow = SW_SHOWNORMAL; // added 27 Nov sei.lpVerb = argv[1]; sei.lpFile = argv[2]; ...

Why do folders like “My Pictures” come back after I delete them?

Some people are offended by the special folders like "My Pictures" and "My Music" and delete them, only to find them being re-created. What's going on? Windows itself is okay with you deleting those folders. Some corporations, for example, remove those folders from their employees' machines because they don't want the employees looking at ...

The various ways of sending a message

There are several variations on the SendMessage function, but some are special cases of others. The simplest version is SendMessage itself, which sends a message and waits indefinitely for the response. The next level up is SendMessageTimeout which sends a message and waits for the response or until a certain amount of time has elapsed...

How do I break an integer into its component bytes?

Warning: .NET content ahead. For some reason, this gets asked a lot. To break an integer into its component bytes, you can use the BitConverter.GetBytes method: int i = 123456; byte[] bytes = BitConverter.GetBytes(i); After this code fragment, the byte array contains { 0x40, 0xE2, 0x01, 0x00 }. Update 11am: The endian-ness ...

Advantages of knowing your x86 machine code

Next time you find yourself debugging in assembly language (which for some of us is the only way we debug), here are some machine code tricks you may wish to try out: 90 This is the single-byte NOP opcode. If you want to patch out code and don't want to think about it, just whack some 90's over it. To undo it, you have to patch ...

Accessing the current module’s HINSTANCE from a static library

If you're writing a static library, you may have need to access the HINSTANCE of the module that you have been linked into. You could require that the module that links you in pass the HINSTANCE to a special initialization function, but odds are that people will forget to do this. If you are using a Microsoft linker, you can take advantage ...

Let WMI do the heavy lifting of determining system information

Windows Management Instrumentation is a scriptable interface to configuration information. This saves you the trouble of having to figure it out yourself. For example, here's a little program that enumerates all the CPUs in your system and prints some basic information about them. var locator = WScript.CreateObject("WbemScripting....

Implementing higher-order clicks

Another question people ask is "How do I do triple-click or higher?" Once you see the algorithm for double-clicks, extending it to higher order clicks should be fairly natural. The first thing you probably should do is to remove the CS_DBLCLKS style from your class because you want to do multiple-click management manually. Next, you can ...