mercoledì 21 settembre 2011

2 way to create a VB Picture from a GDI Picture Handle

*********************
1: (es: Picture added to ImageList)
*********************

    Dim hndRsrc As Long
    Dim tPicConv As PictDesc
    Dim IGuid As GUID
    Dim arrNewPic As Picture


    hndRsrc = ExtractIcon(App.hInstance, filenameAppz, indexIcon)

    With tPicConv
        .cbSizeofStruct = Len(tPicConv)
        .PicType = TYPE_ICON
        .hImage = hndRsrc '<<<< associate to tPicConv(PictDesc)
    End With

    With IGuid
        .Data1 = &H7BF80980 'IPicture    {7BF80980-BF32-101A-8BBB-00AA00300CAB}  interface
        .Data2 = &HBF32
        .Data3 = &H101A
        .Data4(0) = &H8B
        .Data4(1) = &HBB
        .Data4(2) = &H0
        .Data4(3) = &HAA
        .Data4(4) = &H0
        .Data4(5) = &H30
        .Data4(6) = &HC
        .Data4(7) = &HAB
    End With

    OleCreatePictureIndirect tPicConv, IGuid, True, arrNewPic
    indexImageList = indexImageList + 1
    Form1.ImageList.ListImages.Add indexImageList, , arrNewPic               
    Form1.List.ListItems.Add , , "string blabla", , , indexImageList

*********************
2: (create a control Picture1 on Form as store temporary)
*********************
* es: indexIcon=-123 (-123 must really match in the icon)

    hndRsrc = ExtractIcon(App.hInstance, filenameAppz, indexIcon)
    ret = DrawIconEx(Form1.Picture1.hdc, 0, 0, hndRsrc, 24, 24, 0, 0, 3)
    Form1.Picture1.Refresh
    indexImageList = indexImageList + 1
    Form1.ImageList.ListImages.Add indexImageList, , Form1.Picture1.Image
    Form1.List.ListItems.Add , , "string blabla", , indexImageList


************************************************
* Format IPicture (COM)

'IPicture    {7BF80980-BF32-101A-8BBB-00AA00300CAB}  interface
'              Prop Get  Handle  (), Ret:VT_INT
'              Prop Get  hPal    (), Ret:VT_INT
'              Prop Get  Type    (), Ret:VT_I2
'              Prop Get  Width   (), Ret:VT_I4
'              Prop Get  Height  (), Ret:VT_I4
'              Method    Render  (hdc:VT_INT, x:VT_I4, y:VT_I4, cx:VT_I4, cy:VT_I4, xSrc:VT_I4, ySrc:VT_I4, cxSrc:VT_I4, cySrc:VT_I4, prcWBounds:VT_VOID), Ret:VT_HRESULT
'              Prop Put  hPal    (), Ret:VT_INT
'              Prop Get  CurDC   (), Ret:VT_INT
'              Method    SelectPicture   (hdcIn:VT_INT, phdcOut:VT_INT, phbmpOut:VT_INT), Ret:VT_HRESULT
'              Prop Get  KeepOriginalFormat  (), Ret:VT_BOOL
'              Prop Put  KeepOriginalFormat  (), Ret:VT_BOOL
'              Method PictureChanged(), ret: VT_HRESULT
'              Method    SaveAsFile  (pstm:VT_VOID, fSaveMemCopy:VT_BOOL, pcbSize:VT_I4), Ret:VT_HRESULT
'              Prop Get  Attributes  (), Ret:VT_I4
'              Method    SetHdc  (hdc:VT_INT), Ret:VT_HRESULT

*****************************************************************
** Result: Icon On ListView
*****************************************************************

Nessun commento:

Posta un commento