Board index » cppbuilder » Custom Cursors

Custom Cursors


2004-02-02 01:26:44 AM
cppbuilder26
I am trying to create a custom cursor.
Using the image editor I have created a new cursor called HAND to the .res
file.
I was following the faq at bcbdev.com (www.bcbdev.com/faqs/faq24.htm)
but my cursor does not seem to change. I don't think my cursor is being
loaded,
but at this point that is just a guess.
The purpse here is to have the cursor change while the spacebar is
depressed.
Code:
const TCursor crHand = 1; // ID for cursor
__fastcall TMain::TMain(TComponent* Owner)
: TForm(Owner)
{
Screen->Cursors[crHand] = LoadCursor((void*)HInstance, "HAND");
}
void __fastcall TMain::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key == VK_SPACE)
Screen->Cursor = crHand;
}
void __fastcall TMain::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
Screen->Cursor = crDefault;
}
The cursor stays the same and no error messages are presented, so I assume
that
the cursor is not being loaded correctly.
Thanks!
 
 

Re:Custom Cursors

"oLiVeS" <olives3#Remove#@earthlink.net>wrote in message
Quote
Using the image editor I have created a new cursor called
HAND to the .res file.
If you are referring to the project's default .res file, then *do not* put
custom resources into that file at all. It is managed by the IDE and
recreated often, then losing any custom resources you place into it. You
should always place custom resources into their own separate .res file that
you then add to the project.
Gambit
 

Re:Custom Cursors

Quote
If you are referring to the project's default .res file, then *do not* put
custom resources into that file at all. It is managed by the IDE and
recreated often, then losing any custom resources you place into it. You
should always place custom resources into their own separate .res file
that
you then add to the project.
Thanks!
 

{smallsort}

Re:Custom Cursors

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote
[...] then *do not* put custom resources into that file at
all. It is managed by the IDE and recreated often, then
losing any custom resources you place into it.
The work-around is to dump the project from the IDE before
adding resources and delete the .tds before reloading the
project into the IDE.
~ JD
 

Re:Custom Cursors

Quote
The work-around is to dump the project from the IDE before
adding resources and delete the .tds before reloading the
project into the IDE.
That's ok, I will just follow Gambits advice. I got it working already, but
thanks for the help anyway.
Olives
 

Re:Custom Cursors

I do have another cursor question. I am running windows 2000 and my cursors
have a shadow effect (Pointer Shadow).
How can I create a shadow effect like that for my own cursors?
Thanks!
 

Re:Custom Cursors

"oLiVeS" <olives3#Remove#@earthlink.net>wrote in message
Quote
I do have another cursor question. I am running windows
2000 and my cursors have a shadow effect (Pointer Shadow).
The shadowing is handled by the OS itself, using layered windows for the
cursor images. I do not whether you can set that up manually or not. I
would image the OS already handling that for you automatically for any
cursor regardless of source. But I don't know, I never came across it
before.
Gambit
 

Re:Custom Cursors

I now have the cursor working on the MainForm, but I want other forms to
have access to them as
well. How should I set this up so that any form can access the cursors?
Thanks!
 

Re:Custom Cursors

"oLiVeS" <olives3#Remove#@earthlink.net>wrote:
Quote
[...] How should I set this up so that any form can access
the cursors?
Once added, the new cursor is added to the global Screen
variable so it's already accessable anywhere in the application.
All you need to do now is to make your crMyCursor global as well.
~ JD
BTW : That other post was intended for Gambit because he
*always* advocates putting resources in a seperate file. While
I agree that it's good practice for a number of reasons, it's
not always a must.
 

Re:Custom Cursors

Quote
Once added, the new cursor is added to the global Screen
variable so it's already accessable anywhere in the application.
All you need to do now is to make your crMyCursor global as well.
I guess the question is how do you make it global?
Thanks!
 

Re:Custom Cursors

"oLiVeS" <olives3#Remove#@earthlink.net>wrote:
Quote
I guess the question is how do you make it global?
You already did (according to your initial post).
const TCursor crHand = 1; // ID for cursor
To let other units see it, define it again preceeded with the
key word 'extern':
extern const TCursor crHand; // ID for cursor
~ JD
 

Re:Custom Cursors

Quote
You already did (according to your initial post).

const TCursor crHand = 1; // ID for cursor

To let other units see it, define it again preceeded with the
key word 'extern':

extern const TCursor crHand; // ID for cursor
That's what I thought you meant, but I guess I just got a little confused.
But, I did fine a better way, instead of redefining it again in every form.
I declared it in the header of my MainForm just before the class. Now
whenever I need them I just include the MainForm header.
But now that I think of it, is it better to do it your way or mine. Won't
my method use more memory because it will be including a lot of other
stuff too?
Thanks!
 

Re:Custom Cursors

"oLiVeS" <olives3#Remove#@earthlink.net>wrote in message
Quote
But, I did fine a better way, instead of redefining it again in
every form. I declared it in the header of my MainForm just
before the class. Now whenever I need them I just include
the MainForm header.
I would suggest putting it into its own header instead of the MainForm's,
ie:
--- MyCursors.h ---
#ifndef MyCursors_H
#define MyCursors_H
extern const TCursor crHand;
#endif
--- SomeFile.cpp ---
const TCursor crHand = 1;
Then you can simply #include "MyCursors.h" where needed.
Quote
Won't my method use more memory because it will be
including a lot of other stuff too?
No, because that "stuff" is only included once regardless of how many times
you #include the file. That is why header file have header guards
surrounding the content to begin with.
Gambit
 

Re:Custom Cursors

Quote
I would suggest putting it into its own header instead of the MainForm's,

--- MyCursors.h ---

#ifndef MyCursors_H
#define MyCursors_H

extern const TCursor crHand;

#endif


--- SomeFile.cpp ---

const TCursor crHand = 1;
Does this need to be done on every form that needs the cursors or just on
the
form that loads them?
Quote
Then you can simply #include "MyCursors.h" where needed.
I am having some trouble using this method, here is what I got so far.
I have changed crHand to crOpenHand.
--- MyCursors.h ---
#ifndef MyCursors_H
#define MyCursors_H
extern const TCursor crOpenHand;
extern const TCursor crFingerHand;
extern const TCursor crZoomIn;
extern const TCursor crZoomOut;
#endif
--- MainWin.cpp ---
const TCursor crOpenHand = 1;
const TCursor crFingerHand = 2;
const TCursor crZoomIn = 3;
const TCursor crZoomOut = 4;
--- PreferencesWin.cpp ---
#include "MyCursors.h"
__fastcall TPreferences::TPreferences(TComponent* Owner)
: TForm(Owner)
{
BackgroundColorPanel->Cursor = crFingerHand;
}
I get the following errors:
[Linker Error] Unresolved external '_crFingerHand' referenced from
E:\...\PREFERENCESWIN.OBJ
Thanks!
 

Re:Custom Cursors

"oLiVeS" <olives3#Remove#@earthlink.net>wrote:
Quote
Does this need to be done on every form that needs the
cursors or just on the form that loads them?
Neigther.
Don't include MyCursors.h in the unit where they are defined.
I'm unclear if including the header (extern definitions) in
the same unit where they're defined is a problem or not but it
makes sense not to.
In addition, in the unit where they are defined, you want them
to NOT be part of the class (form). You can accomplish this by
placeing their definitions directly above the unit's constructor:
const TCursor crOpenHand = 1;
const TCursor crFingerHand = 2;
const TCursor crZoomIn = 3;
const TCursor crZoomOut = 4;
//------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{
}
Now in any other unit that needs to use them, simply include
the cursor header.
~ JD