dontpanic92 / wxGo

Golang wxWidgets Wrapper
Other
403 stars 51 forks source link

How to show icon? #40

Closed spieglt closed 6 years ago

spieglt commented 6 years ago

I've found a couple different methods for embedding an .ico file in a Go executable on Windows (for example: https://github.com/akavel/rsrc). They show up as the program's icon before running it, but how do I get an icon to show in the top-left of the Frame while the program is running?

spieglt commented 6 years ago

Nevermind, figured it out. Make a file called "sample.rc" with contents as simple as appicon ICON "myIcon.ico"

With a valid "myIcon.ico" file in the same directory as "sample.rc," run this: windres -i sample.rc -O coff -o sample.syso (windres comes with MinGW or TDM-GCC.)

Put the resulting "sample.syso" file in the same folder as your .go files (where you run go build).

In your Go code, where you declare your main wxWidgets Frame, have code like:

myFrame = wx.NewFrame(wx.NullWindow, wx.ID_ANY, "My Program Name")

icon := wx.NewIcon("appicon", wx.BITMAP_TYPE_ICO_RESOURCE, -1, -1)

myFrame.SetIcon(icon)

Then when you run go build, it will automatically embed the icon, and it will be accessible from within wxWidgets by the name you put in the .rc file ("appicon" in this case").

blimmo commented 6 years ago

Will these syso files link into the executable on other OSes (e.g. linux)?

I'm looking for a cross platform method of embedding images. In C I used xpms so I'm hoping this is a good alternative.

To be clear I'm happy for the syso to only compile on windows but I'd like my program to be buildable on other OSes (I'd include the syso)

spieglt commented 6 years ago

No, this is just for Windows. For Mac, I used XCode to make this .plist file: https://github.com/spieglt/FlyingCarpet/blob/master/icons/Mac/info.plist And this guide to make the icons: https://blog.macsales.com/28492-create-your-own-custom-icons-in-10-7-5-or-later

No idea about Linux unfortunately.