1. A Question or Two

Howdy.

Anybody know how to make a program accept drag-and-dropped
files/text/etc.?

I had another question or two but I forgot 'cuz I got interrupted here.

I'll try again later. :)

Thanks in advance!
ck

new topic     » topic index » view message » categorize

2. Re: A Question or Two

ck asked:

> Anybody know how to make a program accept drag-and-dropped
> files/text/etc.?

It looks like the steps are:

    1. Register your app with the DragAcceptFiles function
    2. Look for the WM_DROPFILES event
    3. Use DragQueryFile to get the file names

Here's what I got from the Win32 help file:

The DragAcceptFiles function registers whether a window accepts dropped
files.

    VOID
ceptFiles(
        HWND hWnd, // handle to the registering window
        BOOL fAccept // acceptance option
    );


The WM_DROPFILES message is sent when the user releases the left mouse button
while the cursor is in the window of an application that has registered itself
as a recipient of dropped files.

    WM_DROPFILES
        hDrop = (HANDLE) wParam;  // handle of internal drop structure


The DragQueryFile function retrieves the filenames of dropped files.

    UINT DragQueryFile(
        HDROP hDrop, // handle to structure for dropped files
        UINT iFile, // index of file to query
        LPTSTR lpszFile, // buffer for returned filename
        UINT cch  // size of buffer for filename
   );


Parameters:
[hDrop]
Identifies the structure containing the filenames of the dropped files.

[iFile]
Specifies the index of the file to query. If the value of the iFile parameter
is 0xFFFFFFFF, DragQueryFile returns a count of the files dropped. If the value
of the iFile parameter is between zero and the total number of files dropped,
DragQueryFile copies the filename with the corresponding value to the buffer
pointed to by the lpszFile parameter.

[lpszFile]
Points to a buffer to receive the filename of a dropped file when the function
returns. This filename is a null-terminated string. If this parameter is NULL,
DragQueryFile returns the required size, in characters, of the buffer.

[cch]
Specifies the size, in characters, of the lpszFile buffer.

[Return Values]
When the function copies a filename to the buffer, the return value is a count
 of the characters copied, not including the terminating null character.

If the index value is 0xFFFFFFFF, the return value is a count of the dropped
files.

If the index value is between zero and the total number of dropped files and
the lpszFile buffer address is NULL, the return value is the required size,
in characters, of the buffer, not including the terminating null character.

This should be enough to get you in business.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu