Bad Cursor and Good Cursor for Drag and Drop
Zhilin Li -- zhilin@infocorp.infolytica.qc.ca Monday, January 29, 1996 Hi Everyone, When implementing drag and drop, I define a set of valid drop sites for a drag source object. I would like to make the drag cursor "good cursor" when dragging over a valid drop site and "bad cursor" otherwise. Does anyone has any hints about how to do this with MFC 4.0? Thank you very much, Zhilin -- ===================================================================== Zhilin Li Infolytica Corporation Software Developper 300 Leo Pariseau #2222 Tel: (514) 849-8752 ext. 252 P.O.Box 1144, Place du Parc Fax: (514) 849-4239 Montreal, QC, Canada, H2W 2P4 e-Mail: zhilin@infolytica.qc.ca =====================================================================
Joseph Koral -- jkoral@ftp.com Monday, January 29, 1996 [Mini-digest: 3 responses] Zhilin Li writes: >> When implementing drag and drop, I define a set of valid drop sites >> for a drag source object. I would like to make the drag cursor >> "good cursor" when dragging over a valid drop site and "bad cursor" >> otherwise. >> >> Does anyone has any hints about how to do this with MFC 4.0? This isn't really MFC specific. Are you using OLE drag and drop? If so, you provide the appropriate DROPEFFECT in your IDropTarget. MFC does wrap this object, refer to the COleDropTarget, OnDragEnter and OnDragOver. Otherwise if you're implementing your own proprietary drag and drop, you need to include the appropriate cursors in your resource file. Load the cursors using LoadCursor, and while the mouse is captured during your drag and drop operation, use SetCursor to display the appropriate one. - Joseph -----From: Richard Morris>When implementing drag and drop, I define a set of valid drop sites >for a drag source object. I would like to make the drag cursor=20 >"good cursor" when dragging over a valid drop site and "bad cursor" >otherwise. > >Does anyone has any hints about how to do this with MFC 4.0?=20 Use the member function COleDropTarget::OnDragOver and return DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_MOVE, DROPEFFECT_LINK. I have included below a small bit from the on-line documentation which discusses OnDragOver. Note that OnDragOver is a virtual function which you replace with in your class subclassed from COleDropTarget. Also, there is more on-line documentation in the VC++ on-line documentation. And, if you are an MSDN subscriber, search under Drag and Drop. There is some example code there. --------------------------------------------------------------- The snippet is copyright (C) Microsoft Corp as it comes from their VC++ on-line documentation. virtual DROPEFFECT COleDropTarget::OnDragOver( CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point ); =20 Return Value The effect that would result if a drop were attempted at the location specified by point. It can be one or more of the following: =B7 DROPEFFECT_NONE A drop would not be allowed. =B7 DROPEFFECT_COPY A copy operation would be performed. =B7 DROPEFFECT_MOVE A move operation would be performed. =B7 DROPEFFECT_LINK A link from the dropped data to the original data= would be established. =B7 DROPEFFECT_SCROLL Indicates that a drag scroll operation is about to occur or is occurring in the target. =20 Parameters pWnd Points to the window that the cursor is over. pDataObject Points to the data object that contains the data to be= dropped. dwKeyState Contains the state of the modifier keys. This is a combination of any number of the following: MK_CONTROL, MK_SHIFT, MK_ALT, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON. point Contains the current location of the cursor in client coordinates. Remarks Called by the framework when the cursor is dragged over the window. This function should be overridden to allow drop operations to occur in the window. The default implementation of this function calls CView::OnDragOver, which returns DROPEFFECT_NONE by default. Because this function is called frequently during a drag-and-drop operation, it should be optimized as much as possible. For more information, see IDropTarget::DragOver in the OLE 2 Programmer=92s Reference, Volume 1. -----From: Ken Freeman 1) Derive a class from COleDropSource and override GiveFeedback. This is where you get to set the cursor using SetCursor. 2) Derive a class from COleServerItem and copy MFC's DoDragDrop. (Unfortunately, DoDragDrop is not virtual.) The call to pDataSource->DoDragDrop should be passed your derived COleDropSource as the third parameter. (MFC 3.2 passes a NULL third parameter.) That should do it. Ken
Jim Kearney -- jim@dataware.com Tuesday, January 30, 1996 Hello, If you are also looking for alternative methods: I found that an easier way to do this is to use the OLE MFC class COleDropTarget. This class has all the functionality you described built into the class already. You have to register your app as a OLE container, register the drop sources and override a few of the member functions but it isn't to bad. This class also takes care of all the cursor shapes as you drag and drop. The shapes are identical to the Win95 explorer drag and drop cursors. I have it working for NT,95 and Win32s 1.3 . I got a example off the microsoft web and here is the title and description. SAMPLE: Using MFC OLE Drag & Drop to Drag Text A sample MFC application that implements MFC OLE drag and drop in a CListBox, CEdit, and a generic CWnd object. (993178 bytes, published 8/21/95) (lstdrg.exe is the zip file for ftp) Steve M. smiller@dataware.com ---------- From: owner-mfc To: mfc-l Subject: Bad Cursor and Good Cursor for Drag and Drop Date: Monday, January 29, 1996 10:36AM Hi Everyone, When implementing drag and drop, I define a set of valid drop sites for a drag source object. I would like to make the drag cursor "good cursor" when dragging over a valid drop site and "bad cursor" otherwise. Does anyone has any hints about how to do this with MFC 4.0? Thank you very much, Zhilin -- ===================================================================== Zhilin Li Infolytica Corporation Software Developper 300 Leo Pariseau #2222 Tel: (514) 849-8752 ext. 252 P.O.Box 1144, Place du Parc Fax: (514) 849-4239 Montreal, QC, Canada, H2W 2P4 e-Mail: zhilin@infolytica.qc.ca =====================================================================
| Вернуться в корень Архива |