Demo to add a resource file to the exe file

Started by Roland Stowasser, November 10, 2024, 07:51:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Roland Stowasser

Hi Charles,

I would like to ask because of the  "adding file.res" option in co2.exe / co2m64.exe:

could the folder \demos\WinDynDialogs\ExeWithRes be replaced? The demo was created with an older version of OxygenBasic and I adjusted the code a little. I have also added kurbis.bmp in the folder with a decreased number of colors (requires slightly less disk space / memory and simplifies the .rc file).

There are two batch files:
Build_AppIcon_old.bat creates the demo the old way by co2.exe / co2m64.exe creating AppIcon.exe, GoRC creating AppIcon.res from AppIcon.rc and LinkRes appending AppIcon.res to AppIcon.exe.

Build_AppIcon.bat creates the demo in a new way by directly adding an existing AppIcon.res file when compiling to AppIcon.exe. This can be an advantage when developing an application if you do not want to keep re-creating the .res file. E.g. AppIcon.rc, kurbis.bmp and manifest.xml would no longer be necessary in the folder if there were no changes to the resources.

Attached is ExeWithRes.zip with the necessary files to  create the demo.


AppIcon.o2bas:
'====================================================================
' Icon as Application Icon and Bitmap from resource, modal dialog as main.
'
' Resources must be kept in a .rc file e.g.
' 1000 Icon   "..\..\..\tools\oxicon.ico"
' 1001 BITMAP DISCARDABLE "kurbis.bmp"
'
' The compiled .res file can be linked with LinkRes.exe
' or directlly with co2.exe / co2m64.exe by adding the Name.res file   
'====================================================================

#compact

$ filename "AppIcon.exe"

uses dialogs

% IDI_APPICON=1000
% IDB_BITMAP =1001

==============================================

'MAIN CODE
=============================================
 
sys hInstance = GetModuleHandle(NULL)


function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback
  select case uMsg
 
    case WM_INITDIALOG
       sys AppIcon = LoadIcon(hInstance, IDI_APPICON)
       'Set Icon to Main Window
       SendMessage(hDlg, WM_SETICON, ICON_BIG, AppIcon)
       return true

    case WM_COMMAND
       select case loword(wParam)
         case IDCANCEL
            EndDialog( hDlg, null )
       end select
     
    case WM_CLOSE
       EndDialog( hDlg, null )
               
  end select

  return 0
end function

'====================================================================

sub winmain()

  Dialog( 0, 0, 200, 100, "Memory based modal dialog using OxygenBasic",
          WS_OVERLAPPEDWINDOW or DS_CENTER )
  PushButton( "Close" , IDCANCEL, 80, 70, 40, 12 )

  Control("",100, "STATIC",SS_BITMAP, 0, 0, 0, 0, , 1001)

  CreateModalDialog( null, @DialogProc, 0 )
end sub

winmain()


Charles Pegge

Thanks Roland, I have replaced your previous version.