Forum: wxRuby Loading icons on windows with icon index

Posted by John Bentley (misiim)
on 2010-04-27 13:38
How do you load icons on windows in wxRuby? I know in wxWidgets you use
wxIconLocation, but as far as I can see, it is not included in wxRuby.
Any ideas?

Thanks.
Posted by hendra kusuma (Guest)
on 2010-04-28 05:44
(Received via mailing list)
Do you mean to load icon to top-left of a window?
every window should have set_icon method to do that

Regards
Hendra
Posted by Alex Fenton (Guest)
on 2010-04-28 11:37
(Received via mailing list)
On 27/04/2010 12:38, John Bentley wrote:
> How do you load icons on windows in wxRuby? I know in wxWidgets you use
> wxIconLocation, but as far as I can see, it is not included in wxRuby.
> Any ideas?
>    

You can load an external icon from a file simple with
Wx::Icon.new(filepath,...)

If you have a Windows icon file containing multiple icons, you should be
able to use Wx::IconBundle.new(filepath,...), then the method
get_icon(i) to access individual icons by index.

hth
alex
Posted by John Bentley (misiim)
on 2010-04-28 13:46
Will that load all the icons from the file? It would be better to be 
able to just load one. I will be loading the icons from various system 
dlls so it wouldn't make sense to load all of them.


Alex Fenton wrote:
> On 27/04/2010 12:38, John Bentley wrote:
>> How do you load icons on windows in wxRuby? I know in wxWidgets you use
>> wxIconLocation, but as far as I can see, it is not included in wxRuby.
>> Any ideas?
>>    
> 
> You can load an external icon from a file simple with
> Wx::Icon.new(filepath,...)
> 
> If you have a Windows icon file containing multiple icons, you should be
> able to use Wx::IconBundle.new(filepath,...), then the method
> get_icon(i) to access individual icons by index.
> 
> hth
> alex
Posted by Mario Steele (Guest)
on 2010-04-29 00:12
(Received via mailing list)
If you wish to load just one Icon, create a method like this:

def load_windows_icon(dll_file,icon_number)
  ib = Wx::IconBundle.new(dll_file)
  ib.get_icon(icon_number)
end

This will return a Wx::Icon, and the ib will be put on the garbage heap 
for
release at the next run of the Garbage Collector.  There is no slowing 
down
between loading a single icon, and loading multiple Icons through
IconBundle, as wxWidgets will utilize Win32API first, and foremost, for 
most
GUI Operations.  In the case of IconBundles, it will read the Icon 
Header,
be it .ico, .dll, or .exe, and it will parse the most important 
information
needed to create the IconBundle class.  The actual extraction, and 
creation
of the Icon is deferred to when you use the get_icon method on the
IconBundle class.  An Icon Resource could have a hundred icons in it, 
and it
will not slow down the reading of the data.

hth,

Mario
Posted by Roger Sperberg (rsperberg)
on 2010-04-29 17:54
Alex Fenton wrote:
> If you have a Windows icon file containing multiple icons, you should be
> able to use Wx::IconBundle.new(filepath,...), then the method
> get_icon(i) to access individual icons by index.
> 

I apologize for asking here what I could discover on my own, but I get 
impatient about some things and I won't have access to a Mac till the 
weekend. :-)

If I have a Windows icon file with multiple icons, will the Mac use 
those icons too?

Alternatively, if I were to have a Mac icns file, does it work the same 
way you describe when on the Mac (instead of Windows)? And will Windows 
be able to access the individual icons in that file or are they 
inaccessible to it?

From the suggestion I've seen more than once to use .png for icons to 
simplify different platform use, I'm guessing these questions will be 
answered in the negative. Is the preferred method to use Wx::SetIcons 
with various sized png's if you don't know on what platform your app 
will be used?

Thanks!

Roger S

rsperberg at gmail
Posted by John Bentley (misiim)
on 2010-04-29 19:57
OK, thanks. That's good to know.
Posted by Mario Steele (Guest)
on 2010-04-29 23:13
(Received via mailing list)
Hello Roger,

On Thu, Apr 29, 2010 at 11:54 AM, Roger Sperberg 
<lists@ruby-forum.com>wrote:
>
>
> I apologize for asking here what I could discover on my own, but I get
> impatient about some things and I won't have access to a Mac till the
> weekend. :-)
>

Not a problem, we get quite a few questions on here, that people can't 
find
in documentation.


> If I have a Windows icon file with multiple icons, will the Mac use
> those icons too?


I believe that wxWidgets needs a library in order to load Widows Icon 
files
on any other system other then Windows itself.


> Alternatively, if I were to have a Mac icns file, does it work the same
> way you describe when on the Mac (instead of Windows)? And will Windows
> be able to access the individual icons in that file or are they
> inaccessible to it?
>

Mac OS X uses png's, like Linux does.  If you ever look in a .app bundle
folder, you will often find icons are in png.


> >From the suggestion I've seen more than once to use .png for icons to
> simplify different platform use, I'm guessing these questions will be
> answered in the negative. Is the preferred method to use Wx::SetIcons
> with various sized png's if you don't know on what platform your app
> will be used?
>

It is best to use PNG's for icons, simply for the fact that wxWidgets 
can
load PNG's correctly on all 3 platforms.  And you will find that if you 
load
with Wx::Bitmap, or Wx::Image, you can convert it to an Icon, through
Wx::Icon, which will allow the icon to be created in native format, to 
be
used on the platform in question.  And infact, any PNG, GIF, JPEG, etc, 
etc,
can be converted to a Icon, and used where ever Wx::Icon is required.

Thanks!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.