Another program icon via command line

New to FreeBASIC? Post your questions here.
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Another program icon via command line

Postby newbieforever » Jul 06, 2018 23:08

And now for something completely different:

I know that the icon of a FB-compiled program can be set by including a rc file when compiling the code (with FB_PROGRAM_ICON ICON "MyIcon.ico").

How a FB program (MyProgram.exe) could be enabled (by its code) to change its icon via command line:
MyProgram.exe /icon:AnotherIcon.ico



My ultimate wish would be an additional option to return to the previous icon (used as default) via
MyProgram.exe /icon:
But this is probably not easy (or impossible) to implement...



EDIT:
Inserted later (because my question seems to be not clear enough):

MyProgram.exe is my FB-compiled program. It is a launcher program used to launch another programs, flexibly in the following way: If I rename MyProgram.exe to ProgA.exe, it will launch the program tmp\ProgASomething.exe; If I rename it to ProgB.exe, it will launch the program tmp\ProgBSomething.exe. (This is just for illustration, my real setting is more meaningful than it is recognizable here.)

What want is to add to MyProgram.exe (by an included code) the option: 'MyProgram.exe /icon:AnotherIcon.ico'. With this CL no program should be launched, only the program icon of MyProgram.exe (as shown in Windows Explorer) should be changed.

By this way I would be able to change the icon of MyProgram.exe to the icon of tmp\ProgA.exe etc. After renaming MyProgram.exe to ProgA.exe, on the icon of this launcher ProgA.exe would be recognizable which program will be launched.

As stated in my OP: My ultimate wish would be an additional option to return to the default icon (applied when compiling) via
MyProgram.exe /icon
(or at least to return to no specific icon).
Last edited by newbieforever on Jul 08, 2018 20:45, edited 2 times in total.
MrSwiss
Posts: 2811
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Another program icon via command line

Postby MrSwiss » Jul 07, 2018 9:53

The stack-overflow article is NOT related, to what OP seeks. (explained in Wikipedia article, below)

More info on .ico file format can be found here: Wikipedia - ICO (file format)
St_W
Posts: 1407
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Another program icon via command line

Postby St_W » Jul 07, 2018 10:13

You cannot change the icon of the EXE file displayed by explorer (without modifying the EXE itself) because that is statically read from that file.

What you actually can change are the icons displayed in the upper-left corner of the window border / the icon shown in the taskbar when the application runs. Use LoadImage and the WM_SETICON messages as shown by grindstone to do that.
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Re: Another program icon via command line

Postby newbieforever » Jul 07, 2018 11:12

St_W wrote:You cannot change the icon of the EXE file displayed by explorer (without modifying the EXE itself)...


That's exactly what I want: an icon-changer code in FB, which changes the icon of an exe (modifying the exe itself, of course), and which in my case would be applied to the FB exe itself.
MrSwiss
Posts: 2811
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Another program icon via command line

Postby MrSwiss » Jul 07, 2018 11:37

newbieforever wrote:That's exactly what I want: an icon-changer code in FB, which changes the icon of an exe (modifying the exe itself, of course)

In that case (as I've suspected, btw.), happy hacking ...
(I don't want to be part of, or have anything to do with, any such thing!)
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Re: Another program icon via command line

Postby newbieforever » Jul 07, 2018 12:18

Oh god, that childish paranoid reflex again ... (Arguing probably useless: There are plenty of free tools that do the same thing [eg RH]. And the FB compiler does it, too. But: If anyone wants to write such a code itself, he can only intend the destruction of the world, of course...)
marcov
Posts: 2643
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Another program icon via command line

Postby marcov » Jul 07, 2018 12:53

An easier workaround can be to hide the .exe (e.g. a directory level deeper) and create some shortcuts. One can change the type of icons of shortcut.
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Re: Another program icon via command line

Postby newbieforever » Jul 07, 2018 13:15

marcov wrote:An easier workaround can be to hide the .exe (e.g. a directory level deeper) and create some shortcuts. One can change the type of icons of shortcut.


Thank you, marcov! Yes, but in my project's setting I need an exe, not a lnk file...
MrSwiss
Posts: 2811
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Another program icon via command line

Postby MrSwiss » Jul 07, 2018 13:56

@newbieforever,

I don't care, if you call me paranoid, because I am (working in ICT security, makes
one so, if one isn't from the outset, which is considered: a asset!).
However, never again ever, call me "childish", otherwise you'll learn my "other side",
and this is: a promise ...
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Re: Another program icon via command line

Postby newbieforever » Jul 07, 2018 14:31

I would never call anyone childish. I'm only talking about a childish reflex.
dodicat
Posts: 5225
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Another program icon via command line

Postby dodicat » Jul 07, 2018 15:49

Mr Swiss cannot read that.

Code: Select all

 

screen 19,32
data 73,32,119,111,117,108,100,32,110,101,118,101,114,32,99,97,108,108,32,97,110,121,111,110,101,32,99,104,105,108,100,105,115
data 104,46,32,73,39,109,32,111,110,108,121,32,116,97,108,107,105,110,103,32,97,98,111,117,116,32,97,32,99,104,105,108,100
data 105,115,104,32,114,101,102,108,101,120

dim as string g=string(76,0)

for n as long=0 to 75
    read g[n]
next

dim as any ptr i=imagecreate(800,600,0)
draw string i,(0,300), g
put(0,0),i

#define map(a,b,x,c,d) ((d)-(c))*((x)-(a))/((b)-(a))+(c)

Type d2
    As Single mx,my
    As Single mw
End Type

Sub Blow(b As d2,i as any ptr=0)
        static  As Ulong _colour(81,81)
        static as long result
        #macro rotate(pivotx,pivoty,px,py,a,scale)
        var Newx=scale*((px-pivotx))+pivotx
        var Newy=scale*((py-pivoty))+pivoty
        #endmacro
        #macro incircle(cx,cy,r,mx,my,a)
        If a<=1 Then
        result=a*(cx-mx)*a*(cx-mx) +1*(cy-my)*1*(cy-my)<= r*r*a*a
        Else
        result=a*(cx-mx)*a*(cx-mx) +1*(cy-my)*1*(cy-my)<= (r)*(r)
        End If
        #endmacro
       
        If b.mw=0 Then b.mw=1
        b.mw=Abs(b.mw)
        For x As long=b.mx-40 To b.mx+40
            For y As long=b.my-40 To b.my+40
                incircle(b.mx,b.my,40,x,y,1.5)
                If result Then
                    _colour(x-b.mx+40,y-b.my+40)=Point(x,y,i)
                End If
            Next y
        Next x
       
        static As Single dil
        For x As long=b.mx-40 To b.mx+40
            For y As long=b.my-40 To b.my+40
                incircle(b.mx,b.my,40,x,y,1.5)
                If result Then
                    rotate(b.mx,b.my,x,y,0,dil)
                    var dist=Sqr((b.mx-newx)*(b.mx-newx)+(b.my-newy)*(b.my-newy))
                    dil=(b.mw+(.5-b.mw)*dist/(40*b.mw))
                    incircle(b.mx,b.my,(20*b.mw),newx,newy,1.5)
                    If result Then
                        Line(NewX-dil/2,NewY-dil/2)-(NewX+dil/2,NewY+dil/2),_colour(x-b.mx+40,y-b.my+40),BF
                    End If
                End If
            Next y
        Next x
    End Sub
   
    sub mapper(i as any ptr)
        dim as single yp
        for x as long=0 to 600
            for y as long=290 to 310
                yp=map(290,310,y,297,303)
                pset(x,yp),point(x,y,i)
            next
            next
        end sub
       
    dim as long mx,my,mw
    dim as d2 b
    windowtitle "Mouse magnifier"
    do
        getmouse mx,my,mw
        b=type(mx,my,mw)
        screenlock
        cls
        mapper(i)
        Blow(b,i)
        'print s
        screenunlock
        sleep 1,1
        loop until len(inkey)
       
imagedestroy(i)
sleep
 
grindstone
Posts: 582
Joined: May 05, 2015 5:35
Location: Germany

Re: Another program icon via command line

Postby grindstone » Jul 07, 2018 15:55

@newbieforever: It's not quite clear to me what you are intended to do: Do you want to manipulate an existing exe-file, or do you want to embed multiple icons in an exe-file compiled by yourself and then choose one of that icons at runtime? If the latter, maybe this could be helpful:
https://msdn.microsoft.com/en-us/library/ms997538.aspx
newbieforever
Posts: 84
Joined: Jun 21, 2018 11:14

Re: Another program icon via command line

Postby newbieforever » Jul 07, 2018 16:30

@grindstone:
"How a FB program (MyProgram.exe) could be enabled (by its code) to change its icon via command line:
MyProgram.exe /icon:AnotherIcon.ico"
Yes, MyProgram will be my program compiled by me, and this my program should have the feature described above. When the program is launched next time after applying the above command it should have the new icon.

@dodicat:
Very nice!!!
MrSwiss
Posts: 2811
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Another program icon via command line

Postby MrSwiss » Jul 07, 2018 16:36

hi dodicat,

sorry, but you missed the second 'full stop' (second sentence). <lol>

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests