Search code examples
nsis

How can I resize a NSD_SetImageOLE image


I'm using the plugin macro NSD_SetImageOLE from http://nsis.sourceforge.net/NsDialogs_SetImageOLE - And I would like add another macro NSD_SetStretchedImageOLE the same way nsDialog.nsh works.

But I'm not sure is it's even possible, I've found that the resizing of an IPicture can be done by getting the "HBITMAP, BITMAP and BITMAPINFO" and resizing it (quoted from http://www.mofeel.net/958-microsoft-public-vc-mfc/12516.aspx). Anyway, I'm kind of lost trying to covert these methods to NSIS's System::Call style.


Solution

  • !ifndef IID_IPicture
        !define IID_IPicture {7BF80980-BF32-101A-8BBB-00AA00300CAB}
    !endif
    !define SRCCOPY 0xCC0020
    !include nsDialogs.nsh
    
    !define IMAGEPATH "$sysdir\migwiz\PostMigRes\Web\base_images\Documents.gif" ;"C:\Windows\Web\Wallpaper\Windows\img0.jpg"
    !define NEWSIZEW 200
    !define NEWSIZEH 100
    
    Page Custom mypagestretchcreate_GDI ; GDI resize
    Page Custom mypagestretchcreate_CTL ; Simple control resize
    
    
    Function mypagestretchcreate_GDI
    nsDialogs::Create 1018
    Pop $0
    System::Call 'oleaut32::OleLoadPicturePath(w "${IMAGEPATH}",i0r2,i0,i0,g"${IID_IPicture}",*i.r9)i.r1'
    ${If} $1 = 0
        System::Call 'user32::GetDC(i0)i.s'
        System::Call 'gdi32::CreateCompatibleDC(iss)i.r1'
        System::Call 'gdi32::CreateCompatibleBitmap(iss,i${NEWSIZEW},i${NEWSIZEH})i.r2'
        System::Call 'user32::ReleaseDC(i0,is)'
        System::Call $9->3(*i.r3)i.r4 ; IPicture->get_Handle
        ${If} $4 = 0
            System::Call 'gdi32::SetStretchBltMode(ir1,i4)'
            System::Call '*(&i40,&i1024)i.r4' ; BITMAP / BITMAPINFO
            System::Call 'gdi32::GetObject(ir3,i24,ir4)'
            System::Call 'gdi32::SelectObject(ir1,ir2)i.s'
            System::Call '*$4(i40,i.r6,i.r7,i0,i,i.s)' ; Grab size and bits-ptr AND init as BITMAPINFOHEADER
            System::Call 'gdi32::GetDIBits(ir1,ir3,i0,i0,i0,ir4,i0)' ; init BITMAPINFOHEADER
            System::Call 'gdi32::GetDIBits(ir1,ir3,i0,i0,i0,ir4,i0)' ; init BITMAPINFO
            System::Call 'gdi32::StretchDIBits(ir1,i0,i0,i${NEWSIZEW},i${NEWSIZEH},i0,i0,ir6,ir7,is,ir4,i0,i${SRCCOPY})'
            System::Call 'gdi32::SelectObject(ir1,is)'
            System::Free $4
        ${EndIf}
        System::Call 'gdi32::DeleteDC(ir1)'
        System::Call $9->2() ; IPicture->release()
    ${EndIf}
    ${NSD_CreateBitmap} 1u 1u ${NEWSIZEW} ${NEWSIZEH} ""
    Pop $9
    ;Not required when the control size matches: ${NSD_AddStyle} $9 ${SS_CENTERIMAGE}
    SendMessage $9 ${STM_SETIMAGE} ${IMAGE_BITMAP} $2
    nsDialogs::Show
    System::Call 'gdi32::DeleteObject(ir2)'
    FunctionEnd
    
    Function mypagestretchcreate_CTL
    nsDialogs::Create 1018
    Pop $2
    ${NSD_CreateBitmap} 0 1u 70% 50% ""
    Pop $3
    ${NSD_AddStyle} $3 ${SS_REALSIZECONTROL}
    File "/oname=$PLUGINSDIR\image.bmp" "${NSISDIR}\Contrib\Graphics\Header\win.bmp"
    ${NSD_SetImage} $3 "$PLUGINSDIR\image.bmp" $1
    nsDialogs::Show
    ${NSD_FreeImage} $1
    FunctionEnd