get icon from application exe

  • Thread starter Thread starter Dominique Vandensteen
  • Start date Start date
D

Dominique Vandensteen

I want to get the icon from my application exe file

dim myIcon as Icon = ... -> "myApplication.exe,0"

how can I do that?
 
Hi Dominique,

I never tested it have to do that still but I thought this was where you
where looking for?

Herfried will surely confirm when he does his round.

:-)

\\\By Herfried K Wagner
foo.Icon = _
New Icon( _
[Assembly].GetExecutingAssembly().GetManifestResourceStream( _
"WindowsApplication1.Ball.ico" _
) _
)
///

Cor
 
Cor,

* "Cor said:
I never tested it have to do that still but I thought this was where you
where looking for?

Herfried will surely confirm when he does his round.

I am not sure if this will solve the problem, but it will work for
embedded icon ressources.

;-)
 
* "Dominique Vandensteen said:
I want to get the icon from my application exe file

dim myIcon as Icon = ... -> "myApplication.exe,0"

how can I do that?

AFAIS p/invoke on 'ExtractIconEx' if the icon is embedded as Win32
resource.
 
Addendum:
I am not sure if this will solve the problem, but it will work for
embedded icon ressources.

It won't work because the application icon is embedded as Win32
resource and .NET cannot deal with Win32 resources.
 
Hi Herfried,

Can you give me that routine dominique is using, I will try it also.

But finding out that wheel that you have 10000 times done, you know I will
distribute it only with your name.


Cor
 
it works here...
code:

Public Declare Function DestroyIcon Lib "User32.dll" (ByRef phicon As
IntPtr) As Boolean
Public Declare Function ExtractIconEx Lib "shell32.dll" _
(ByVal lpszFile As String, ByVal nIconIndex As Integer, _
ByRef phiconLarge As IntPtr, ByRef phiconSmall As IntPtr, ByVal nIcons As
Integer) _
As IntPtr
....
Dim iconPtr As IntPtr
Dim myIcon As Icon
ExtractIconEx(Application.ExecutablePath, 0, iconPtr, Nothing, 1)
-> returnvalue is number of icons found, so normally check for > 0 :-)
myIcon = Icon.FromHandle(iconPtr)
....
when "finished using" the icon:
DestroyIcon(iconPtr)


dominique
 
Hi Dominique,

Thanks

2 questions,
written by yourself (because I add that when I redistribute that)
combobox problem Net 1.0 or Net 1.1
Cor
 
Hi Herfried,

That I can also do myself but than I do not know which one is working.

And it is a German site how can I read that.

I try that one from Dominique, she is nice for me.

Cor
 
written by yourself (because I add that when I redistribute that)

euh yes, with help of herfried's hint :-)
combobox problem Net 1.0 or Net 1.1

workaround by doing .selectedIndex=-1 twice
and add a (boolean) variable IgnoreEvent which is true "around" the first
..selectindex=-1 so the switch to index 0 is ignored...

something like:
sub button_click()
IgnoreEvent = true
comboBox1.selectedIndex = -1
IgnoreEvent = false
comboBox1.selectedIndex = -1
end sub

sub combobox_selectedIndexChangedOrSomethingLikeThat()
if(IgnoreEvent) then exit Sub
'do stuff
end sub


dominique
 
Back
Top