Page 1 of 1

adding icon to executable

Posted: Sat May 01, 2004 11:02 am
by thefool
Hi!

Im thinking about writing an EXE Bundler. I have created a method
to pack and unpack file with filenames, so no problem there. But now i wonder, how can i let the user choose the icon of the final exe?
The final exe is built like this:

Uncompresser
Packed files+filetag

Its like an exe that gets a packed file in the end, and then it can uncompress those files and run and delete them..

How do i let the user change the icon of my uncompresser (the program the enduser runs.)

Posted: Sat May 01, 2004 5:08 pm
by thefool
well i guess you dont answer because you cant do it.. :(

Posted: Sat May 01, 2004 5:12 pm
by fweil
I can( figure out how to find the icon"s handle when the app is running.

I searched WinAPI docs but nothing answers well right now.

I will let it open some more time and try again.

Rgrds

Posted: Sat May 01, 2004 5:43 pm
by GPI
The API doesn't help, because ResourceChange don't work under 9X-Systems (and the unicode-dll doesn't work, or i don't see any working code).

ResHacker can change Resourcen and it has a script-support.

When you use jaPBe:

Hold shift (don't release!)
Projekt>Create executeable
Select a name
OK

During the compiling DON'T RELEASE shift.

After some times, a dos-box should appear with the linker-commands. Now go to the purebasic\compilers directory and copy all the lib, obj which are named in the dos-box. Also copy the complete command-string out of the dos-box.
Now you have the to link files and the command-string to create the exe and to change the icon.
the icon is in the _japbe_0.obj (the source for this resource you found in _japbe_0.rc) Change the source of this obj, create a obj-file (for example with gorc), then start the linker with command-string and you get a exe with your own icon and your own version string, and so on...

Posted: Sat May 01, 2004 5:43 pm
by thefool
i also searched the api.

Well, i belive pb can do anything. So who knows how to do this?

Posted: Sun May 09, 2004 2:01 am
by fweil
...,

If you would like the user to be able to change the program icon, you may find your way looking there and adapting the code. You will need to g further with API to understand how to get compatible icons from files or generate it by yourself.

Here I use a tip to change program icon on the fly using standard icons which constants are numbered from 32512 to 32517 !

Code: Select all

;
; Main starts here
;
  Quit = #FALSE
  WindowXSize = 320
  WindowYSize = 240

  Resource.l = #IDI_APPLICATION

  tz = GetTickCount_()
  If OpenWindow(0, 0, 0, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow")
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      Repeat
        Select WindowEvent()
          Case #PB_Event_CloseWindow
            Quit = #TRUE
          Case #PB_Event_Menu
            Select EventMenuID()
              Case #PB_Shortcut_Escape
                Quit = #TRUE
            EndSelect
          Case #PB_EventGadget
            Select EventGadgetID()
            EndSelect
          Case #WM_LBUTTONDOWN
            ReleaseCapture_()
            SendMessage_(hWnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
          Default
        EndSelect
        If GetTickCount_() - tz > 1000
            Resource + 1
            If Resource > #IDI_WINLOGO
                Resource = #IDI_APPLICATION
            EndIf
            DestroyIcon_(hIcon)
            hIcon = LoadIcon_(0, Resource)
            SendMessage_(WindowID(), #WM_SETICON, 0, hIcon)
            tz = GetTickCount_()
        EndIf
        Delay(1)
      Until Quit
  EndIf
  TerminateProcess_(GetCurrentProcess_(), 0)
End

Posted: Sun May 09, 2004 8:04 am
by thefool
thanks fweil and gpi. :D

will test it out later.

Posted: Sun May 09, 2004 11:48 am
by omid-xp
Thanks fweil . :D