Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using a custom cursor.

Status
Not open for further replies.

LyMc

Programmer
Jun 3, 2003
84
US
I created a cursor as a bitmap in the VC bitmap editor. It's 16x16, monochrome bitmap, and I used this code to try to get it displayed:

Code:
static HCURSOR	hcZoom;
...
	long flags = LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_SHARED | LR_MONOCHROME;
	hcZoom = (HCURSOR) LoadImage (hInstance, MAKEINTRESOURCE (IDB_BITMAP), IMAGE_CURSOR, 0, 0, flags);
...
	SetCursor (hcZoom);
After the SetCursor, the cursor has not changed.

As an aside, cursors have a hot spot in their image, which can be set if you create a cursor on the fly using CreateCursor, but if you load it from a resource I don't see anywhere that can be established. Does anyone know how that is done?
 
I believe you should use LoadCursor instead of LoadImage.

Ion Filipski
1c.bmp
 
Thanks for the fast response, Ion. According to the Platform SDK and MSVC .NET help, LoadImage has replaced LoadCursor as the preferred method of loading a cursor specifically. LoadCursor is deprecated.
 
In this case see if you have set the cursor for the right window.

Ion Filipski
1c.bmp
 
Well, that sounded good. I have a main window which contains a tabbed control, and on top of that there is another class window which is where the cursor needs to change. It is supposed to change when one of the tabs is clicked, and that was done right in the tab click handler (in the main window).

I moved the SetCursor into the WM_PAINT handler for the topmost drawing window. The cursor still does not change.

Is there something in your response I'm not seeing? The only sort of-reference to a window is the instance parameter in the LoadImage (or LoadCursor) call, which I do set to the main program instance. Other than that there is no window reference to hang onto.

BTW, I also tried LoadCursor; it makes no difference.
 
try something like this:
yourWindow->SetCursor (hcZoom);


Ion Filipski
1c.bmp
 
Dont know about .NET stuff but in old VC6 i usually just override the CWnd::OnSetCursor and set the cursor there to whatever is appropriate for the context.

The default behavior of OnSetCursor is to set the arrow thingie. OnSetCursor is called if mouse input is not captured and the mouse causes cursor movement in the window.

Could that explain why your cursor doesnt change? As mentioned - I dont know if this is applicable in .net

See
/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
I'm not using MFC (or .NET), this is all pure SDK (sorry, should have mentioned that above).

I did find one problem - the LoadImage was failing because I used the IMAGE_CURSOR argument value rather than the correct IMAGE_BITMAP (darn the slippery, weasely wording of the descriptions - it wasn't clear whether I was specifying what I had or what I wanted). Fixed, it now returns what appears to be a handle (it's nonzero, at least). However, it didn't change the outcome.

I would expect that if the MFC SetCursor was a method of a window, then the SDk equivalent would have a window handle argument, but that doesn't seem to be the case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top