Thread overview | |||||
---|---|---|---|---|---|
|
February 25, 2017 DWT Windows Load Icon from File/Program/Resource | ||||
---|---|---|---|---|
| ||||
I'm a hobbyist and new to the D language. With a lot of help from various online resources, I finally figured out how to load an icon from: 1. A file "icon.ico" (this was easy) 2. A Program extension from the Windows registry, e.g. "*.inf" (harder) 3. A linked resource from the exe itsself (very hard) I learned how to add an icon to the exe with a compiled Resource file. Now I can load this embedded icon as the shell icon. And I don't have to distribute a separate ico file with my exe. I added a couple of simple bat files to compile with either dmd or dub. This work can be found at: https://github.com/jasc2v8/dwt-support/tree/master/windows/example-load-icon I hope this helps another newbie like me. Constructive feedback is welcome. |
February 25, 2017 Re: DWT Windows Load Icon from File/Program/Resource | ||||
---|---|---|---|---|
| ||||
Posted in reply to JamesD | On 2017-02-25 09:45, JamesD wrote: > I'm a hobbyist and new to the D language. With a lot of help from > various online resources, I finally figured out how to load an icon from: > > 1. A file "icon.ico" (this was easy) > 2. A Program extension from the Windows registry, e.g. "*.inf" (harder) > 3. A linked resource from the exe itsself (very hard) > > I learned how to add an icon to the exe with a compiled Resource file. > Now I can load this embedded icon as the shell icon. > And I don't have to distribute a separate ico file with my exe. > I added a couple of simple bat files to compile with either dmd or dub. > > This work can be found at: > > https://github.com/jasc2v8/dwt-support/tree/master/windows/example-load-icon > > > I hope this helps another newbie like me. > Constructive feedback is welcome. In D it's very simple to embed resources in the executable at compile time using string imports: immutable data = cast(immutable(uyte[]) import("foo.ico"); Compile by adding the -J flag to point to the directory where the icon files are located: dmd main.d -J./resources Then I'm pretty sure there's a an API that takes a byte array and returns an image of some sort. -- /Jacob Carlborg |
March 04, 2017 Re: DWT Windows Load Icon from File/Program/Resource | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Saturday, 25 February 2017 at 19:58:17 UTC, Jacob Carlborg wrote: > On 2017-02-25 09:45, JamesD wrote: >> I'm a hobbyist and new to the D language. With a lot of help from >> various online resources, I finally figured out how to load an icon from: >> >> 1. A file "icon.ico" (this was easy) >> 2. A Program extension from the Windows registry, e.g. "*.inf" (harder) >> 3. A linked resource from the exe itsself (very hard) >> >> I learned how to add an icon to the exe with a compiled Resource file. >> Now I can load this embedded icon as the shell icon. >> And I don't have to distribute a separate ico file with my exe. >> I added a couple of simple bat files to compile with either dmd or dub. >> >> This work can be found at: >> >> https://github.com/jasc2v8/dwt-support/tree/master/windows/example-load-icon >> >> I hope this helps another newbie like me. >> Constructive feedback is welcome. > > In D it's very simple to embed resources in the executable at compile time using string imports: > > immutable data = cast(immutable(uyte[]) import("foo.ico"); > > Compile by adding the -J flag to point to the directory where the icon files are located: > > dmd main.d -J./resources > > Then I'm pretty sure there's a an API that takes a byte array and returns an image of some sort. Very interesting, thank you! Update: I expanded and renamed this project, now at: https://github.com/jasc2v8/dwt-support/tree/master/windows/loadicon The key takeway is the Win32 API LoadImage function. Use to set the Shell icon from the program icon linked with icons.res in this exe file. |
Copyright © 1999-2021 by the D Language Foundation