<p>I'm trying to implement some drag and drop functionality for a material system being developed at my work. Part of this system includes a 'Material Library' which acts as a repository, divided into groups, of saved materials on the user's hard drive.</p>

<p>As part of some UI polish, I was hoping to implement a 'highlight' type feature. When dragging and dropping, windows that you can legally drop a material onto will very subtly change color to improve feedback to the user that this is a valid action.</p>

<p>I am changing the bar with 'Basic Materials' (Just a CWnd with a CStatic) from having a medium gray background when unhighlighed to a blue background when hovered over. It all works well, the OnDragEnter and OnDragExit messages seem robust and set a flag indicating the highlight status. Then in OnCtrlColor I do this:</p>

<pre><code>    if (!m_bHighlighted) {
    pDC-&gt;FillSolidRect(0, 0, m_SizeX, kGroupHeaderHeight, kBackgroundColour);
}
else {
    pDC-&gt;FillSolidRect(0, 0, m_SizeX, kGroupHeaderHeight, kHighlightedBackgroundColour);
}
</code></pre>

<p>However, as you can see in the screenshot, the painting 'glitches' below the dragged object, leaving the original gray in place. It looks really ugly and basically spoils the whole effect.</p>

<p>Is there any way I can get around this?</p>

[{'answer_id': 74501, 'author': 'Andy', 'author_id': 3857, 'author_profile': 'https://Stackoverflow.com/users/3857', 'pm_score': 0, 'selected': False, 'text': "<p>It almost looks like the CStatic doesn't know that it needs to repaint itself, so the background color of the draggable object is left behind. Maybe try to invalidate the CStatic, and see if that helps at all?</p>\n"}, {'answer_id': 77701, 'author': 'Aidan Ryan', 'author_id': 1042, 'author_profile': 'https://Stackoverflow.com/users/1042', 'pm_score': 1, 'selected': False, 'text': '<p>Remote debugging is a godsend for debugging visual issues. It\'s a pain to set up, but having a VM ready for remote debugging will pay off for sure.</p>\n\n<p>What I like to do is set a ton of breakpoints in my paint handling, as well as in the framework paint code itself. This allows you to effectively "freeze frame" the painting without borking it up by flipping into devenv. This way you can get the true picture of who\'s painting in what order, and where you\'ve got the chance to break in a fill that rect the way you need to.</p>\n'}, {'answer_id': 81662, 'author': 'Ali Parr', 'author_id': 1169, 'author_profile': 'https://Stackoverflow.com/users/1169', 'pm_score': 1, 'selected': True, 'text': '<p>Thanks for the answers guys, ajryan, you seem to always come up with help for my questions so extra thanks.</p>\n\n<p>Thankfully this time the answer was fairly straightforward....</p>\n\n<pre><code>ImageList_DragShowNolock(FALSE);\nm_pDragDropTargetWnd-&gt;SendMessage(WM_USER_DRAG_DROP_OBJECT_DRAG_ENTER, (WPARAM)pDragDropObject, (LPARAM)(&amp;dragDropPoint));\nImageList_DragShowNolock(TRUE);\n</code></pre>\n\n<p>This turns off the drawing of the dragged image, then sends a message to the window being entered to repaint in a highlighted state, then finally redraws the drag image over the top. Seems to have done the trick.</p>\n'}]
['https://Stackoverflow.com/questions/74350', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1169/']