I've got an Icon File that has a transparent background and I need to set
this icon like the icon's form in run time. Whe I do this with LoadImage
function, the transparent background is replaced with black. I can't use a
resource file, I need to set the icon from an icon file, because this file
depends on the end user.
Any idea of how can I fix that?
Private Sub Form_Load()
Me.Icon = LoadPicture(App.Path & "\x.ico")
End Sub
Thanks!
LoadImage() won't fill the background of an icon, I'm guessing though that you're using a 32-bit icon with an alpha channel which
isn't supported natively however this article may be of some use to you:
http://www.vbaccelerator.com/home/VB/Tips/Setting_the_App_Icon_Correctly/article.asp
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: ED...@mvps.org
WWW: Http://www.mvps.org/EDais/
Thanks for answer me, but the big proble to me is that I can't use a
resource file because the end user can create any icon file and the
application has to set that icon in the mdi main form, the icon is 16x16
Thanks for your help
"Mike D Sutton" <ED...@mvps.org> escribió en el mensaje
news:%23tXQU4b...@TK2MSFTNGP12.phx.gbl...
It's a while since I've looked at the article, but doesn't it just take an API icon handle? (IIRC the icon was only saved in a
resource for convenience since it didn't need to be changed and re-loaded from disk every time.) If so then you can use the
LoadImage() API call to load that from disk rather than using VB's LoadPicture() which does the bit-depth conversion nastiness
behind the scenes.
Thanks again for answer me!
I've never used LoadImage or LoadIcon to do that, and I'm not getting to
much info about that, could you give me an example please?
The icon file has this conditions:
- 16x16 size (and only that image device)
- 16 color depth
- transparent background
I create those icons with MS-Visual C++ Icon Editor.
Thanks for your help again!
"Mike D Sutton" <ED...@mvps.org> escribió en el mensaje
news:e0xZdjic...@TK2MSFTNGP11.phx.gbl...
'***
Private Declare Function LoadImage Lib "User32.dll" Alias "LoadImageA" ( _
ByVal hInst As Long, ByVal lpszName As String, ByVal uType As Long, _
ByVal cxDesirded As Long, ByVal cyDesired As Long, ByVal fuLoad As Long) As Long
Private Declare Function DrawIconEx Lib "User32.dll" (ByVal hDC As Long, _
ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, _
ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal iStepIfAniCur As Long, _
ByVal hBrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "User32.dll" (ByVal hIcon As Long) As Long
Private Const IMAGE_ICON As Long = &H1
Private Const LR_LOADFROMFILE As Long = &H10
Private Const DI_NORMAL As Long = &H3
Private Sub Form_Load()
Dim hIcon As Long
Const IconFile As String = "X:\Path\File.ico"
Me.AutoRedraw = True
hIcon = LoadImage(App.hInstance, IconFile, IMAGE_ICON, 32, 32, LR_LOADFROMFILE)
Call DrawIconEx(Me.hDC, 0, 0, hIcon, 0, 0, 0, 0, DI_NORMAL)
Call DestroyIcon(hIcon)
hIcon = LoadImage(App.hInstance, IconFile, IMAGE_ICON, 16, 16, LR_LOADFROMFILE)
Call DrawIconEx(Me.hDC, 32, 0, hIcon, 0, 0, 0, 0, DI_NORMAL)
Call DestroyIcon(hIcon)
End Sub
'***
Thanks!
"Mike D Sutton" <ED...@mvps.org> escribió en el mensaje
news:OX6QDtnc...@TK2MSFTNGP11.phx.gbl...
Wasn't that what the vbaccelerator article demonstrated?..