Archive: LoadBitmap Problem


LoadBitmap Problem
what i want to do:
assign a custom bitmap to a static bitmap control on runtime, by loading it from any path.

what's the problem:
don't know the right usage for LoadImage / the correct values for IMAGE_BITMAP and LR_LOADFROMFILE params.

[LoadPicture gives me error 1814 (Ressource not found in specified file), seems not to fit for this job]

attached a full example script (you may take your own bitmap!) with custom page.

plz have a look.


1. Bitmap load is correct, but first of all you need valid control handle. To get [Field 1] use


FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $ctrlhandle $0 1200

This works in my home 2.08, may be later versions put handle to INI file...
2. Might be better to set Top and Left coordinates of control and not set Right and Bottom in the INI file. MSDN: "SS_BITMAP The style ignores the nWidth and nHeight parameters; the control automatically sizes itself to accommodate the bitmap."

1. you can indeed ommit that, as with latest installoptions the handle of the control is written to the ini file as HWND/HWND2 setting for each field.

2. well, installoptions wont work without those settings :)
the control will resize no matter what you tell it by the ini file.

but thanx for your testing.


seems not to work :(


ReadINIStr $0 "$PLUGINSDIR\test3.ini" "Field 1" "HWND"
System::Call "user32::LoadBitmap (i r0, t '$PLUGINSDIR\test3.bmp') i .r1"
SendMessage $0 0x0172 "" "$1"
SendMessage $0 0x000F "" ""

MessageBox MB_OK "$0, $1"

messagebox says: <some number>,error

The LoadBitmap function loads the specified bitmap resource from a module's executable file.
You cannot use it to load a bitmap from a .bmp file. For this, you must use LoadImage with the LR_LOADFROMFILE flag.

See the following for an example:

http://nsis.sourceforge.net/ModernUI...stalling_files

well, that was exactly what i ment and read from msdn, but takhir made me think otherwise...

and regarding LR_LOADFROMFILE ... read my first post, i thought using this one at first ... :)

anyway, thanx for the link, thats the solution! :)


2 Comm@nder21: First of all I tested test3 with LoadImage() sample you included to zip and it worked (with my corrections for 2.08) both with 2 and 1 images (download or replace on Cancel click, I added second image and defined it in INI). This worked fine without Right and Bottom definitions in INI, but if these parameters were defined I found wrong position (and probably size) of bitmap/static control. And WM_PAINT usage in your script is wrong and not required.


INI and NSI with my corrections
Files attached. Image appeares on Cancel click.


I remember EBanner plug-in I wrote last year :), it scales image and supports more formats (including png). Sample script attached (1 line to show image, but 'stop' call required at the end to remove it).


well, i found a much easier way once i had a look into MUI's system.nsh. :)

from NSIS Docs:

4.9.14.12 SetBrandingImage
[/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 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 AddBrandingImage you can get this size, by compiling your script and watching for AddBrandingImage output, it will tell you the size. SetBrandingImage will not work when called from .onInit!
now as you may set any control id, this should work for every kind of loading bitmaps :)

I tested AddBrandingImage some time ago, but big picture appeared on the HWNDPARENT field and was visible partly only. And I not continued with this option :) Good sample in Manual might be very usefull.
BTW thanks for idea, I added 'partly known' window class name option to my find-close-terminate plug-in.