A. This article will give readers a solution to the following two questions:
1, users cut/Copy (cut/copy) files in the Resource Manager (Windows Explorer), and then paste (Paste) operations in their own applications;
2. Users cut/Copy files in their applications and paste operations in resource management.
Two. The Code authoring tool and test environment in this article:
1,vc6.0, Platform SDK (no MFC required);
2.Windows 2000.
Three. Overview
We know that in Windows you can share and pass data through the Clipboard (Clipboard), such as cutting/copying/pasting files in the Resource Manager (Windows Explorer). We can also do this through the Clipboard in our own applications to improve interoperability between our own applications and the Windows operating system. But how can we share and deliver data with applications such as the explorer? This article provides a way to achieve data sharing and delivery through the clipboard using some of the data structures and APIs provided by Windows itself.
Four. Implementation methods
First, Windows does not write the file name to the Clipboard when it cuts/copies the file, but instead puts a draganddrop file object in the Clipboard and writes a status value to identify the type of operation (move/copy, cut is actually moving, if you cut it and not paste it, Then the file still exists without being deleted. Based on this knowledge, let's take a look at how the Windows Explorer's Cut/copy action is identified in the application.
Before using the Clipboard, we first want to open it:
BOOL OpenClipboard(HWND hWnd);
参数 hWnd 是打开剪贴板的窗口句柄,成功返回TRUE,失败返回FALSE。
You can then use GetClipboardData to get the data from the Clipboard:
HANDLE GetClipboardData(UINT uFormat);
Uformat is the format of the data you want, such as the format of the drag-and-drop object in this article Cf_hdrop. The data format that indicates the Drop object type (move/copy) is not a Windows standard clipboard structure, but rather a simple DWORD pointer. We can register the data type with the following statement:
UINT uDropEffect=RegisterClipboardFormat("Preferred DropEffect");
The Udropeffect returned here is the code of the data structure that we will be substituting for the GetClipboardData function,
The GetClipboardData function return is a handle, which is just what Windows does for unification, and we can convert it to the appropriate data form as needed, such as our udropeffect is a DWORD pointer.
As I've said before, there is a drag-and-drop object on the Clipboard, so we can get that object from the following statement:
HDROP hDrop = HDROP( GetClipboardData( CF_HDROP));
If there is a Hdrop object, we should get the udropeffect data so that we can process the following file:
DWORD dwEffect=*((DWORD*)(GetClipboardData( uDropEffcet)));
As for the meaning of this value, we simply include "Oleidl." H "header file can be, in the header file in the definition of 5 states and this article is only concerned:
#define DROPEFFECT_COPY ( 1 )
#define DROPEFFECT_MOVE ( 2 )