Board index » cppbuilder » Adding custom cursors to Screen->Cursors

Adding custom cursors to Screen->Cursors

Hi! I have created a component that uses custom cursors. To be able to do a
MyComponent->Cursor = crMyCursor, I need to add these cursors to the global
cursor list (Screen->Cursors). How can I do this without overriding an
existing, user defined cursor? IOW how to I determine whether or not an
index is already used?

Thanks!
Jens

 

Re:Adding custom cursors to Screen->Cursors


The cursors are stored in an internal linked list which you do not have
direct access to, thus the only way to determine whether your cursor already
exists in the list is to actually query for it and see if it returns
crDefault or your actual custom value.

Of course, this requires a runtime check, which means that to ensure your
value is truely unique, you can't really hard-code your cursor value in your
code but instead should generate it randomly at runtime.  Which means you
can't use it at design-time, though.

If you must use it at design-time, then that means that you have to pick a
custom value that is very unlikely to be used by anyone else.  You have
millions of values that you can chose from, fortunately.

Gambit

Quote
"Jens Weiermann" <wexmanATsolidsoftwareDOTde> wrote in message

news:3cf1d1c2_1@dnews...
Quote
> Hi! I have created a component that uses custom cursors. To be
> able to do a MyComponent->Cursor = crMyCursor, I need to
> add these cursors to the global cursor list (Screen->Cursors).
> How can I do this without overriding an existing, user defined
> cursor? IOW how to I determine whether or not an index is
> already used?

Re:Adding custom cursors to Screen->Cursors


Hi Remy,

that's what I'm doing now. Here's the code I'm using:

   for (int i=32767; i > 0; i--)
   {
      if (Screen->Cursors[i] == Screen->Cursors[crDefault])
      {
         crHandOpen = i;
         Screen->Cursors[crHandOpen] = LoadCursor( HInstance, "HANDOPEN");
         break;
      }
   }

I don't really like this solution, because someone who uses my component
could at any time override the cursor at the found index by accident. I
guess I'll try the WM_SETCURSOR message directly.

Thanks!
Jens

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> schrieb im Newsbeitrag
news:3cf1ebd5$1_2@dnews...

Quote

> Of course, this requires a runtime check, which means that to ensure your
> value is truely unique, you can't really hard-code your cursor value in
your
> code but instead should generate it randomly at runtime.  Which means you
> can't use it at design-time, though.

> If you must use it at design-time, then that means that you have to pick a
> custom value that is very unlikely to be used by anyone else.  You have
> millions of values that you can chose from, fortunately.

> Gambit

> "Jens Weiermann" <wexmanATsolidsoftwareDOTde> wrote in message
> news:3cf1d1c2_1@dnews...
> > Hi! I have created a component that uses custom cursors. To be
> > able to do a MyComponent->Cursor = crMyCursor, I need to
> > add these cursors to the global cursor list (Screen->Cursors).
> > How can I do this without overriding an existing, user defined
> > cursor? IOW how to I determine whether or not an index is
> > already used?

Re:Adding custom cursors to Screen->Cursors


Most people base their cursor values from 0 upwards, so start yours from
32,767 downwards instead.  You'll have a better chance of being unique if
you want it hard-coded.

Gambit

Quote
"Jens Weiermann" <wexmanATsolidsoftwareDOTde> wrote in message

news:3cf203cd_2@dnews...
Quote
> that's what I'm doing now. Here's the code I'm using:

>    for (int i=32767; i > 0; i--)
>    {
>       if (Screen->Cursors[i] == Screen->Cursors[crDefault])
>       {
>          crHandOpen = i;
>          Screen->Cursors[crHandOpen] = LoadCursor( HInstance, "HANDOPEN");
>          break;
>       }
>    }

> I don't really like this solution, because someone who uses my
> component could at any time override the cursor at the found index
> by accident. I guess I'll try the WM_SETCURSOR message directly.

Re:Adding custom cursors to Screen->Cursors


Hi Remy,

thanks! But I'm using the WM_SETCURSOR directly now, works fine.

Jens

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> schrieb im Newsbeitrag
news:3cf28ec4$2_2@dnews...

Quote
> Most people base their cursor values from 0 upwards, so start yours from
> 32,767 downwards instead.  You'll have a better chance of being unique if
> you want it hard-coded.

> Gambit

> "Jens Weiermann" <wexmanATsolidsoftwareDOTde> wrote in message
> news:3cf203cd_2@dnews...

> > that's what I'm doing now. Here's the code I'm using:

> >    for (int i=32767; i > 0; i--)
> >    {
> >       if (Screen->Cursors[i] == Screen->Cursors[crDefault])
> >       {
> >          crHandOpen = i;
> >          Screen->Cursors[crHandOpen] = LoadCursor( HInstance,
"HANDOPEN");
> >          break;
> >       }
> >    }

> > I don't really like this solution, because someone who uses my
> > component could at any time override the cursor at the found index
> > by accident. I guess I'll try the WM_SETCURSOR message directly.

Other Threads