Showing results for Code - The Old New Thing

Dec 10, 2004
0
0

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

Raymond Chen
Raymond Chen

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 = CreateWindow(...

Code
Dec 9, 2004
0
0

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

Raymond Chen
Raymond Chen

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

Code
Dec 8, 2004
0
0

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

Raymond Chen
Raymond Chen

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, int x...

Code
Dec 7, 2004
0
0

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

Raymond Chen
Raymond Chen

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

Code
Nov 30, 2004
0
0

What’s the difference between GetKeyState and GetAsyncKeyState?

Raymond Chen
Raymond Chen

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

Code
Nov 26, 2004
0
0

Simple things you can do with the ShellExecuteEx function

Raymond Chen
Raymond Chen

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]; ShellExecuteEx...

Code
Nov 23, 2004
0
0

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

Raymond Chen
Raymond Chen

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

Code
Nov 19, 2004
0
0

The various ways of sending a message

Raymond Chen
Raymond Chen

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

Code
Nov 17, 2004
0
0

How do I break an integer into its component bytes?

Raymond Chen
Raymond Chen

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

Code