Cursor from Bitmap Conundrum
-
Hello. I have a cursor conundrum. I am developing a custom control and one feature I want this custom control to have is the ability to be able to rearrange its appearance by dragging and dropping one part of it to another. The way I decided I would do this would be to: 1) Convert the selected area into a bitmap 2) Use the bitmap from 1) as the cursor until the drop point is selected. 3) Redraw the control in the new arrangement. I am not worried about step 3). That should be trivial - it won't involve anything I haven't achieved already in my code concerning bitmaps or device contexts. However, I have a conundrum concerning step 2). I have achieved what I want to achieve but only if I save the bitmap to a file first then reload it as a cursor! What I am looking for here is a way of obtaining the bitmap data and converting it directly into a cursor. Clearly my problem stems from having cobbled together samples of code from various sources without properly understanding what is going on - So I call the image capuring function on clicking the mouse...
void CScrollBarEx::OnLButtonDown(UINT inFlags, CPoint inPoint) {
...
CaptureAnImage(sliderVector[m_currentSlider-1].sliderRect);
...
}and then you can see where I have edited out the code where I try and use the HBITMAP used to subsequently make a .bmp file to make the cursor - doing this always produces a black rectangle as the cursor. However- when I save that HBITMAP to .bmp file, then reload it into memory and use that to make a cursor - it works perfectly!
int CScrollBarEx::CaptureAnImage(RECT sliderRect)
{
//HDC hdcScreen;
HDC hdcWindow;
HDC hdcMemDC = NULL;
HBITMAP hbmScreen = NULL;
BITMAP bmpScreen;HBITMAP m\_hAndMask; HBITMAP m\_hXorMask; // Retrieve the handle to a display device context for the client // area of the window. //hdcScreen = (GetDC())->GetSafeHdc(); hdcWindow = (GetDC())->GetSafeHdc(); // Create a compatible DC which is used in a BitBlt from the window DC hdcMemDC = CreateCompatibleDC(hdcWindow); if(!hdcMemDC) { // MessageBox(hWnd, L"CreateCompatibleDC has failed",L"Failed", MB\_OK); goto done; } // Get the client area for size calculation RECT rcClient; GetClientRect(&rcClient); /\* //This is the best stretch mode SetStretchBltMode(hdcWindow,HALFTONE); //The source DC is the entire screen and the destination DC is the current window (