The Old New Thing

Dragging a shell object, part 4: Adding a prettier drag icon

You may have noticed that the drag feedback is rather sad-looking. Just a box, maybe with a plus sign or an arrow; you don't even know what it is you're dragging. Let's fix that. We'll drag the icon of the file around. We'll need to add the drag image to the data object. void OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT...

Dragging a shell object, part 3: Detecting an optimized move

We were considering how to detect that the drag/drop operation resulted in a conceptual Move even if the DROPEFFECT_MOVE was optimized away. If the drop target is the shell, you can query the data object for CFSTR_PERFORMEDDROPEFFECT to see what the performed effect was. void OnLButtonDown(HWND hwnd, BOOL fDoubleClick, ...

Dragging a shell object, part 2: Enabling the Move operation

Let's say that we did want to support Move in our drag/drop program, for whatever reason. Let's do it with some scratch file instead of clock.avi, though. Create a file somewhere that you don't mind losing; let's say it's C:\throwaway.txt. Change the function OnLButtonDown as follows: void OnLButtonDown(HWND hwnd, BOOL fDoubleClick...

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