Problem with cursor display

tyonuts

Well-known member
Joined
Dec 27, 2005
Messages
78
Location
Romania
Programming Experience
3-5
Ok, now that all my other problems are over, I have one last question.

I created a nice looking cursor in Aha-Soft's ArtCursor application, with Alpha_blends and shadows and everything. I tried to set it (first in Design mode, then programmatically) as a form's cursor, but VB doesn't display it in all it's 32 bits. What I get is a black and white cursor (4 bits), and all the glows and shadows are screwed up. Is this a problem specific to .Net 1.1?
If not, what could I possibly do?

Any help on this will be rewarded with a
 
This is a very complex thing to do believe it or not, plus the fact that 32 bit cursors are only supported in win xp. The following function is in c++ and should return a cursor that can support alpha blending etc...

The following procedure should be used to create an alpha blended cursor or
icon:

1) Define a 32 BPP alpha blended DIB by filling out a BITMAPV5HEADER
structure as in the example code below.

2) Create a DIB section based off of that BITMAPV5HEADER by calling
CreateDIBSection.

3) Fill the DIB section with the bitmap information and alpha information
desired for your alpha blended cursor or icon.

4) Fill out an ICONINFO structure. Place an empty monochrome bitmap in the
hbmMask field and place the alpha blended DIB section in the hbmColor
field.

5) Finally, call CreateIconIndirect to create the cursor or icon.

The following C++ code demonstrates how to create an alpha blended cursor.
The same code can be used to create an alpha blended icon by changing the
fIcon member of the ICONINFO structure to TRUE:

VB.NET:
HCURSOR CreateAlphaCursor(void)
{
HDC hMemDC;
DWORD dwWidth, dwHeight;
BITMAPV5HEADER bi;
HBITMAP hBitmap, hOldBitmap;
void *lpBits;
DWORD x,y;
HCURSOR hAlphaCursor = NULL;
 
dwWidth = 32; // width of cursor
dwHeight = 32; // height of cursor
 
ZeroMemory(&bi,sizeof(BITMAPV5HEADER));
bi.bV5Size = sizeof(BITMAPV5HEADER);
bi.bV5Width = dwWidth;
bi.bV5Height = dwHeight;
bi.bV5Planes = 1;
bi.bV5BitCount = 32;
bi.bV5Compression = BI_BITFIELDS;
// The following mask specification specifies a supported 32 BPP
// alpha format for Windows XP.
bi.bV5RedMask = 0x00FF0000;
bi.bV5GreenMask = 0x0000FF00;
bi.bV5BlueMask = 0x000000FF;
bi.bV5AlphaMask = 0xFF000000;
 
HDC hdc;
hdc = GetDC(NULL);
 
// Create the DIB section with an alpha channel.
hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS,
(void **)&lpBits, NULL, (DWORD)0);
 
hMemDC = CreateCompatibleDC(hdc);
ReleaseDC(NULL,hdc);
 
// Draw something on the DIB section
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
PatBlt(hMemDC,0,0,dwWidth,dwHeight,WHITENESS);
SetTextColor(hMemDC,RGB(0,0,0));
SetBkMode(hMemDC,TRANSPARENT);
TextOut(hMemDC,0,9,"rgba",4);
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);
 
// Create an empty mask bitmap
HBITMAP hMonoBitmap = CreateBitmap(dwWidth,dwHeight,1,1,NULL);
 
// Set the alpha values for each pixel in the cursor so that
// the complete cursor is semi-transparent.
DWORD *lpdwPixel;
lpdwPixel = (DWORD *)lpBits;
for (x=0;x<dwWidth;x++)
for (y=0;y<dwHeight;y++)
{
// Clear the alpha bits
*lpdwPixel &= 0x00FFFFFF;
// Set the alpha bits to 0x9F (semi-transparent)
*lpdwPixel |= 0x9F000000;
lpdwPixel++;
}
 
ICONINFO ii;
ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
ii.xHotspot = 0;
ii.yHotspot = 0;
ii.hbmMask = hMonoBitmap;
ii.hbmColor = hBitmap;
 
// Create the alpha cursor with the alpha DIB section
hAlphaCursor = CreateIconIndirect(&ii);
 
DeleteObject(hBitmap);
DeleteObject(hMonoBitmap);
 
return hAlphaCursor;
}
Hope this helps.

p.s You may be able to use reflector to get the vb.net version.
 
Back
Top