tags:

views:

308

answers:

1

Does anyone have any code to read and write a res file with just cursors in the res file that they can share?

I have tried on multiple occasions over a multitude of days to get Colin Wilsons XN resource units to compile and function in Delphi 2009 without much success.

To get his code to compile I have had to replace PChar with PAnsiChar in a few places as well as use CharInSet. Non-the-less I am having a terrible time.

Delphi does not have a good modern resource editor so I am attempting to create one.

To start I was trying to just read a resfile containing only cursors and build a treeview with cursor groups and cursors. Once I get that working I'd like to be able to edit and save the res file... and to be able to add a cursor to the res file from a cursor file.

I think if I can just get his code to read and write I can accomplish this. I am willing to redistribute the source code.

Thanks in advance.

+1  A: 

A resource file is simple to create. I'm not sure why you need a visual editor for it.

In MyCursor.rc:

MYCURSOR1 Cursor MyCursor.cur

In your Delphi project file or main form file:

{$R MyCursor.rc MyCursor.res}

In code:

const
  crMyCursor = 1;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.Cursor[crMyCursor] := LoadImage(hInstance, 'MYCURSOR1', IMAGE_CURSOR,
                                         0, 0, LR_DEFAULTSIZE);
  Cursor := crMyCursor;
end;

No resource editor needed.

Once in a while, using the above $R compiler directive, you can get an error message related to an invalid 16-bit resource, even though you're sure it's not. You can resolve that by compiling the resource script yourself from the command line:

brcc32 MyCursor.rc MyCursor.res

Then change the line in your Delphi source to

{$R MyCursor.res}

The rest works the same exact way as the code above demonstrates.

Ken White
Thanks for your reply, but I am trying to build a res editor "good modern resource editor so I am attempting to create one." ... not just trying to load a Screen.Cursor.
But you're missing my point. There are tons of free and commercial icon editors; that's what you use to create cursors. There are tons of free and commercial image editors for bitmaps. String resources are just lists of strings that are assigned identifiers. You don't need a resource editor at all.
Ken White