The Old New Thing

Why does the system convert TEMP to a short file name?

When you set environment variables with the System control panel, the and variables are silently converted to their short file name equivalents (if possible). Why is that? For compatibility, of course. It is very common for batch files to assume that the paths referred to by the and environment variables do not contain any embedded ...

Do you need clean up one-shot timers?

The CreateTimerQueueTimer function allows you to create one-shot timers by passing the WT_EXECUTEONLYONCE flag. The documentation says that you need to call the DeleteTimerQueueTimer function when you no longer need the timer. Why do you need to clean up one-shot timers? To answer this, I would like to introduce you to one of my ...

BOOL vs. VARIANT_BOOL vs. BOOLEAN vs. bool

Still more ways of saying the same thing. Why so many? Because each was invented by different people at different times to solve different problems. BOOL is the oldest one. Its definition is simply typedef int BOOL; The C programming language uses "int" as its boolean type, and Windows 1.0 was written back when C was the cool ...

Dragging a shell object, part 5: Making somebody else do the heavy lifting

Creating that drag image was a bit of work. Fortunately, the listview control is willing to do some of the work for you. Throw away the OnLButtonDown function (and the HANDLE_MESSAGE that goes with it). Instead, we'll make the listview do all our presentation for us. BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpcs) { g_hwndChild = ...

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