CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2004
    Location
    Leamington Spa, UK
    Posts
    202

    Drag and Drop Sticks...

    Greetings,

    I have implemented my first Drag and Drop using OLE. I have followed the examples at MSDN and it more or less works. When I click on control and drag it over the window that supports the drop for that item being dragged, I drop it there, and that window responds accordingly. However, after the drop, the mouse cannot be used for a while. It is as if the mouse is still in "drag and drop mode" or something like that. If I keep clicking the mouse button, eventually after a while it goes back to being a normal mouse which I can use to click on buttons etc.

    Has anybody had such a problem before or have an idea as to what is causing it?

    Thanks in advance,

    Aristotel

  2. #2
    Join Date
    Apr 1999
    Posts
    3,585

    Re: Drag and Drop Sticks...

    However, after the drop, the mouse cannot be used for a while.
    What does this mean? Does the application stop responding? Or, is the mouse cursor shape not returning to an arrow? It would help if you posted some code to show what you've done.
    Gort...Klaatu, Barada Nikto!

  3. #3
    Join Date
    Dec 2004
    Location
    Leamington Spa, UK
    Posts
    202

    Re: Drag and Drop Sticks...

    Hi,

    The cursor is the normal one, but if I try to click on some buttons then nothing happens. If I click the button, hold it down and move it a bit, the cursor then changes to the "+" in a square, just as when initially howering over a window area that supports the drop of that format.

    The following code is of three overidden methods of a class derived from COleDropTarget.

    Code:
    DROPEFFECT CMyDrop::OnDragEnter(CWnd* pWnd,  COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
    {
    	//if the data is the kind we want
    	if(pDataObject->IsDataAvailable(CF_PRIVATEFIRST))
    	{
    		return DROPEFFECT_COPY | DROPEFFECT_MOVE;
    	}
    	//we can't handle this type of data
    	return DROPEFFECT_NONE;
    }
    
    DROPEFFECT CMyDrop::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
    {
    	if(pDataObject->IsDataAvailable(CF_PRIVATEFIRST))
    	{
    		return DROPEFFECT_COPY | DROPEFFECT_MOVE;
    	}
    
    	return DROPEFFECT_NONE;
    }
    
    void CLoopDrop::OnDragLeave(CWnd* pWnd)
    {
    	//we can use this method to do any kind of clean up
    	//in this case, we don't have anything
    }
    
    BOOL CMyDrop::OnDrop(	CWnd* pWnd,
    						COleDataObject* pDataObject,
    						DROPEFFECT dropEffect,
    						CPoint point)
    {
    	 BOOL Ret = FALSE;
    
    	if (pDataObject->IsDataAvailable(CF_PRIVATEFIRST))
    	{
    		HGLOBAL hGlobal = pDataObject->GetGlobalData(CF_PRIVATEFIRST);
    
                    //Get the short that was dragged and store it locally for testing
    		short nTheValue = 0;
    		memcpy(&nTheValue, GlobalLock(hGlobal), sizeof(short));
    		GlobalUnlock(hGlobal);
    
    		Ret = TRUE;
    	}
    
    	return Ret;
    }
    the following code is how I start the drag

    Code:
    COleDataSource dataSource;
    
    HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE,sizeof(short));
    short* pShort = (short*)GlobalLock(hData);
    *pShort = 69;
    GlobalUnlock(hData);
    	
    if(hData)
    {
    	//attach the data to the COleDataSource Object
    	dataSource.CacheGlobalData(CF_PRIVATEFIRST, hData);
    
    	//allow the user to drag it
    	DROPEFFECT DropEffect = dataSource.DoDragDrop();
    }
    Thanks again

  4. #4
    Join Date
    Apr 1999
    Posts
    3,585

    Re: Drag and Drop Sticks...

    What type of object starts the drag and drop operation? Is is a control or a window? Do you start it in the OnLButtonDown() handler?
    Gort...Klaatu, Barada Nikto!

  5. #5
    Join Date
    Dec 2004
    Location
    Leamington Spa, UK
    Posts
    202

    Re: Drag and Drop Sticks...

    It is a dialog that contains an object derived from CButton. On OnLButtonDown the custom button fires a message which is captured by the parent dialog. The parent dialog then calls a member function which contains the code you saw above.

  6. #6
    Join Date
    Apr 1999
    Posts
    3,585

    Re: Drag and Drop Sticks...

    Are you executing the base class call for OnLButtonDown(). Your problem symptoms imply that you're not completing some code.
    Gort...Klaatu, Barada Nikto!

  7. #7
    Join Date
    Dec 2004
    Location
    Leamington Spa, UK
    Posts
    202

    Re: Drag and Drop Sticks...

    Yes I call
    Code:
    CButton::OnLButtonDown(nFlags, point);
    in the function that handles the OnLButtonDown message, before sendning a custom message to the parent. It does seem like some code somewhere is incomplete but I cannot see it being in the custom button. It is probably, in the Drag and Drop code, even though it seems right too.

    I will think a bit more about it .. will let you know on any new information.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured