using a bitmap as a custom cursor

Started by
15 comments, last by Moe 23 years, 9 months ago
Intead of using a regular black and white cursor that I could compile, I decided to use a bitmap instead. What I am trying to do is get the mouse position every frame and blit the bitmap at the cursors position (via Direct Draw blt function). Something is funny. I just can''t get it to work. Here is the code (which is in the main message loop) to get the cursor''s position: case WM_MOUSEMOVE: { //do that neat cursor thingy here //extract mouse position int mouse_x = (int)LOWORD(lparam); int mouse_y = (int)HIWORD(lparam); RECT cursor; DDBLTFX ddbltfx; //set it so that the bitmap is displayed where the cursor should be cursor.top = mouse_y; cursor.left = mouse_x; cursor.bottom = mouse_y + 32; cursor.right = mouse_x + 32; lpddsprimary->Blt(&cursor, lpcursor, NULL, DDBLT_WAIT, &ddbltfx); } break; I can''t figure out what is wrong with it for the life of me. Anyone here have any ideas? Shrapnel Games
Advertisement
Not quite sure why you''re passing a DDBLTFX structure to blt
when you aren''t setting any of the parameters in it....how about
passing NULL where you pass the DDBLTFX structure to blt that
might help a little bit.

lpddsprimary->Blt(&cursor, lpcursor, NULL, DDBLT_WAIT, NULL);

~S''Greth
"The difference between insanity and genius is measured only by success."~Bruce Feirstein
Nope, It didn''t fix it . I am still not getting anything on the screen. Any other ideas?

Shrapnel Games
Maybe you are flipping the primary surface after you draw the bitmap, so the bitmap is never visible...

VBMaster
I see that you have not specified any source rect. But that is probably not the problem. Then the mouse coordinate is relative to the upper-left corner of the client area. You must change this if you are working in window mode.

//set it so that the bitmap is displayed where the cursor should be
cursor.top = g_rcMainWin.top + mouse_y;
cursor.left = g_rcMainWin.left + mouse_x;
cursor.bottom = cursor.top + 32;
cursor.right = cursor.left + 32;

Zeblar Nagrim, Lord of Chaos
Your code looks fine. This is just a shot in the dark here. I think your problem may be one of different bit depths. Check the bit depth of your bitmap. Is it the same as your application''s current bit depth?

hope that helped,
skitzo_smurf
"Innocent is just a nice way to say ignorant, and stupidity is ignorance with its clothes off."words of,skitzo_smurf
bit depth shouldnt matter as all surfaces will be the same bitdepth, it maybe you dont have the bitmap loaded correctly in lpcursor

Im Always Bored
--Bordem
ICQ: 76947930
Im Always Bored--Bordem ICQ: 76947930
sorry,
maybe that wasnt clear enough. I meant that he could be trying to load a 32 bit bitmap onto an 8 bit surface. In other words, I meant to check that the bitmap''s bit depth is the same as his surfaces'' bit depths. That could definitely cause a problem.

skitzo_smurf

"Innocent is just a nice way to say ignorant, and stupidity is ignorance with its clothes off."words of,skitzo_smurf
case WM_MOUSEMOVE:
{
// Store windowrect in global rect
// Do this in your WM_MOVE message,
// not here.
RECT g_rcMainWin;
GetWindowRect(hWnd, &rcClientRect);
CopyRect(&g_rcMainWin, &rcClientRect);

// Hide cursor if inside client rect
int hide;
while(1)
{
hide = ShowCursor(FALSE);
if(hide < 0)
break;
}

//do that neat cursor thingy here
//extract mouse position
int mouse_x = (int)LOWORD(lParam);
int mouse_y = (int)HIWORD(lParam);

// Show cursor on menu
if(mouse_y < 20)
{
while(1)
{
hide = ShowCursor(TRUE);
if(hide > 0)
break;
}
break;
}

RECT cursor;

//set it so that the bitmap is displayed where the cursor should be
cursor.top = g_rcMainWin.top + mouse_y;
cursor.left = g_rcMainWin.left + mouse_x;
cursor.bottom = cursor.top + 32;
cursor.right = cursor.left + 32;

static RECT srect = {0,0,32,32};
lpddsprimary->Blt(&cursor, lpcursor, &srect, 0, &ddbltfx);

}
break;

Zeblar Nagrim, Lord of Chaos

Edited by - Zeblar Nagrim on July 20, 2000 5:59:33 AM
well whatever the reason its not showing up since your blting to the primary expect some flicker and tearing of the cursor

Im Always Bored
--Bordem
ICQ: 76947930
Im Always Bored--Bordem ICQ: 76947930

This topic is closed to new replies.

Advertisement