Recent

Author Topic: Compile resource files for a WINAPI window by means of Lazres  (Read 1963 times)

Pieter

  • New Member
  • *
  • Posts: 23
Compile resource files for a WINAPI window by means of Lazres
« on: August 02, 2022, 04:57:50 pm »
For Windows 11, on a 64-bit laptop, I used Lazres to recompile the resource files for the WINAPI application in GetClientRect in:

https://forum.lazarus.freepascal.org/index.php/topic,52902.msg390865.html#msg390865, see also the attachment

I called Lazres in the following way (compilation of the resources in Lazarus did not work, input file could not be found)
Code: Pascal  [Select][+][-]
  1. lazres GetClientRect.RES GetClientRect.rc APPICON.ICO

with GetClientRectangle.rc:
Code: Pascal  [Select][+][-]
  1. #include "resource.pas"
  2.  
  3. APPICON                 ICON                        "APPICON.ICO"
  4.  
  5. APPMENU                 MENU
  6.   BEGIN
  7.     POPUP "&File"
  8.       BEGIN
  9.          MENUITEM "E&xit"                        ,   IDM_EXIT
  10.       END
  11.  
  12.     POPUP "&Help    "
  13.       BEGIN
  14.          MENUITEM "&About  GetClientRect ..."    ,   IDM_ABOUT
  15.       END
  16.   END
  17.  
  18. ABOUTBOX DIALOG 42, 20, 170, 90
  19. STYLE DS_MODALFRAME | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
  20. CAPTION "About GetClientRect"
  21. FONT 8, "MS Sans Serif"
  22. BEGIN
  23.   ICON              "APPICON", -1, 10, 10, 32, 32
  24.   LTEXT             "Win32 API Example - Functions", -1, 35, 10, 170, 10
  25.   LTEXT             "GetClientRect", -1, 35, 20, 170, 10
  26.   CTEXT             "Copyright \251 1997  440bx",-1, 1, 40, 170, 10
  27.   CTEXT             "All rights reserved.", -1, 1, 48, 170, 10
  28.   DEFPUSHBUTTON     "OK", IDOK, 60, 67, 50, 14
  29. END  

and the implied Resource.pas file

Code: Pascal  [Select][+][-]
  1. unit resource;
  2.   { resource IDs for the GetClientRect example                                }
  3.  
  4. {-----------------------------------------------------------------------------}
  5. INTERFACE
  6. {-----------------------------------------------------------------------------}
  7.  
  8. const
  9.  IDM_EXIT        = 900;
  10.  
  11.  IDM_ABOUT       = 990;
  12.  
  13. {-----------------------------------------------------------------------------}
  14. IMPLEMENTATION
  15. {-----------------------------------------------------------------------------}
  16.  
  17. end.

To my surprise, the icon is incorporated in the program but the menus are not. What is is happening here? I'd be happy to know so I can use the procedure for other applications requiring resource compilation



« Last Edit: August 02, 2022, 06:20:44 pm by Pieter »

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #1 on: August 02, 2022, 06:18:48 pm »
I've seen that problem before.  It's related to the fact that Lazarus manages resource and resource files a bit differently.

Have a look at this thread: https://forum.lazarus.freepascal.org/index.php/topic,40830.msg282333.html#msg282333

the solution/explanation is quite likely there.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #2 on: August 02, 2022, 09:48:44 pm »
You should not even need to call LazRes. The compiler will do that for you..... Only if you change the rc file you will need a rebuild for the whole program.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Pieter

  • New Member
  • *
  • Posts: 23
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #3 on: August 03, 2022, 01:04:26 pm »
You should not even need to call LazRes. The compiler will do that for you..... Only if you change the rc file you will need a rebuild for the whole program.

This was what I expected but I get the following error message, in addition to two warnings
Code: Pascal  [Select][+][-]
  1. Error while compiling resources -> Compile with -vd for more details. Check for duplicates
  2. Warning: windres [option(s)] [input-file] [output-file]
  3. windres: supported targets: pe-i386 pei-i386 elf32-i386 elf32-iamcu elf32-little elf32-big pe-x86-64 pei-x86-64 pe-bigobj-x86-64 elf64-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big plugin srec symbolsrec verilog tekhex binary ihex
  4.  

That's why I used the Lazres separate compilation but with the problem mentioned above.

Pieter

  • New Member
  • *
  • Posts: 23
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #4 on: August 03, 2022, 01:10:41 pm »
I've seen that problem before.  It's related to the fact that Lazarus manages resource and resource files a bit differently.

Have a look at this thread: https://forum.lazarus.freepascal.org/index.php/topic,40830.msg282333.html#msg282333

the solution/explanation is quite likely there.

I did have a look a the thread but renaming the resource file with a name different from the program does not have an effect.
That is, if I do:
Code: Pascal  [Select][+][-]
  1. lazres JustAResource.RES GetClientRect.rc APPICON.ICO
and include the RES file in the source program, the implied resources (i.e. the menu's) do not show up.
I wonder if I did apply Lazres correctly. What could be the matter?

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #5 on: August 03, 2022, 07:56:32 pm »
Code: Pascal  [Select][+][-]
  1. lazres JustAResource.RES GetClientRect.rc APPICON.ICO
and include the RES file in the source program, the implied resources (i.e. the menu's) do not show up.
I wonder if I did apply Lazres correctly. What could be the matter?
The problem is that the "lazres" command you showed above does NOT include the menu nor the dialog in the resource file as menu and dialog resources.

It includes the entire "GetClientRect.rc" as raw resource data.  IOW, it is not parsing and compiling that resource script.  If you want to see what it does, use ResourceHacker (nice little utility, I highly recommend it.)

I don't know exactly what Lazres is supposed to do but, it doesn't seem to be a resource compiler.

Just FYI, I use the resource compiler that was included with Delphi (BRCC32.exe)
« Last Edit: August 03, 2022, 07:58:35 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Pieter

  • New Member
  • *
  • Posts: 23
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #6 on: August 04, 2022, 05:59:59 pm »
@440bx:
Quote
I don't know exactly what Lazres is supposed to do but, it doesn't seem to be a resource compiler.

I agree, given the error and warning messages I mentioned above it seems that windres is used by Lazarus. However, it does not work, as far as I know.
Maybe somebody else can shed some light on this issue?

@440bx:
Quote
Just FYI, I use the resource compiler that was included with Delphi (BRCC32.exe)

Thanks for this information. This does work.  :D

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #7 on: August 04, 2022, 06:11:47 pm »
Thanks for this information. This does work.  :D
You're welcome.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #8 on: August 04, 2022, 10:46:35 pm »
Just FYI, I use the resource compiler that was included with Delphi (BRCC32.exe)

Note that trunk has a native resource compiler (fpcres)

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #9 on: August 04, 2022, 10:53:18 pm »
Note that trunk has a native resource compiler (fpcres)
Yes, I remember PascalDragon mentioning that. I will eventually start using it.  I also remember he mentioned that, at least at that time, there were some resource types it couldn't handle, I believe (not sure) keyboard accelerators were among them.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Pieter

  • New Member
  • *
  • Posts: 23
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #10 on: August 06, 2022, 12:48:59 pm »
Just FYI, I use the resource compiler that was included with Delphi (BRCC32.exe)

Note that trunk has a native resource compiler (fpcres)

As a newbie, I don't understand what is meant by 'trunk' here.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6683
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #11 on: August 06, 2022, 01:18:17 pm »
As a newbie, I don't understand what is meant by 'trunk' here.

https://www.freepascal.org/develop.var

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #12 on: August 06, 2022, 01:23:11 pm »
As a newbie, I don't understand what is meant by 'trunk' here.

Nowadays "Main" in git-speak, though many still use SVN era "trunk", is the branch with the newest development.

The other significant branch is the branch from which releases are made, which is called FIXES_x_y with x.y the first two digits of the version number of the releases (3.2 now)

Pieter

  • New Member
  • *
  • Posts: 23
Re: Compile resource files for a WINAPI window by means of Lazres
« Reply #13 on: August 06, 2022, 06:10:11 pm »
Thanks for the update!

 

TinyPortal © 2005-2018