🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
7 messages
7 total messages Started by JD Fri, 11 Apr 2003 17:51
Animated Cursor
#17060
Author: JD
Date: Fri, 11 Apr 2003 17:51
8 lines
986 bytes
Could someone please point me to an example of making and using
an animated cursor? Google simply returns too many hits to
narrow down to something that I can use.

TIA

~ JD
Re: Animated Cursor
#17066
Author: nicolasr
Date: Fri, 11 Apr 2003 23:57
15 lines
1508 bytes
Hi,

for making animated cursors you can try Microsofts free AniEdit
together with your favorite graphics editor. I forgot the original
Microsoft URL but this site has the files, look out for AniEdit:
http://freepctech.com/pc/002/files003.shtml

I then put my animated cursor into the resources of my exe but loading
the cursor from resource didn't work. I finally stored the cursor as a
file resource (RT_DATA). Then on startup of my program I created the
cursor as a file from the resource and loaded it from that file. That
worked. If you need some code let me know.

Hope this helps,
Nick
Re: Animated Cursor
#17069
Author: JD
Date: Sat, 12 Apr 2003 01:26
19 lines
1443 bytes
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote:
> you can try Microsofts free AniEdit

Free is good ;-)

> [...] finally stored the cursor as a file resource (RT_DATA).
> Then on startup of my program I created the cursor as a file
> from the resource and loaded it from that file. That worked.
> If you need some code let me know.

Code is always nice - especially when you don't know what
you're doing so ... if it wouldn't be too much trouble please.

> Hope this helps

Bunches already. Thanks Nick

~ JD
Re: Animated Cursor
#17071
Author: nicolasr
Date: Sat, 12 Apr 2003 02:46
65 lines
2692 bytes
Hi,

I tried to setup the code in a simple test application.
Assuming you have a new project and a cursor file
MyAniCursor.ani in the project directory:

Add a resource file to the project (f.e. resource.rc) and add this
line to the file:

MyAniCursor RCDATA "MyAniCursor.ani"


then add this function to your project:

#define crMyAniCursor 1

void LoadMyAniCursor()
{
   //build the filename for the cursor file
   AnsiString fileName = ExtractFilePath(Application->ExeName) +
"MyAniCursor.ani";

   //locate the cursor resource,
   //you should add some error checking on the return values...
   HRSRC ResourceHandle = FindResource(HInstance, "MyAniCursor",
RT_RCDATA);
   HGLOBAL GlobalHandle = LoadResource(HInstance, ResourceHandle);
   PVOID Data = LockResource(GlobalHandle);

   //create the empty cursor file
   int FileHandle = FileCreate(fileName);

   //write the data from the resource to the file
   FileWrite
   (
      FileHandle,
      Data,
      SizeofResource(HInstance, ResourceHandle)
   );

   FileClose(FileHandle);

   //finally load the cursor from the file
   //and add it to the default cursors.
   //The default cursor constants are all negative, custom
   //cursors should have positive constants
   HCURSOR h = LoadCursorFromFile(fileName.c_str());
   if(h)
      Screen->Cursors[crMyAniCursor] = h;
}


//this example constructor initializes the cursor
//and sets the current cursor to your animated cursor

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   LoadMyAniCursor();
   Screen->Cursor = crMyAniCursor;
}


regards,
Nick
Re: Animated Cursor
#16977
Author: JD
Date: Sat, 12 Apr 2003 06:04
12 lines
1336 bytes
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote:
> Add a resource file to the project (f.e. resource.rc) and add
> this line to the file:
>
>             MyAniCursor RCDATA "MyAniCursor.ani"

Your code looks complete and easy to read. Many Thanks. I still
have one question though. I have only ever used .res files. How
would I create a .rc file? Is it just a text file?

~ JD
Re: Animated Cursor
#16978
Author: JD
Date: Sat, 12 Apr 2003 06:24
10 lines
1171 bytes
"JD" <nospam@nospam.com> wrote:
>
> How would I create a .rc file?

I googled to some instructions - simple.

Thanks again.

~ JD
Re: Animated Cursor
#16982
Author: Fishface
Date: Sat, 12 Apr 2003 16:54
54 lines
2501 bytes
nicolasr wrote:

> I tried to setup the code in a simple test application.
> Assuming you have a new project and a cursor file
> MyAniCursor.ani in the project directory:
>
> Add a resource file to the project (f.e. resource.rc) and add this
> line to the file:
>
> MyAniCursor RCDATA "MyAniCursor.ani"
>
>
> then add this function to your project:
>
> #define crMyAniCursor 1
>
> void LoadMyAniCursor()

 <snip>

That probably works fine, but you might rather do
something like this instead:

HICON LoadMyAniCursor()
{
  HICON icon_error = reinterpret_cast<HICON>(-1);
  HRSRC hrsrcicon = FindResource(HInstance, "MyAniCursor", RT_RCDATA);
      if(!hrsrcicon) return icon_error;
  DWORD rsrcsize = SizeofResource(HInstance, hrsrcicon);
      if(!rsrcsize) return icon_error;
  HGLOBAL hglobal = LoadResource(HInstance, hrsrcicon);
      if(!hglobal) return icon_error;
  PVOID pvoid = LockResource(hglobal);
      if(!pvoid) return icon_error;
  HICON hIcon = CreateIconFromResource(static_cast<PBYTE>(pvoid),
                             rsrcsize, TRUE, 0x00030000);
      if(!hIcon) return icon_error;
  return hIcon;
}


__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
 HICON icon = LoadMyAniCursor();
 if(icon != INVALID_HANDLE_VALUE )
    Screen->Cursors[crMyAniCursor] = icon;
}


void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Screen->Cursor = crMyAniCursor;
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads