Results 1 to 3 of 3

Thread: WM_GETICON, IPictureDisp

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 1999
    Location
    Oak Park, IL, USA
    Posts
    43

    Question WM_GETICON, IPictureDisp

    Ok, anyone have any idea how i can turn a pointer to an icon (hIcon from a WM_GETICON) into an IPictureDisp object?

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    This should do it:
    VB Code:
    1. Public Declare Sub OleCreatePictureIndirect Lib "oleaut32.dll" (ByRef lpPICTDESC As PICTDESC, ByVal rIID As Long, ByVal fOwn As Long, ByVal lplpvObj As Long)
    2. Public Type PICTDESC
    3.    cbSizeOfStruct As Long
    4.    picType As Long
    5.    hGDIObj As Long
    6.    hPalOrXYExt As Long 'this member isn't used for icons, but is for bitmaps
    7. End Type
    8. Public Type IID
    9.    Data1 As Long
    10.    Data2 As Integer
    11.    Data3 As Integer
    12.    Data4(0 To 7) As Byte
    13. End Type
    14. Public Const hNull As Long = 0
    15. Public Function IconToPicture(ByVal hIcon As Long) As IPicture
    16.    Dim ipic As IPicture
    17.    Dim picdes As PICTDESC
    18.    Dim iidIPicture As IID
    19.    If hIcon = hNull Then Exit Function
    20.    'Fill picture description
    21.    With picdes
    22.       .cbSizeOfStruct = Len(picdes)
    23.       .picType = vbPicTypeIcon
    24.       .hGDIObj = hIcon
    25.    End With
    26.    'Fill in magic IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
    27.    With iidIPicture
    28.       .Data1 = &H7BF80980
    29.       .Data2 = &HBF32
    30.       .Data3 = &H101A
    31.       .Data4(0) = &H8B
    32.       .Data4(1) = &HBB
    33.       .Data4(2) = &H0
    34.       .Data4(3) = &HAA
    35.       .Data4(4) = &H0
    36.       .Data4(5) = &H30
    37.       .Data4(6) = &HC
    38.       .Data4(7) = &HAB
    39.    End With
    40.    'Create picture from icon handle
    41.    OleCreatePictureIndirect picdes, VarPtr(iidIPicture), True, VarPtr(ipic)
    42.    'Result will be valid a valid IPicture reference or Nothing
    43.    Set IconToPicture = ipic
    44. End Function
    Once you do this, you can do something like this:
    VB Code:
    1. Set PictureBox.Picture = IconToPicture(hIcon)

    You can also modify this to take an hBitmap and return the object loaded with it. To do that, you'd say picdes.picType = vbPicTypeBitmap, picdes.hGDIObj = hBitmap, and you can include an optional parameter for in the function for hPal, and if passed in, put that into picdes.hPalOrXYExt. Then you'll get the object back with the bitmap rather than an icon.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 1999
    Location
    Oak Park, IL, USA
    Posts
    43

    Smile that is perfect

    Thank you, thats about all I can say. This is exactly what I needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width