I am facing a problem while creating and setting coloured cursor. Our requirement is to create a coloured cursor from a bmp made from a text(using DrawText to dc). We need to set the background of text as transparent so that only the text appears as the cursor.
In some of our machines , this is working successfully but in some other machines at site , there is a problem.. Each letter of the text in cursor apears twice( just as a thich shadow for each letter). Can anyone point out the reason for this..If it is related to system settings, pls point out, what is actually causing this problem.
As the problem is very critical, it would be highly apprciable if anyone can give me some clues on the matter
COLORREF ColorRefObj= SetTextColor(
hMemDC, // handle to DC
RGB(255,128,64) // text color
);
COLORREF BkColorRefObj = ::SetBkColor(hMemDC,RGB(255,255,255));
{
// Local identifier
HCURSOR hNewCursor = NULL;
//Getting the mask bitmap to make transparent cursor
HBITMAP hMaskBitmap = CreateMaskBitmap(hBitmap,RGB(255,255,255),
size);
// The iconinfo.fIcon must be FALSE
ICONINFO iconinfo = {0};
// Set color and mask bitmaps
iconinfo.hbmMask = hMaskBitmap;
iconinfo.hbmColor = hBitmap;
// Create the cursor
hNewCursor = CreateIconIndirect(&iconinfo);
// Set the background colour of the colour image to the colour
// you want to be transparent.
SetBkColor(hdcColor, crTransparent_i);
// Copy the bits from the colour image to the B+W mask... everything
// with the background colour ends up white while everythig else ends up
// black...Just what we wanted.
// Take our new mask and use it to turn the transparent colour in our
// original colour image to black so the transparency effect will
// work right.
//BitBlt(hdcColor, 0, 0, bm.bmWidth, bm.bmHeight, hdcMask, 0, 0, SRCINVERT);
BitBlt(hdcColor, 0, 0, sizeObj.cx, sizeObj.cy, hdcMask, 0, 0, SRCINVERT);
Ive got your code running in a small test dialog app.
I get a problem where when I move the cursor around quickly, I get periodic flashes of what appears to be the mask bitmap.
It always appears to the upper right of the cursor regardless of the direction I move the cursor. When the cursor is at rest it appears as it should.
Is this the behaviour that you observed.
If so then its not the alpha blended shadow. On further reading, appears that you need to create an alpha channel in your cursor resource, its not automatically added by the OS when you show the cursor.
Last edited by Dave McLelland; October 2nd, 2003 at 08:34 PM.
Try calling SetClassLong to set the class cursor to NULL.
Windows sets the cursor to the class cursor every time it moves unless the class cursor is NULL. All the problems I observed went away when you do this.
Insert this into your OnInitDialog or somewhere convenient in the window to show the cursor. It only needs to execute once.
Code:
SetClassLong(m_hWnd,GCL_HCURSOR,NULL);
My OnMouseMove is shown below (Note I dont bother to destroy the previous cursor, but you will need to).
Dave, We had already tried disabling that option "enable shadow pointer" but with no effect. The cursor is created only once.
Though in the code I posted, I had used setClassLong, actually in my project I am using setSystemCursor in onMouseMove to switch between already created cursors(switching depends on the mouse point obtained in mouse move..Within a region a particular cursor is shown)....
Then you said abt adding alpha channel to the cursor resource. How is it done?
Again the shadow problem we are observing is there even when the cursor is at rest.
Bookmarks