Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom Cursor that shows text

2 views
Skip to first unread message

Preston

unread,
Jan 23, 2006, 11:47:51 AM1/23/06
to
I want a custom cursor that is capable of showing text. I know I can
create a custom cursor using an image an a resource file, but now I want
to generate the cursor at runtime.

Preston

Brad Prendergast

unread,
Jan 23, 2006, 12:10:22 PM1/23/06
to
Preston <n...@na.com> wrote in message
<43d50807$1...@newsgroups.borland.com>:

Hrm, I didn't get to test this but this should get you started:

var
theicon: TICON;
iconwidth, iconheight : integer;
bmpColor: TBitmap;
r: TRect;
iconinfo: TIconInfo;
begin
bmpColor:= TBitmap.Create;
theicon:= TIcon.Create;
try
iconwidth:= GetSystemMetrics(SM_CXCURSOR);
iconheight:= GetSystemMetrics(SM_CYCURSOR);
r.Top:= 0;
r.Left:= 0;
r.Bottom:= iconheight;
r.Right:= iconwidth;

bmpColor.Height:= iconheight;
bmpColor.Width:= iconwidth;
bmpColor.Canvas.Brush.Color:= clWhite;
bmpColor.Canvas.FillRect(r);
bmpColor.Canvas.Font.Size:= 8;
bmpColor.Canvas.Font.Color:= clBlue;
bmpColor.Canvas.TextOut(6,12,text);
bmpColor.TransparentColor:= clWhite;

iconinfo.fIcon:= True;
iconinfo.xHotspot:= 6;
iconinfo.yHotspot:= 12;
iconinfo.hbmMask:= bmpColor.MaskHandle;
iconinfo.hbmColor:= bmpColor.Handle;
theicon.Handle:= CreateIconIndirect(iconinfo);

finally
bmpColor.Free;
theicon.Free;
end;
end;


A TIcon is a Cursor. In the above example theicon can be set to the
cursor.

--
Brad Prendergast

"The only difference between me and a madman is that I'm not mad." --
Salvador Dali (1904 - 1989)

Preston

unread,
Jan 23, 2006, 1:24:39 PM1/23/06
to
Appreciate the response. I'll try it out and repost if there are any
changes.

Brad Prendergast

unread,
Jan 23, 2006, 12:58:51 PM1/23/06
to
Preston <n...@na.com> wrote in message
<43d51eb7$1...@newsgroups.borland.com>:

> Appreciate the response. I'll try it out and repost if there are any
> changes.

Actually this will do it for you: I'd actually return the cursor rather
than setting it.

procedure TForm2.SetCursorText(text: string);


var
theicon: TICON;
iconwidth, iconheight : integer;
bmpColor: TBitmap;
r: TRect;
iconinfo: TIconInfo;
begin
bmpColor:= TBitmap.Create;
theicon:= TIcon.Create;
try
iconwidth:= GetSystemMetrics(SM_CXCURSOR);
iconheight:= GetSystemMetrics(SM_CYCURSOR);
r.Top:= 0;
r.Left:= 0;
r.Bottom:= iconheight;
r.Right:= iconwidth;

bmpColor.Height:= iconheight;
bmpColor.Width:= iconwidth;

bmpColor.Canvas.Brush.Color:= clBlack;


bmpColor.Canvas.FillRect(r);
bmpColor.Canvas.Font.Size:= 8;
bmpColor.Canvas.Font.Color:= clBlue;
bmpColor.Canvas.TextOut(6,12,text);

bmpColor.TransparentColor:= clBlack;

iconinfo.fIcon:= False;


iconinfo.xHotspot:= 6;
iconinfo.yHotspot:= 12;
iconinfo.hbmMask:= bmpColor.MaskHandle;
iconinfo.hbmColor:= bmpColor.Handle;
theicon.Handle:= CreateIconIndirect(iconinfo);

Screen.Cursors[5]:= theicon.Handle;
Screen.Cursor:= 5;

DeleteObject(iconinfo.hbmColor);


finally
bmpColor.Free;
theicon.Free;
end;
end;

--

Preston

unread,
Jan 23, 2006, 2:48:44 PM1/23/06
to
Thanks!

That works great. Now maybe you know how to change the size of the
cursor? By default it's rather small and doesn't allow for much text.

Brad Prendergast

unread,
Jan 23, 2006, 2:05:20 PM1/23/06
to
Preston <n...@na.com> wrote in message
<43d5326b$1...@newsgroups.borland.com>:

> Thanks!
>
> That works great. Now maybe you know how to change the size of the
> cursor? By default it's rather small and doesn't allow for much text.

in the code that I had provided, set the variables:

iconwidth:= 500;
iconheight:= 45;


for example.

Preston

unread,
Jan 23, 2006, 3:17:34 PM1/23/06
to
I apologize, I got hung up on the help file entry GetSystemMetrics

GetSystemMetrics, SM_CYCURSOR -Width and height, in pixels, of a cursor.
These are the cursor dimensions supported by the current display driver.
The system cannot create cursors of other sizes.

After reading "cannot create cursors of other sizes", I didn't even try
to adjust the width.

Works great!!

Brad Prendergast

unread,
Jan 23, 2006, 2:31:25 PM1/23/06
to
Preston <n...@na.com> wrote in message
<43d5392e$1...@newsgroups.borland.com>:

just be sure to test across display drivers/adapters....

0 new messages