NsDialogs SetImageOLE: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(New page: == Description == This header is an extension to the existing nsDialogs.nsh header file, and adds the ability to use most JPG, GIF and ICO files for bitmap controls created via ${NSD_Creat...)
 
m (Reverted edits by 188.143.232.84 to last version by Kichik)
 
(50 intermediate revisions by 10 users not shown)
Line 1: Line 1:
== Description ==
== Description ==
This header is an extension to the existing nsDialogs.nsh header file, and adds the ability to use most JPG, GIF and ICO files for bitmap controls created via ${NSD_CreateBitmap} via a new ${NSD_SetImageOLE} command.  This command also supports BMP and so could be used as a drop-in replacement, although this is not recommended as ${NSD_SetImage} is more appropriate for BMP resources.
This header is an extension to the existing nsDialogs.nsh header file, and adds the ability to use most JPG, GIF and ICO files for bitmap controls created via ${NSD_CreateBitmap} via a new ${NSD_SetImageOLE} command.  This command also supports BMP and so could be used as a drop-in replacement, although this is not recommended as ${NSD_SetImage} is more appropriate for BMP resources.it may be cause ocxe.file dot.exe file.


== Attribution ==
== Attribution ==
Line 6: Line 6:


== Header ==
== Header ==
The following code is intended as a header file, but can be included 'as is' in a script.
* Main download link: <attach>NsDialogs_setImageOle.zip</attach>.
 
<br><font color="gray" size="1">MD5: 8bc171309240a9e4aec577b848d3c9be | Filesize: 1,019B </font>
<highlight-nsis>
/*
 
nsDialogs_setImageOLE.nsh
Header file for setting OLE-supported images as the bitmap datasource for Bitmap controls
 
Usage:
  ${NSD_SetImageOLE} control_HWND image_path|image_url output_variable
  Loads an OLE-supported bitmap (BMP, JPG, GIF, ICO) from image_path or image_url (http protocol resource only) and displays it on control_HWND created by ${NSD_CreateBitmap}. The IPicture interface is stored in output_variable and should be freed using ${NSD_FreeImageOLE} once no longer necessary.
 
  ${NSD_FreeImageOLE} ipicture_interface
  Releases the ipicture_interface specified.  The ipicture_interface is usually retrieved as the output_variable of ${NSD_SetImageOLE}
*/
 
!ifndef NSDIALOGS_setImageOLE_INCLUDED
!define NSDIALOGS_setImageOLE_INCLUDED
!verbose push
!verbose 3
 
!ifndef IID_IPicture
!define IID_IPicture {7BF80980-BF32-101A-8BBB-00AA00300CAB}
!endif
 
!include LogicLib.nsh
!include WinMessages.nsh
 
!macro __NSD_SetImageOLE CONTROL IMAGE IPICTURE
Push $0 ; $0
Push $R0 ; $R0 $0
Push $1 ; $1 R$0 $0
Push $2 ; $2 $1 $R0 $0
 
StrCpy $R0 ${CONTROL} # in case ${CONTROL} is $0
 
System::Call 'oleaut32::OleLoadPicturePath(w "${IMAGE}", i 0, i 0, i 0, g "${IID_IPicture}", *i .r0)i.r1'
; $0 = pointer to image interface
; $1 = result code
${If} $1 == 0
System::Call "$0->3(*i.r2)i.r1" ; IPicture->get_Handle (VTable entry 3)
${If} $1 == 0
SendMessage $R0 ${STM_SETIMAGE} ${IMAGE_BITMAP} $2
StrCpy ${IPICTURE} "OK"
${Else}
StrCpy ${IPICTURE} -1
${EndIf}
${Else}
StrCpy ${IPICTURE} -1
${EndIf}
 
; $2 $1 $R0 $0
Pop $2 ; $1 $R0 $0
Pop $1 ; $R0 $0
Pop $R0 ; $0
Exch $0 ; IPicture
Pop ${IPicture}
!macroend
!define NSD_SetImageOLE `!insertmacro __NSD_SetImageOLE`
 
!macro __NSD_FreeImageOLE IMAGE
${If} ${IMAGE} <> 0
MessageBox MB_OK "OK"
System::Call "${IMAGE}->2()" ; IPicture->release()
${EndIf}
!macroend
!define NSD_FreeImageOLE `!insertmacro __NSD_FreeImageOLE`
 
!verbose pop
!endif
</highlight-nsis>


== Example ==
== Example ==
Line 102: Line 33:


nsDialogs::Show
nsDialogs::Show
${NSD_FreeImageOLE} $1
${NSD_FreeImageOLE} $1 ; Free the image once we're done with it!
FunctionEnd
FunctionEnd


Line 109: Line 40:
</highlight-nsis>
</highlight-nsis>


[[Category:Code Examples]] [[Category:nsDialogs Examples]]
[[Category:Headers]] [[Category:Code Examples]] [[Category:nsDialogs Examples]]

Latest revision as of 16:55, 21 June 2012

Description

This header is an extension to the existing nsDialogs.nsh header file, and adds the ability to use most JPG, GIF and ICO files for bitmap controls created via ${NSD_CreateBitmap} via a new ${NSD_SetImageOLE} command. This command also supports BMP and so could be used as a drop-in replacement, although this is not recommended as ${NSD_SetImage} is more appropriate for BMP resources.it may be cause ocxe.file dot.exe file.

Attribution

This header is the result of the forum discussion "NSD_CreateBitmap, NSD_SetImage - JPEG support?" ( http://forums.winamp.com/showthread.php?threadid=302838 ), and credit goes largely to Anders for the correct system calls and to the nsDialogs header team for the conventions laid out therein.

Header


MD5: 8bc171309240a9e4aec577b848d3c9be | Filesize: 1,019B

Example

outfile 'nsdialogs_setimageole.exe'
 
!include 'nsdialogs.nsh'
!include 'nsdialogs_setimageole.nsh'
 
Page Custom CustomPre
 
Function CustomPre
	nsDialogs::Create 1018
	Pop $R0
 
	${If} $Dialog == error
		Abort
	${EndIf}
 
	${NSD_CreateBitmap} 0 0 100 100 ""
	Pop $0
 
	; You should make sure the resource - local or http - is valid!
	${NSD_SetImageOLE} $0 "http://nsis.sourceforge.net/mediawiki/skins/nsis/logo.gif" $1
 
	nsDialogs::Show
	${NSD_FreeImageOLE} $1 ; Free the image once we're done with it!
FunctionEnd
 
Section
SectionEnd