Windows Client Development--enable your input box to have the ability to drag and drop uploads

Source: Internet
Author: User

Today talk about a day Windows client drag and drop upload feature.

In fact, the main drag-and-drop function, upload is their own implementation.

DragAcceptFiles function

The most important thing is this function, look at the role:
Registers whether a window accepts dropped files

Prototype:

VOID DragAcceptFiles(   HWND hWnd,   BOOL fAccept);

Parameters:
HWnd
Type:hwnd
The identifier of the window is registering whether it would accept dropped files.
Faccept
Type:bool
A value that indicates if the window identified by the HWND parameter accepts dropped files. This value was TRUE to accept dropped files or FALSE to discontinue accepting dropped files.

header Files and libraries:

Shellapi.hShell32.lib

This is very simple, first get a handle to the window, and then call the DragAcceptFiles function:

    TRUE);

Next is the message response ~ ~ ~

wm_dropfiles Message
Sent when the user drops a file in the window of an application, has registered itself as a recipient of dropped files .

Now we have to deal with Wm_dropfiles news:

dragqueryfile function
Retrieves the names of dropped files, the result from a successful drag-and-drop operation.
(after completion) a successful drag-and-drop operation gets information such as the name of the dragged file.
Prototype:

DragQueryFile(  _In_  HDROP  hDrop,  _In_  UINT   iFile,  _Out_ LPTSTR lpszFile,        UINT   cch);

Parameters:
Hdrop [in]
Type:hdrop
Identifier of the structure that contains the file names of the dropped files. Br>ifile [in]
Type:uint
Index of the file to query. If the value of this parameter is 0xFFFFFFFF, Dragqueryfile returns a count of the files dropped. If the value of this parameter are between zero and the total number of files dropped, dragqueryfile copies the file name W ith the corresponding value to the buffer pointed to by the Lpszfile parameter.
Lpszfile [out]
Type:lptstr
The address in a buffer that receives the file name of a dropped file when the Ction returns. This file name is a null-terminated string. If This parameter was NULL, Dragqueryfile returns the required size, in characters, of this buffer.
CCH
Type:uint
The size, in characters, of the lpszfile buffer.

Focus on the return value:
Type:uint
A nonzero value indicates a successful call.
When the function copies a file name to the buffer, the return value was a count of the characters copied, not including th e terminating null character.
If the index value is 0xFFFFFFFF, the return value is a count of the dropped files. Note that the index variable itself returns unchanged, and therefore remains 0xFFFFFFFF.
If The index value is between zero and the total number of dropped files, and the lpszfile buffer address is NULL, the RET Urn value is the required size, in characters, of the buffer, not including the terminating null character.
This return value can be used to determine whether the dragged is a single file.

See the first parameter
Hdrop

HDROP hDrop = (HDROP)wParam

dragfinish function
Releases memory that the system allocated for use in transferring file names to the application
Windows programming always remembers that you want to release the resource after you get it.

getfileattributes function
GetFileAttributes function returns the properties of the file system for a specified file or directory.
If you decide whether the dragged folder can be this way:

GetFileAttributes(file_path)&FILE_ATTRIBUTE_DIRECTORY

The last chrysanthemum, hand slip, is the complete code:

Hdrop Hdrop = (hdrop) WParam; UINT nfilenum = Dragqueryfile (Hdrop,0xFFFFFFFF,NULL,0);            TCHAR File_path[max_path]; Dragqueryfile (Hdrop,0, File_path, MAX_PATH); Dragfinish (Hdrop);//Release Hdrop            if(GetFileAttributes (File_path) &file_attribute_directory) {MessageBox (NULL, L"Allow only single files to be dragged", L"Drag and drop Files",NULL); }Else if(Nfilenum >1) {MessageBox (NULL, L"Allow only single files to be dragged", L"Drag and drop Files",NULL); }Else{//Upload a single file}        }

Windows Client Development--enable your input box to have the ability to drag and drop uploads

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.