MSI: Switch back to using IPicture to load images

Mike McCormack mike at codeweavers.com
Tue Oct 25 07:36:46 CDT 2005


(note: The text below was generated from my tree using the a script. Let 
me know if the format is OK. Yey for Wine 0.9...)

ChangeLog:
Switch back to using IPicture to load images.  LoadImage did the
resizing for us, but doesn't handle jpeg files and requires us writing a 
temp file, whereas IPicture handles jpeg files and can load directly 
from a stream.


  dlls/msi/dialog.c |   70 
+++++++++++++++++++++++++++++++++++++++++++++++++++--
  1 files changed, 68 insertions(+), 2 deletions(-)

0512f04bad6599c86fc0a87cd277e2ab3f8f1aa0
diff --git a/dlls/msi/dialog.c b/dlls/msi/dialog.c
--- a/dlls/msi/dialog.c
+++ b/dlls/msi/dialog.c
@@ -750,6 +750,73 @@ static UINT msi_dialog_scrolltext_contro
      return ERROR_SUCCESS;
  }

+static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
+                                 INT cx, INT cy, DWORD flags )
+{
+    HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
+    MSIRECORD *rec = NULL;
+    IStream *stm = NULL;
+    IPicture *pic = NULL;
+    HDC srcdc, destdc;
+    BITMAP bm;
+    UINT r;
+
+    rec = msi_get_binary_record( db, name );
+    if( !rec )
+        goto end;
+
+    r = MSI_RecordGetIStream( rec, 2, &stm );
+    msiobj_release( &rec->hdr );
+    if( r != ERROR_SUCCESS )
+        goto end;
+
+    r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
+    IStream_Release( stm );
+    if( FAILED( r ) )
+    {
+        ERR("failed to load picture\n");
+        goto end;
+    }
+
+    r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
+    if( FAILED( r ) )
+    {
+        ERR("failed to get bitmap handle\n");
+        goto end;
+    }
+
+    /* make the bitmap the desired size */
+    r = GetObjectW( hOleBitmap, sizeof bm, &bm );
+    if (r != sizeof bm )
+    {
+        ERR("failed to get bitmap size\n");
+        goto end;
+    }
+
+    if (flags & LR_DEFAULTSIZE)
+    {
+        cx = bm.bmWidth;
+        cy = bm.bmHeight;
+    }
+
+    srcdc = CreateCompatibleDC( NULL );
+    hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
+    destdc = CreateCompatibleDC( NULL );
+    hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
+    hOldDestBitmap = SelectObject( destdc, hBitmap );
+    StretchBlt( destdc, 0, 0, cx, cy,
+                srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
+    SelectObject( srcdc, hOldSrcBitmap );
+    SelectObject( destdc, hOldDestBitmap );
+    DeleteDC( srcdc );
+    DeleteDC( destdc );
+
+end:
+    if ( pic )
+        IPicture_Release( pic );
+    return hBitmap;
+}
+
  static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD 
*rec )
  {
      UINT cx, cy, flags, style, attributes;
@@ -773,8 +840,7 @@ static UINT msi_dialog_bitmap_control( m
      cy = msi_dialog_scale_unit( dialog, cy );

      text = msi_get_deformatted_field( dialog->package, rec, 10 );
-    control->hBitmap = msi_load_image( dialog->package->db, text,
-                                       IMAGE_BITMAP, cx, cy, flags );
+    control->hBitmap = msi_load_picture( dialog->package->db, text, cx, 
cy, flags );
      if( control->hBitmap )
          SendMessageW( control->hwnd, STM_SETIMAGE,
                        IMAGE_BITMAP, (LPARAM) control->hBitmap );




More information about the wine-patches mailing list