Justin Bozalina
2007-03-28 14:30:04 UTC
I'm running VS 2005. The application I develop for uses a "shaping tool"
cursor at some points, replacing the cursor with a transparent bitmap. It
does this by creating a bitmap, testing the colors of the bitmap to set the
alpha values, then using CreateIconIndirect to create an HCURSOR, as seen
below.
This normally works correctly. However, we've observed that when both third
party and our own add-ons to the software create an OpenGL context for
on-screen and off-screen rendering, the cursor does not display as expected.
Instead of displaying the entire cursor bitmap, it won't display anything
larger than 61 pixels, in the x or y dimensions. Once the OpenGL context is
destroyed, it goes back to working as it should.
Also peculiar, when running OpenGL, the entire cursor bitmap WILL display
correctly if the transparency of the bitmap is not altered (the double for
loop is commented out). This occurs on every computer we run this on, ATI
and NVIDIA cards, otherwise I would think it was an OpenGL issue. Any ideas?
lpdwPixel is a pointer to the DIB bit values, as returned from
CreateDIBSection. ptSizeDP is the size of the bitmap, in device coordinates.
// Set the alpha values for each pixel in the cursor so that the cursor is
semi-transparent.
DWORD* lpdwPixel;
lpdwPixel = (DWORD*)lpBits;
DWORD dwBlack = 0x00000000;
DWORD dwWhite = 0x00FFFFFF;
for( int x = 0; x < ptSizeDP.x; x++ )
for( int y = 0; y < ptSizeDP.y; y++ )
{
// Clear the alpha bits (this will make all bits transparent).
*lpdwPixel &= 0x00FFFFFF;
//If pixel is black, set the alpha bit to opaque.
if( *lpdwPixel == dwBlack )
*lpdwPixel |= 0xFF000000;
//If pixel is white, set the alpha bits to 0x4F (semi-transparent)
else if( *lpdwPixel == dwWhite )
*lpdwPixel |= 0x4F000000;
lpdwPixel++;
}
//Create the icon info structure.
ICONINFO ii;
ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
ii.xHotspot = ptSizeDP.x / 2;
ii.yHotspot = ptSizeDP.y / 2;
ii.hbmMask = hMonoBitmap;
ii.hbmColor = hBitmap;
// Create the alpha cursor with the alpha DIB section.
hAlphaCursor = CreateIconIndirect( &ii );
SetCursor( hAlphaCursor );
cursor at some points, replacing the cursor with a transparent bitmap. It
does this by creating a bitmap, testing the colors of the bitmap to set the
alpha values, then using CreateIconIndirect to create an HCURSOR, as seen
below.
This normally works correctly. However, we've observed that when both third
party and our own add-ons to the software create an OpenGL context for
on-screen and off-screen rendering, the cursor does not display as expected.
Instead of displaying the entire cursor bitmap, it won't display anything
larger than 61 pixels, in the x or y dimensions. Once the OpenGL context is
destroyed, it goes back to working as it should.
Also peculiar, when running OpenGL, the entire cursor bitmap WILL display
correctly if the transparency of the bitmap is not altered (the double for
loop is commented out). This occurs on every computer we run this on, ATI
and NVIDIA cards, otherwise I would think it was an OpenGL issue. Any ideas?
lpdwPixel is a pointer to the DIB bit values, as returned from
CreateDIBSection. ptSizeDP is the size of the bitmap, in device coordinates.
// Set the alpha values for each pixel in the cursor so that the cursor is
semi-transparent.
DWORD* lpdwPixel;
lpdwPixel = (DWORD*)lpBits;
DWORD dwBlack = 0x00000000;
DWORD dwWhite = 0x00FFFFFF;
for( int x = 0; x < ptSizeDP.x; x++ )
for( int y = 0; y < ptSizeDP.y; y++ )
{
// Clear the alpha bits (this will make all bits transparent).
*lpdwPixel &= 0x00FFFFFF;
//If pixel is black, set the alpha bit to opaque.
if( *lpdwPixel == dwBlack )
*lpdwPixel |= 0xFF000000;
//If pixel is white, set the alpha bits to 0x4F (semi-transparent)
else if( *lpdwPixel == dwWhite )
*lpdwPixel |= 0x4F000000;
lpdwPixel++;
}
//Create the icon info structure.
ICONINFO ii;
ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
ii.xHotspot = ptSizeDP.x / 2;
ii.yHotspot = ptSizeDP.y / 2;
ii.hbmMask = hMonoBitmap;
ii.hbmColor = hBitmap;
// Create the alpha cursor with the alpha DIB section.
hAlphaCursor = CreateIconIndirect( &ii );
SetCursor( hAlphaCursor );