LoadAndSetImage can return the image handle

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7179 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2020-05-01 13:15:03 +00:00
parent 52da4576ba
commit e73d05f1f5
7 changed files with 31 additions and 24 deletions

View file

@ -969,11 +969,11 @@ Exch
!macroend
!macro __NSD_SetIconFromExeResource CONTROL IMAGE HANDLE
!insertmacro __NSD_LoadAndSetImage exeresource ${IMAGE_ICON} 0 ${LR_DEFAULTSIZE} "${CONTROL}" "${IMAGE}" ${HANDLE}
LoadAndSetImage /EXERESOURCE /STRINGID "${CONTROL}" ${IMAGE_ICON} ${LR_DEFAULTSIZE} "${IMAGE}" ${HANDLE}
!macroend
!macro __NSD_SetIconFromInstaller CONTROL HANDLE
!insertmacro __NSD_SetIconFromExeResource "${CONTROL}" "#103" ${HANDLE}
LoadAndSetImage /EXERESOURCE "${CONTROL}" ${IMAGE_ICON} ${LR_DEFAULTSIZE} 103 ${HANDLE}
!macroend
!define NSD_SetImage `!insertmacro __NSD_LoadAndSetImage file ${IMAGE_BITMAP} 0 "${LR_LOADFROMFILE}" `

View file

@ -73,9 +73,11 @@ If HWND is a window, Gotos jump_if_window, otherwise, Gotos jump_if_not_window (
\S2{loadandsetimage} LoadAndSetImage
\c [/EXERESOURCE] [/STRINGID] [/RESIZETOFIT[WIDTH|HEIGHT]] ctrl imagetype lrflags image
\c [/EXERESOURCE] [/STRINGID] [/RESIZETOFIT[WIDTH|HEIGHT]] ctrl imagetype lrflags imageid [user_var(imagehandle)]
Loads and sets a image on a static control. \cw{ctrl} is the handle of the control. \cw{imagetype} must 0 for bitmaps and 1 for icons (and the control style must match the image type). \cw{lrflags} should be 0x10 to load from a file or 0 to load from a resource. \cw{image} specifies the file path or resource name. Use \cw{/EXERESOURCE} to load a resource from the installer .EXE. Use \cw{/STRINGID} if \cw{image} is a string, otherwise it is interpreted as a number. Use \cw{/RESIZETOFIT[WIDTH|HEIGHT]} to resize the image to the dimensions of the control.
Loads and sets a image on a static control. \cw{ctrl} is the handle of the control. \cw{imagetype} must 0 for bitmaps and 1 for icons (and the control style must match the image type). \cw{lrflags} should be 0x10 to load from a file or 0 to load from a resource. \cw{imageid} specifies the file path or resource name. Use \cw{/EXERESOURCE} to load a resource from the installer .EXE. Use \cw{/STRINGID} if \cw{imageid} is a string, otherwise it is interpreted as a number. Use \cw{/RESIZETOFIT[WIDTH|HEIGHT]} to resize the image to the dimensions of the control. \cw{imagehandle} can optionally recieve the handle of the loaded image.
Images loaded on individual pages should be destroyed to minimize resource leaks. If images are loaded into the same control multiple times, the previous image will only be destroyed if it is a bitmap image. Previous icons and 32-bit ARGB bitmaps must be retrieved with \cw{STM_GETIMAGE} and destroyed.
\c LoadAndSetImage /EXERESOURCE $hIconStatic 1 0 103
\c LoadAndSetImage /STRINGID /RESIZETOFITWIDTH $hBmpStatic 0 0x10 "$PluginsDir\myimg.bmp"
@ -109,7 +111,7 @@ Overrides the default auto window-closing flag (specified for the installer usin
\c [/IMGID=item_id_in_dialog] [/RESIZETOFIT] path_to_bitmap_file.bmp
Sets the current bitmap file displayed as the branding image. If no IMGID is specified, the first image control found will be used, or the image control created by \R{aaddbrandingimage}{AddBrandingImage}. Note that this bitmap must be present on the user's machine. Use File first to put it there. If /RESIZETOFIT is specified the image will be automatically resized (very poorly) to the image control size. If you used \R{aaddbrandingimage}{AddBrandingImage} you can get this size by compiling your script and watching for \R{aaddbrandingimage}{AddBrandingImage} output, it will tell you the size. SetBrandingImage will not work when called from .onInit!
Sets the current bitmap file displayed as the branding image. If no IMGID is specified, the first image control found will be used, or the image control created by \R{aaddbrandingimage}{AddBrandingImage}. Note that this bitmap must be present on the user's machine. Use \cw{File} first to put it there. If /RESIZETOFIT is specified the image will be automatically resized (very poorly) to the image control size. If you used \R{aaddbrandingimage}{AddBrandingImage} you can get this size by compiling your script and watching for \R{aaddbrandingimage}{AddBrandingImage} output, it will tell you the size. SetBrandingImage will not work when called from .onInit!
\S2{setdetailsview} SetDetailsView

View file

@ -61,7 +61,7 @@
// 5000..5999 Important generic warnings
// 6000..6999 Script warnings
// 7000..7499 Recovered from bad input etc. warnings
// 7500..7999 Discouraged usage warnings (allocated top to bottom to reserve as much space as possible for more bad input codes)
// 7500..7999 Discouraged usage warnings (allocated high to low to reserve as much space as possible for more bad input codes)
// 8000..8999 Generic warnings
// 9000..9999 Breaking our and/or MS guidelines warnings
typedef enum {
@ -107,6 +107,7 @@ typedef enum {
DW_LICENSE_EMPTY = 7050,
DW_ATTRIBUTE_OVERLONGSTRING = 7060,
DW_PARSE_BADNUMBER = 7070,
DW_PARSE_NUMBEROUTOFSPEC = 7071,
DW_PARSE_LNK_HK = 7075,
DW_GENERIC_DEPRECATED = 7998,
DW_PARSE_REGPATHPREFIX = 7999,

View file

@ -843,14 +843,15 @@ static int NSISCALL ExecuteEntry(entry *entry_)
case EW_LOADANDSETIMAGE:
{
RECT r;
HANDLE hImage;
HWND hCtl=(parm2 & LASIF_HWND) ? GetHwndFromParm(1) : GetDlgItem(g_hwnd, parm1);
UINT it=parm2 & LASIM_IMAGE, exeres=parm2 & LASIF_EXERES, fitw=(UINT)parm2 >> LASIS_FITCTLW, fith=(parm2 & LASIF_FITCTLH) != 0;
LPCTSTR imgname = (parm2 & LASIF_STRID) ? GetStringFromParm(0x00) : MAKEINTRESOURCE(parm0);
HANDLE hNewImage, hPrevImage;
HWND hCtl=(parm3 & LASIF_HWND) ? GetHwndFromParm(2) : GetDlgItem(g_hwnd, parm2);
UINT it=parm3 & LASIM_IMAGE, exeres=parm3 & LASIF_EXERES, fitw=(UINT)parm3 >> LASIS_FITCTLW, fith=(parm3 & LASIF_FITCTLH) != 0;
LPCTSTR imgid = (parm3 & LASIF_STRID) ? GetStringFromParm(0x11) : MAKEINTRESOURCE(parm1);
GetClientRect(hCtl, &r);
hImage=LoadImage(exeres ? g_hInstance : NULL, imgname, it, fitw*r.right, fith*r.bottom, parm2 & LASIM_LR);
hImage=(HANDLE)SendMessage(hCtl, STM_SETIMAGE, it, (LPARAM)hImage);
if (hImage && IMAGE_BITMAP == it) DeleteObject(hImage); // Delete the old image
hNewImage=LoadImage(exeres ? g_hInstance : NULL, imgid, it, fitw*r.right, fith*r.bottom, parm3 & LASIM_LR);
hPrevImage=(HANDLE)SendMessage(hCtl, STM_SETIMAGE, it, (LPARAM)hNewImage);
if (hPrevImage && IMAGE_BITMAP == it) DeleteObject(hPrevImage); // Delete the old bitmap
if (parm0 >=0) iptrtostr(var0, (INT_PTR)hNewImage); // Optional output handle
}
break;
case EW_CREATEFONT:

View file

@ -112,7 +112,7 @@ enum
#ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
EW_GETDLGITEM, // GetDlgItem: 3: [outputvar, dialog, item_id]
EW_SETCTLCOLORS, // SerCtlColors: 3: [hwnd, pointer to struct colors]
EW_LOADANDSETIMAGE, // SetBrandingImage/LoadAndSetImage: 3: [imgid ctl flags]
EW_LOADANDSETIMAGE, // SetBrandingImage/LoadAndSetImage: 5: [ctrl imagetype lrflags imageid [output]]
EW_CREATEFONT, // CreateFont: 5: [handle output, face name, height, weight, flags]
EW_SHOWWINDOW, // ShowWindow: 2: [hwnd, show state]
#endif

View file

@ -4913,10 +4913,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return add_entry(&ent);
case TOK_LOADANDSETIMAGE:
{
SCRIPT_MSG(_T("LoadAndSetImage: "));
ent.which=EW_LOADANDSETIMAGE;
int tidx = 1, conv = 1, fail = 0;
unsigned int flags = LASIF_HWND;
unsigned int flags = LASIF_HWND, lrflagsin;
for (; tidx < line.getnumtokens(); tidx++)
{
if (!_tcsicmp(line.gettoken_str(tidx),_T("/EXERESOURCE"))) flags |= LASIF_EXERES;
@ -4927,12 +4926,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
else if (!_tcsicmp(line.gettoken_str(tidx),_T("/GETDLGITEM"))) flags &= ~LASIF_HWND; // Reuses TOK_SETBRANDINGIMAGE functionality
else { if (line.gettoken_str(tidx)[0] == '/') ++fail; break; }
}
ent.offsets[1]=(flags & LASIF_HWND) ? add_string(line.gettoken_str(tidx+0)) : line.gettoken_int(tidx+0, &conv); fail += !conv; // HWND/CtrlId
flags |= (line.gettoken_int(tidx+1, &conv) & LASIM_IMAGE); fail += !conv;
flags |= (line.gettoken_int(tidx+2, &conv) & LASIM_LR); fail += !conv;
ent.offsets[0]=(flags & LASIF_STRID) ? add_string(line.gettoken_str(tidx+3)) : line.gettoken_int(tidx+3, &conv); fail += !conv; // Image path/resid
ent.offsets[2]=flags;
SCRIPT_MSG(_T("%") NPRIs _T(" %#x \"%") NPRIs _T("\" \n"), line.gettoken_str(tidx+0), flags, line.gettoken_str(tidx+3));
ent.offsets[2] = (flags & LASIF_HWND) ? add_string(line.gettoken_str(tidx+0)) : line.gettoken_int(tidx+0, &conv); fail |= !conv; // HWND/CtrlId
flags |= (line.gettoken_int(tidx+1, &conv) & LASIM_IMAGE); fail |= !conv; // IMAGE_*
flags |= ((lrflagsin = line.gettoken_int(tidx+2, &conv)) & LASIM_LR); fail |= !conv; // LR_*
ent.offsets[1] = (flags & LASIF_STRID) ? add_string(line.gettoken_str(tidx+3)) : line.gettoken_int(tidx+3, &conv); fail |= !conv; // Image path/resid
ent.offsets[3] = flags; // Packed flags, IMAGE_* and LR_*
ent.offsets[0] = GetUserVarIndex(line, tidx+4); // Outvar
SCRIPT_MSG(_T("LoadAndSetImage %") NPRIs _T(" %#x \"%") NPRIs _T("\""), line.gettoken_str(tidx+0), flags, line.gettoken_str(tidx+3));
if (ent.offsets[0] >= 0) SCRIPT_MSG(_T(" -> %") NPRIs _T(""), line.gettoken_str(tidx+4));
SCRIPT_MSG(_T("\n"));
if ((lrflagsin & LASIM_LR) != lrflagsin) warning_fl(DW_PARSE_NUMBEROUTOFSPEC, _T("Out of spec: \"%") NPRIs _T("\""), line.gettoken_str(tidx+2));
if (fail) PRINTHELP();
}
return add_entry(&ent);
@ -4941,7 +4944,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
case TOK_LOADANDSETIMAGE:
ERROR_MSG(_T("Error: %") NPRIs _T(" specified, NSIS_CONFIG_ENHANCEDUI_SUPPORT not defined.\n"),line.gettoken_str(0));
return PS_ERROR;
#endif //~ NSIS_SUPPORT_CREATEFONT
#endif //~ NSIS_CONFIG_ENHANCEDUI_SUPPORT
case TOK_DEFVAR:
{
int a=1;

View file

@ -196,7 +196,7 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_SETAUTOCLOSE,_T("SetAutoClose"),1,0,_T("(false|true)"),TP_CODE},
{TOK_SETCTLCOLORS,_T("SetCtlColors"),2,2,_T("hwnd [/BRANDING] [text_color] [transparent|bg_color]"),TP_CODE},
{TOK_SETBRANDINGIMAGE,_T("SetBrandingImage"),1,2,_T("[/IMGID=image_item_id_in_dialog] [/RESIZETOFIT] bitmap.bmp"),TP_CODE},
{TOK_LOADANDSETIMAGE,_T("LoadAndSetImage"),4,4,_T("[/EXERESOURCE] [/STRINGID] [/RESIZETOFIT[WIDTH|HEIGHT]] ctrl imagetype lrflags image"),TP_CODE},
{TOK_LOADANDSETIMAGE,_T("LoadAndSetImage"),4,5,_T("[/EXERESOURCE] [/STRINGID] [/RESIZETOFIT[WIDTH|HEIGHT]] ctrl imagetype lrflags imageid [$(user_var: imagehandle)]"),TP_CODE},
{TOK_SETCOMPRESS,_T("SetCompress"),1,0,_T("(off|auto|force)"),TP_ALL},
{TOK_SETCOMPRESSOR,_T("SetCompressor"),1,2,_T("[/FINAL] [/SOLID] (zlib|bzip2|lzma)"),TP_GLOBAL},
{TOK_SETCOMPRESSORDICTSIZE,_T("SetCompressorDictSize"),1,0,_T("dict_size_mb"),TP_ALL},