Another program icon via command line
Re: Another program icon via command line
@newbieforever
I find your small font posts annoying
I find your small font posts annoying
-
- Posts: 117
- Joined: Jun 21, 2018 11:14
Re: Another program icon via command line
@srvaldez: Tiny font means:
All these weird and wonderful nerds here make life difficult for the newbieforever with their childish quirks.
The nerd newbieforever has to take revenge somehow.
Sorry, it's all a joke, do not take it so seriously.
All these weird and wonderful nerds here make life difficult for the newbieforever with their childish quirks.
The nerd newbieforever has to take revenge somehow.
Sorry, it's all a joke, do not take it so seriously.
Re: Another program icon via command line
@newbieforever
yes of course, but the older I get, the less my sense of humor.
yes of course, but the older I get, the less my sense of humor.
-
- Posts: 117
- Joined: Jun 21, 2018 11:14
Re: Another program icon via command line
@srvaldez: In my case, it's the other way round.
Re: Another program icon via command line
Actually you have posted the solution yourself, with your AutoHotkey code, which just seems to call some regular Win32 API methods. I haven't used any of those yet (and tbh didn't even know of their existence), but it should be pretty straightforward to translate the AHK code to FB.
There even seems to be an example in MSDN on updating resources:
https://docs.microsoft.com/en-gb/window ... -resources
PS: I find your tiny fonts annoying too.
There even seems to be an example in MSDN on updating resources:
https://docs.microsoft.com/en-gb/window ... -resources
PS: I find your tiny fonts annoying too.
Re: Another program icon via command line
there are quite a large number of web articles related to changing the icon at runtime https://www.codeguru.com/cpp/w-p/win32/ ... ources.htm
but I simply don't have the expertise.
using fbfrog you get a good start at translating the code to FB
but I simply don't have the expertise.
using fbfrog you get a good start at translating the code to FB
Code: Select all
#pragma once
#include once "crt/long.bi"
#include once "io.bi"
#include once "crt/stdio.bi"
#include once "crt/stdlib.bi"
#include once "fcntl.bi"
#include once "windows.bi"
extern "C"
type GROUPICON field = 2
Reserved1 as WORD
ResourceType as WORD
ImageCount as WORD
Width as BYTE
Height as BYTE
Colors as BYTE
Reserved2 as BYTE
Planes as WORD
BitsPerPixel as WORD
ImageSize as DWORD
ResourceID as WORD
end type
private sub InjectMainIcon(byval Where as zstring ptr, byval What as zstring ptr)
'' TODO: HANDLE hWhere = BeginUpdateResource(Where, FALSE);
dim buffer as zstring ptr
dim buffersize as clong
dim hFile as long
hFile = open(What, O_RDONLY or O_BINARY)
if hFile = (-1) then
return
end if
buffersize = filelength(hFile)
buffer = cptr(zstring ptr, malloc(buffersize))
read(hFile, buffer, buffersize)
close(hFile)
UpdateResource(hWhere, RT_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), buffer + 22, buffersize - 22)
dim grData as GROUPICON
grData.Reserved1 = 0
grData.ResourceType = 1
grData.ImageCount = 1
grData.Width = 32
grData.Height = 32
grData.Colors = 0
grData.Reserved2 = 0
grData.Planes = 2
grData.BitsPerPixel = 32
grData.ImageSize = buffersize - 22
grData.ResourceID = 1
UpdateResource(hWhere, RT_GROUP_ICON, "MAINICON", MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), @grData, sizeof(GROUPICON))
'' TODO: delete buffer;
EndUpdateResource(hWhere, FALSE)
end sub
private sub main(byval argc as long, byval argv as zstring ptr ptr)
if argc <> 3 then
printf("Usage: chicon [executable filename] [icon filename]")
return
end if
InjectMainIcon(argv[1], argv[2])
end sub
end extern
Re: Another program icon via command line
@newbieforever
You play constantly with this tiny police and it's annoying.
Therefore I lost interest in all your posts (and I'm certainly not the only one).
You play constantly with this tiny police and it's annoying.
Therefore I lost interest in all your posts (and I'm certainly not the only one).
Re: Another program icon via command line
srvaldez
you frog translation works.
chicon.bas
compile to exe
in a folder
From a shell;
chicon file.exe file.ico
You will see the icon changing.
Here is a shell
shell.bas
compile to exe
you frog translation works.
chicon.bas
compile to exe
Code: Select all
#include once "crt/long.bi"
#include once "crt/io.bi"
#include once "crt/stdio.bi"
#include once "crt/stdlib.bi"
#include once "windows.bi"
#include "file.bi"
type GROUPICON field = 2
Reserved1 as WORD
ResourceType as WORD
ImageCount as WORD
Width as BYTE
Height as BYTE
Colors as BYTE
Reserved2 as BYTE
Planes as WORD
BitsPerPixel as WORD
ImageSize as DWORD
ResourceID as WORD
end type
sub InjectMainIcon(byval Where as string , byval What as string)
var hwhere= beginupdateresourceA(where,0)
dim buffer as zstring ptr
dim buffersize as clong
dim hFile as any ptr
hFile = fopen(What,"rt+")', O_RDONLY or O_BINARY) 'two Irishmen ??
if hFile = (-1) then
return
end if
fseek(hfile, 0, SEEK_END)' // seek to end of file
buffersize = ftell(hfile)' // get current file pointer
fseek(hfile, 0, SEEK_SET)'re set
buffer = cptr(zstring ptr, malloc(buffersize))
fread( buffer,buffersize,1,hfile)
fclose(hFile)
UpdateResource(hWhere, RT_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), buffer + 22, buffersize - 22)
dim grData as GROUPICON
grData.Reserved1 = 0
grData.ResourceType = 1
grData.ImageCount = 1
grData.Width = 32
grData.Height = 32
grData.Colors = 0
grData.Reserved2 = 0
grData.Planes = 2
grData.BitsPerPixel = 32
grData.ImageSize = buffersize - 22
grData.ResourceID = 1
UpdateResource(hWhere, RT_GROUP_ICON, "MAINICON", MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), @grData, sizeof(GROUPICON))
free (buffer)
EndUpdateResource(hWhere, FALSE)
end sub
printf("Usage: chicon [executable filename] [icon filename]")
if fileexists(command(1))=0 then print " " +command(1) + " not found":end
if fileexists(command(2))=0 then print " " + command(2) + " not found":end
InjectMainIcon(command(1), command(2))
'InjectMainIcon("pool.exe","icon.ico") 'test OK
'sleep
From a shell;
chicon file.exe file.ico
You will see the icon changing.
Here is a shell
shell.bas
compile to exe
Code: Select all
shell "cmd"
Last edited by dodicat on Jul 10, 2018 10:03, edited 1 time in total.
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: Another program icon via command line
It's not a good idea to bully people you want to get help from.newbieforever wrote:Tiny font means:
All these weird and wonderful nerds here make life difficult for the newbieforever with their childish quirks.
The nerd newbieforever has to take revenge somehow.
Re: Another program icon via command line
Actually, a simple example showing how to change an icon in an existing executable. But it can't read directly from a *.ico file, so you would need a bunch of executables containing the desired icons.St_W wrote:There even seems to be an example in MSDN on updating resources:
https://docs.microsoft.com/en-gb/window ... -resources
Besides, it won't help OP because he needs to embed also his mysterious other executables to be launched.
-
- Posts: 117
- Joined: Jun 21, 2018 11:14
Re: Another program icon via command line
Many thanks to all who helped me here! You are all great!
I know, in your posts here everything is already included, it only has to be written the code. But because I do not know enough about this at the moment, I will use my AHK solution for the time being because I have more knowledge there.
I'm also making good progress with my project, but there are always new insidious problems...
I know, in your posts here everything is already included, it only has to be written the code. But because I do not know enough about this at the moment, I will use my AHK solution for the time being because I have more knowledge there.
I'm also making good progress with my project, but there are always new insidious problems...
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: Another program icon via command line
@newbieforever:
Only for me to know if I got you right: Your intention is that your launcher inherits the icon of the exe it launches. Correct?
Only for me to know if I got you right: Your intention is that your launcher inherits the icon of the exe it launches. Correct?
Re: Another program icon via command line
I have adjusted the above code slightly.
Please note: With the code as it stands,the .ico file must be 128 by 128 in size.
Also it should be a proper .ico format, not a re-named bitmap file.
Please note: With the code as it stands,the .ico file must be 128 by 128 in size.
Also it should be a proper .ico format, not a re-named bitmap file.
-
- Posts: 117
- Joined: Jun 21, 2018 11:14
Re: Another program icon via command line
@grindstone:
Inherit? Not in an automatic way, if that's what you mean.
I am giving the Launcher the icon. Actually, I give it to both––to the Launcher and to the exe which is to be started.
Inherit? Not in an automatic way, if that's what you mean.
I am giving the Launcher the icon. Actually, I give it to both––to the Launcher and to the exe which is to be started.
-
- Posts: 117
- Joined: Jun 21, 2018 11:14
Re: Another program icon via command line
@dodicat:
I have no possibility to create a 128 x 128 icon at the moment (IcoFX doesn't support this size), so I can't test it. As you said, it doesn't work with other sizes.
But, as I already said, I am using now the AHK solution, which will be good enogh for the moment (for a Proof-of-the-Concept of my project), so this has not a high priority at the moment.
Especially because I have other problems to deal with...
I have no possibility to create a 128 x 128 icon at the moment (IcoFX doesn't support this size), so I can't test it. As you said, it doesn't work with other sizes.
But, as I already said, I am using now the AHK solution, which will be good enogh for the moment (for a Proof-of-the-Concept of my project), so this has not a high priority at the moment.
Especially because I have other problems to deal with...