I have a problem loading an icon from a resource.dll and the problem is that when I load it from the dll the image gets blurred, while if I add it to the form's Icon property it gets crispy and clear (for the small size).
To create the resource.dll I use Resource Builder 4, and I load it to an Icon resource.
The icon contains 3 sizes (48x48, 32x32 and 16x16) all 32 bits depth.
I have attached 2 screen shots below that show how it looks when loaded in the IDE and in code from the resource.
This is the code I use:
In the form Load
cLang is an instance of a class I picked up online somewhere some years ago, which I to date mainly used for loading text. This is the code used and I have left out some of the more well known declarations as MoveMemory etc.
I guess my question really is if there is something wrong with my code causing this, if it's a VB6 thing OR if it is more likely to have something to do with Resource Builder and how the resource is created/provided?
Thankful for any feedback and/or point in direction as I have never really bothered with this side of VB6 earlier.
To create the resource.dll I use Resource Builder 4, and I load it to an Icon resource.
The icon contains 3 sizes (48x48, 32x32 and 16x16) all 32 bits depth.
I have attached 2 screen shots below that show how it looks when loaded in the IDE and in code from the resource.
This is the code I use:
In the form Load
Code:
Private Sub Form_Load()
...
Icon = cLang.LoadGraphic(200, ICON_IMAGE)
....
Code:
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PICDESC As PICDESC, RefIID As IID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hinst As Long, ByVal lpsz As Long, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Private Const IMAGE_ICON = 1
Public Enum GraphicTypes
BITMAP_IMAGE = 1
ICON_IMAGE = 3
CURSOR_IMAGE = 4
End Enum
Private Type IID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PicBmp
SIZE As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Type PICDESC
cbSizeOfStruct As Long
picType As Long
hGdiObj As Long
hPalOrXYExt As Long
End Type
...
Public Function LoadGraphic(lngGraphicID As Long, intGraphicType As GraphicTypes) As StdPicture
Dim lngImageH As Long
Dim stdp As StdPicture
Select Case intGraphicType
Case BITMAP_IMAGE
'load the BMP Image and get BMP Handle
lngImageH = LoadImage(m_lngResourceHandle, lngGraphicID, IMAGE_BITMAP, 0&, 0&, LR_DEFAULTCOLOR)
Case ICON_IMAGE
'load the Icon Image and get Icon Handle
lngImageH = LoadImage(m_lngResourceHandle, lngGraphicID, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR)
Case CURSOR_IMAGE
'load the Cursor Image and get Cursor Handle
lngImageH = LoadImage(m_lngResourceHandle, lngGraphicID, IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR)
End Select
'Pass the handle to the create function to create a picture of type stdpicture
CreateBitmapPicture lngImageH, intGraphicType, stdp
'return the picture
Set LoadGraphic = stdp
'free our memory
Set stdp = Nothing
End Function
Function CreateBitmapPicture(ByVal hBmp As Long, intGraphicType As GraphicTypes, stdp As StdPicture)
Dim R As Long, pic As PicBmp, IPic As StdPicture, IID_IDispatch As IID
Dim lngPicType As Long, picdes As PICDESC
Select Case intGraphicType
'assign the respective GUID's and Values
Case BITMAP_IMAGE
lngPicType = 1& 'vbPicTypeBitmap
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
picdes.picType = 1& 'vbPicTypeBitmap
Case ICON_IMAGE
lngPicType = 3& 'vbPicTypeIcon
With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
End With
picdes.picType = 3& 'vbPicTypeIcon
MoveMemory IID_IDispatch.Data4(0), dblID, 8
Case CURSOR_IMAGE
lngPicType = 3& 'vbPicTypeIcon
With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
End With
MoveMemory IID_IDispatch.Data4(0), dblID, 8
picdes.picType = 3& 'vbPicTypeIcon
End Select
picdes.cbSizeOfStruct = Len(picdes)
picdes.hGdiObj = hBmp
'Create the picture
R = OleCreatePictureIndirect(picdes, IID_IDispatch, True, stdp)
End Function
Thankful for any feedback and/or point in direction as I have never really bothered with this side of VB6 earlier.