Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Using Win32API to load an icon from .ico file

Reply
Thread Tools

Using Win32API to load an icon from .ico file

 
 
Tom Robinson
Guest
Posts: n/a
 
      07-12-2004
Has anyone successfully managed to do this? I'm trying to write an
app using vruby which adds icons to the systray. VRuby comes with an
example of how to do this, which works, except it does not say how to
load the icons you want from .ico files. Instead it just uses icons
out of the user32.dll I think. This is the code it uses to load the
icons:

LoadIcon = Win32API.new("user32","LoadIcon","II","I")
QUESTIONICON= LoadIcon.call(0,32514)

That works fine, and QUESTIONICON can then be used to call
create_trayicon, but I'm trying to do this:

LoadIconA = Win32API.new("user32","LoadIcon",['I','P'],"I")
FOOICON= LoadIconA.call(0,"myicon.ico")

I think if you give a string as a second argument to the LoadIcon call
in the user32.dll it'll try and load from a file, but I'm not 100%
sure. The docs from MS say that LoadIcon is deprecated and you should
use LoadImage but that's even more complicated from what I can tell.
I've found a few examples on the web of people who've used LoadIcon to
load from .ico files (I think), but none of them are in ruby. I'm not
sure if I'm specifying the parameter types correctly using ['I','P']
for an integer and a string either. Anyway, it loads a blank icon at
the moment so it isn't working.

Anyone managed to accomplish this before?

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
remove 'spamfree.' to respond
 
Reply With Quote
 
 
 
 
Michael Geary
Guest
Posts: n/a
 
      07-13-2004
> LoadIconA = Win32API.new("user32","LoadIcon",['I','P'],"I")
> FOOICON= LoadIconA.call(0,"myicon.ico")
>
> I think if you give a string as a second argument to the LoadIcon
> call in the user32.dll it'll try and load from a file, but I'm not
> 100% sure.
>
> The docs from MS say that LoadIcon is deprecated and you should
> use LoadImage but that's even more complicated from what I can tell.
> I've found a few examples on the web of people who've used LoadIcon to
> load from .ico files (I think), but none of them are in ruby. I'm not
> sure if I'm specifying the parameter types correctly using ['I','P']
> for an integer and a string either. Anyway, it loads a blank icon at
> the moment so it isn't working.


LoadIcon is for loading icons from executable or resource files such as
DLLs. The second argument is the resource ID for the icon, not a filename.
The resource ID can be either a string or an integer less than 65536,
depending on how the icon resource was defined when the DLL was built. The
first argument is an HINSTANCE for the DLL, which you obtain by calling
LoadLibrary or LoadLibraryEx.

To load an icon from a .ico file, use either ExtractIcon or LoadImage.
ExtractIcon is simpler, but it only looks for one size of icon, the "system
large" size, typically 32x32 or 48x48. If you want to be able to control
which size icon you get, use LoadImage instead.

I don't have Ruby code handy to do this, but if you Google for the function
names above you'll get the MSDN documentation for them.

-Mike


 
Reply With Quote
 
 
 
 
Tom Robinson
Guest
Posts: n/a
 
      07-13-2004
On Mon, 12 Jul 2004 22:13:51 -0700, "Michael Geary" <(E-Mail Removed)>
wrote:

>To load an icon from a .ico file, use either ExtractIcon or LoadImage.
>ExtractIcon is simpler, but it only looks for one size of icon, the "system
>large" size, typically 32x32 or 48x48. If you want to be able to control
>which size icon you get, use LoadImage instead.
>
>I don't have Ruby code handy to do this, but if you Google for the function
>names above you'll get the MSDN documentation for them.


Thanks, ExtractIcon was what I needed! Here's the code that works:

ExtractIcon = Win32API.new("shell32","ExtractIcon",['I','P','I'],"I")
FOOICON = ExtractIcon.call(0,"myicon.ico",0)

And then this FOOICON can be used in the create_trayicon function.

Fantastic, I thought it was going to be a lot trickier for some
reason. Cheers!

--
(E-Mail Removed)
remove 'spamfree.' to respond
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the win32api antoine crouzi Ruby 4 04-19-2011 12:02 PM
Using win32api Tristin Davis Ruby 0 06-19-2008 07:12 PM
"no module named win32api" using PyWin32-208 Mike Python 0 06-27-2006 01:21 PM
Moving Directory using win32api::File Brian Perl Misc 2 04-22-2004 08:32 PM
Anyone using RegisterClass from Win32API? Michael Davis Ruby 1 07-29-2003 03:42 AM



Advertisments