DOCUMENT:Q152092 26-JUN-2002 [visualc] TITLE :DRAGD95.EXE OLE Drag/Drop in Windows 95 Common Controls PRODUCT :Microsoft C Compiler PROD/VER::4.0,4.1,4.2,5.0,6.0 OPER/SYS: KEYWORDS:kbfile kbole kbSample kbDragDrop kbMFC kbVC400 kbVC410 kbVC420 kbVC500 kbVC600 kbGrpDSM ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - The Microsoft Foundation Classes (MFC), used with: - Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1 - Microsoft Visual C++, 32-bit Enterprise Edition, versions 4.2, 5.0, 6.0 - Microsoft Visual C++, 32-bit Professional Edition, versions 4.2, 5.0, 6.0 - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 - Microsoft Visual C++.NET (2002) ------------------------------------------------------------------------------- NOTE: Microsoft Visual C++ .NET (2002) supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies to unmanaged Visual C++ code only. SUMMARY ======= This sample demonstrates implementing OLE drag and drop in Windows 95 Common controls. It also demonstrates how the drag image functionality can be preserved while dragging within the application that is the source of the data. MORE INFORMATION ================ The following files are available for download from the Microsoft Download Center: Visual C++ 6.0: The following file is available for download from the Microsoft Download Center: DownloadDownload Dragd95.exe now (http://download.microsoft.com/download/vc60pro/Sample10/1/NT4/EN-US/Dragd95.exe) For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base: Q119591 How to Obtain Microsoft Support Files from Online Services Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on secure servers that prevent any unauthorized changes to the file. Visual C++ .NET: The following file is available for download from the Microsoft Download Center: DownloadDownload Dragd95vcnet.exe now (http://download.microsoft.com/download/visualstudionet/sample/1.3/win98mexp/en-us/Dragd95vcnet.exe) Release Date: June 24, 2002 For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base: Q119591 How to Obtain Microsoft Support Files from Online Services Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on secure servers that prevent any unauthorized changes to the file. NOTE: Use the -d option when running dragd95.exe to decompress the file and recreate the proper directory structure. If you are using Visual C++ 5.0 you may get a message: "This project was generated by a previous version of Developer Studio. Continuing will convert it to the new format. Do you want to convert the project?" Accept this by clicking "Yes." Please Note the Following Problem --------------------------------- Dragd95.exe reports a memory leak when the steps below are taken: 1. Build the debug version of the sample. Then, run the .exe. 2. Drag one item from left pane to right pane. 3. Close the .exe. You should see the memory leak in the output window of VC++. Resolution ---------- The following code needs to be at the bottom of OnHandleDrag() (that is, before the last return statement): delete m_pDragImage; m_pDragImage = NULL; More Information ---------------- Windows 95 Common controls implement their own style of drag and drop. However, this style of drag and drop does not support dragging to other applications. To enable this functionality, it is possible to implement OLE drag and drop using the Common controls. Unfortunately, when OLE drag and drop is implemented, the Common control drag image is lost. It is possible, when implementing OLE drag and drop, to preserve the Common control drag image. However, this image will only be displayed when the pointer is over the application that is the source of the data. This is because the image is not a system-wide resource and belongs to the application that is the source of the data. This behavior is consistent with that of the shell in Windows 95. In Windows 95, you will notice that the drag image is lost over applications other than the Explorer or the Windows shell. The shell and any instances of the Explorer that are running are a single instance of the same application. OLE drag and drop as implemented by this sample is straight forward. When a drag is started, a COleDataSource object is loaded with data and COleDataSource::DoDragDrop() is called. The data source is loaded with a CF_TEXT format and a private clipboard format that has been registered. Applications that understand CF_TEXT, such as Microsoft Word, can be a drop target for the data. You can also implement a COleDropTarget object so that you can be a drop target for your own custom clipboard format. Common controls normally begin a drag operation in response to the LVN_BEGINDRAG message. You can also take advantage of this message to begin the drag operation. This is where the similarity with Common control drag and drop ends. Common control drag and drop uses mouse messages to control tracking the drag image and processing the drop. You will not be able to use mouse messages because, after you begin the drag operation, control is passed to OLE's DoDragDrop() function. To control the tracking and display of the common control drag image, you will implement a COleDropSource object and pass it to the DoDragDrop() function. COleDropSource implements a GiveFeedback() function that is called to give feedback about the effect of a drop at the current mouse position as the mouse is moved over a drop target. Overriding the GiveFeedback() function and obtaining the position of the mouse gives you a chance to control tracking and display of the drag image. REFERENCES ========== Programming with MFC: Encyclopedia - Drag-and-Drop (OLE) Additional query words: Dragd95 Dragd95vcnet ====================================================================== Keywords : kbfile kbole kbSample kbDragDrop kbMFC kbVC400 kbVC410 kbVC420 kbVC500 kbVC600 kbGrpDSMFCATL Technology : kbAudDeveloper kbMFC Version : :4.0,4.1,4.2,5.0,6.0 ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2002.