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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display system's hand cursor?

Programming

How to display system's hand cursor?

by  imagenetics  Posted    (Edited  )
Few days ago I posted a [link http://www.tek-tips.com/viewthread.cfm?qid=955186&page=1]thread[/link] asking how to display the hand cursor, for example over a TLabel, however the global cursor defined in the Window's Control Panel, not the one available in Builder (crHandPoint). Nobody answered that question. I made some research, mostly in [link http://msdn.microsoft.com/default.aspx]MSDN database[/link] and found a solution.

Hint: As always, [color green] green lines[/color] is what you have to write, the rest is generated by Builder and I include it here for reference where to put the actual code. Comments are [color blue]blue[/color].

Create new project and drop a TLabel on the form (ofcourse you can do this for any control which has a cursor porperty). Then in "Unit1.cpp" write the following:
Code:
...
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
[color green]const TCursor crDefaultCursor = 1;[/color] [color blue]// ID of the cursor[/color]
//-----------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
[color blue]// In form's constructor load the cursor from the system[/color]
Screen->Cursors[crDefaultCursor] = LoadCursor(NULL, IDC_HAND);

[color blue]// and assign it to desired control[/color]
[color green]Label1->Cursor = crDefaultCursor;[/color]
}
//-----------------------------------------------------------------
Compile and run (F9). Move the mose over a label and your Window's cursor will be displayed. You don't have to create any additional resources with custom cursor or use crHandPoint anymore. Every user of the program will have his own cursor which he uses in web browser etc.

Refer to Win32 SDK in Builder's help system or to [link http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/loadcursor.asp]MSDN[/link] for other cursors' IDs.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top