Setting the cursor shape during a dragging session

Hello, I’ve come across an issue regarding the control of the cursor shape during a dragging session on a Windows (Win 10 Pro) plattformusing VSTGUI 4.9. Specifically, what i am doing is to start a drag’n’drop operation with the function call doDrag inside a function call onMouseDown. Further I’ve placed function calls to setCursor inside several callback functions such as dragWillBegin.

I’ve made following observations:

  • The function call setCursor has NO impact during a dragging session. I’ve traced the function calls up to the function bool Win32Frame::setMouseCursor (CCursorType type) in the win32frame.cpp file where a cursor is loaded via the MACRO LoadCursor(…) and passed to the MACRO function SetClassLongPtr (getPlatformWindow (), GCLP_HCURSOR, (__int3264)(LONG_PTR)(cursor));. If I look into the definition of this function in SetClassLongPtrW, what I understand is that a default cursor is assigned to a window class and that the changes does not apply immediately (See Remarks section). However, when I call setCursor outside a dragging session, my window gets an assigned default cursor changing its shape.
  • So, how does the drag’ndrop operation works anyway? To answer this question for myself, I found the following source: DoDragDrop which is in the end called inside the bool Win32DraggingSession::doDrag(…) function in the win32dragging.cpp source file. In the beforementioned link it is described that the function IDropSource::GiveFeedback method is responsible for changing the cursor shape and that OLE default cursors are used if it returns DRAGDROP_S_USEDEFAULTCURSORS which is the case if I look into the wrapper STDMETHODIMP Win32DropSource::GiveFeedback (DWORD effect) in win32dragging.cpp.

What happens in my application is that the cursor shape is changing depending on the return values VSTGUI::DragOperation associated with callbacks such as onDragEnter. But only permitting the windows default cursor shapes as if I am dragging a file/folder and NOT any shape that I want to set with setCursor.

To be able to fully control the cursor shape during a dragging session, I replaced the SetClassLongPtr function inside Win32Frame::setMouseCursor function with a function call SetCursor(cursor) as described in setting the cursor image where the argument cursor is the loaded object by calling LoadCursor. Further, I changed the return value of the function STDMETHODIMP Win32DropSource::GiveFeedback (DWORD effect) from DRAGDROP_S_USEDEFAULTCURSORS to S_OK so that the Windows default cursors are not used.

Following questions pop up in my mind:

  • Is the function call SetClassLongPtr the correct method to change the cursor shape immediately during a dragging session?
  • Is the drag’n’drop operation originally considered for files/folders and not for GUI Objects such as CViewContainer where the windows default cursor shapes reflect this during a dragging session?

Thanks in advance for the answers/suggestions!

it is not supported to change the mouse cursor via CFrame::setCursor while doing a dragging session.

The mouse cursor will be automatically updated depending if the target accepts the drag as a copy (changing the cursor to something with a plus sign) or if the target accepts the drag as a move operation or if the target does not accept the drag.