GetIconInfo will give you the mask and color information of the
cursor. In your case, you want the standard arrow cursor (unless you
actually want to use your own arrow cursor). Combine this information
with your bitmap (create new mask and color bitmaps). Then pass the
new bitmaps to CreateIconIndirect. Be careful to delete all of the
bitmaps generated during this process (both the GetIconInfo and
CreateIconIndirect bitmaps).
If you need help creating the bitmaps, post more information about how
you want to combine the cursor and the bitmap.
Chris Hill
Chri...@aol.com
Here is a function that combines a cursor and a bitmap and returns a
handle to the combined cursor. First, the bitmap is drawn (it is
assumed that the bitmap covers the entire cursor, so there is no
transparency). Next, the cursor is drawn transparently on top of the
bitmap.
Use this function at your own risk. I haven't tested it much.
HCURSOR CombineImageAndCursor(HCURSOR cur, Graphics::TBitmap *bmp)
{
HCURSOR result;
ICONINFO src, dest;
HBITMAP dest_mask;
int cursor_width, cursor_height;
char *mask_data;
int mask_data_size;
BOOL suc = GetIconInfo(cur, &src);
if(!suc)
return 0;
cursor_width = GetSystemMetrics(SM_CXCURSOR);
cursor_height = GetSystemMetrics(SM_CYCURSOR);
// Create a fully opaque cursor
mask_data_size = (cursor_width/8)*cursor_height;
mask_data = new char[mask_data_size];
ZeroMemory(mask_data, mask_data_size);
dest_mask = CreateBitmap(cursor_width,
cursor_height,
1,
1,
mask_data);
delete[] mask_data;
// Draw the bitmap onto the cursor
using Graphics::TBitmap;
TBitmap* color_data = new TBitmap;
color_data->Width = cursor_width;
color_data->Height = cursor_height;
color_data->Canvas->Draw(0,0,bmp);
// Draw the source cursor on the destination cursor
HDC mem_dc = CreateCompatibleDC(color_data->Canvas->Handle);
HBITMAP old_bitmap;
if(src.hbmColor == 0) // mono source cursor
{
old_bitmap = SelectObject(mem_dc, src.hbmMask);
BitBlt(color_data->Canvas->Handle,0,0,cursor_width,cursor_height,
mem_dc,0,0,SRCAND);
BitBlt(color_data->Canvas->Handle,0,0,cursor_width,cursor_height,
mem_dc,0,cursor_height,SRCINVERT);
}
else // color source cursor
{
old_bitmap = SelectObject(mem_dc, src.hbmMask);
BitBlt(color_data->Canvas->Handle,0,0,cursor_width,cursor_height,
mem_dc,0,0,SRCAND);
SelectObject(mem_dc, src.hbmColor);
BitBlt(color_data->Canvas->Handle,0,0,cursor_width,cursor_height,
mem_dc,0,0,SRCINVERT);
}
SelectObject(mem_dc, old_bitmap);
DeleteDC(mem_dc);
DeleteObject(src.hbmMask);
DeleteObject(src.hbmColor);
dest.fIcon = FALSE;
dest.xHotspot = src.xHotspot;
dest.yHotspot = src.yHotspot;
dest.hbmMask = dest_mask;
dest.hbmColor = color_data->Handle;
result = CreateIconIndirect(&dest);
delete color_data;
DeleteObject(dest_mask);
return result;
}
An example of the use:
const int crMine = 10;
Screen->Cursors[crMine] =
CombineImageAndCursor(Screen->Cursors[crArrow], MyBitmap);
Screen->Cursor = crMine;
On Mon, 12 Apr 1999 14:36:27 -0400, Bill Engst
<Bill....@Celwave.com> wrote:
Chris Hill
Chri...@aol.com
>Where can I find an example on how to use these functions. I looked Win API
>help. There are no examples, only definitions?
>Thanks.
See my reply to your last message. I wrote an example function that
combines a bitmap and a cursor. The Win32 help file provides examples
after the overview topics. I'm not sure about these particular
functions. Most of the time I find that example code always does the
most straightforward and least interesting things. I'm familiar
enough with Win32 programming to work with the reference topics.
Chris Hill
Chri...@aol.com