Archive: nsDialogs - resizetofit


nsDialogs - resizetofit
  Hi,
I've converted some of my pages to nsDialogs. If you look at the examples and have the patience too, it really is good for customizing layouts.:)

What is the correct way to set bitmap size in an nsDialogs function?

nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${SS_BITMAP} 0 0 0 109u 193u "" 
When you change the size, use pixels (p) or percent (%) or units (u), nothing happens.
System::Call 'user32::LoadImage(i 0, t r0, i ${IMAGE_BITMAP}, i 164, i 314, i ${LR_LOADFROMFILE}) i.s' 
Width and height are in pixels. Relative dimensions (percent, units) are not possible. Is there a way to apply "resizetofit"? (For DPI settings that stretch the installer?)

You can manually retrieve the size of the new control and use the coordinates in LoadImage. That's what InstallOptions does when you the RESIZETOFIT flag. I'll have to add a macro for that in nsDialogs.nsh.

System::Alloc 16
System::Call user32::GetClientRect(i $HWND, isr0)
System::Call *$0(i,i,i.r1,i.r2)
System::Free $0
# $1 and $2 are now width and height

I got the gist of it I think, but, say, $IMAGECTL is the new control and is 331u 193u or 497p 314p ... when I insert $1 and $2 in LoadImage, the effect is the same as 0 and 0; that is, the image displays at the original bitmap size, which is not 497x314 pixels (or there would no point in the experiment). The System::Call code is pasted between the new control and LoadImage in the function.

A macro of course would solve it. I can wait that long -- it's not urgent -- and deal with this then, if you want, seeing as nsDialogs is under development.


A macro would probably contain the above code. So we'd need to debug a bit, if it doesn't work. Do $1 and $2 contain any meaningful values?


I thought you retrieve the size from the control. I used units or pixels.


  nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${SS_BITMAP} 0 0 0 497p 314p ""

Pop $IMAGECTL
System
::Alloc 16
System::Call user32::GetClientRect(i $IMAGECTL, isr0)
System::Call *$0(i,i,i.r1,i.r2)
System::Free $0
; $1 and $2 are now width and height
StrCpy$0 $PLUGINSDIRmodern-wizard.bmp
System::Call 'user32::LoadImage(i 0, t r0, i ${IMAGE_BITMAP}, i $1, i $2, i ${LR_LOADFROMFILE}) i.s'
Pop $IMAGE
SendMessage $IMAGECTL${STM_SETIMAGE} ${IMAGE_BITMAP} $IMAGE
>
So the values are those of the control?

$1 and $2 should be the pixel width of the control after the call to GetClientRect. What you've used to create the control in the first place shouldn't matter as that's only for an internal conversion of nsDialogs.


At the moment $1 and $2 have the values 0 and 0. I'm not sure I understand how GetClientRect is supposed to work. Where do the values come from if not from the control?


The values come from the control, but the units used by nsDialogs don't matter as it's all converted to pixels eventually.

The problem with the code is missing quotes in the call to GetClientRect.

System::Call "user32::GetClientRect(i $IMAGECTL, isr0)"

Congrats! That did it, pixels, units, or whatever. Thanks! Missing quotes, the usual culprit.:)


A macro of course would solve it. I can wait that long -- it's not urgent -- and deal with this then, if you want, seeing as nsDialogs is under development.
I didn't mean to suggest it wasn't worth fixing. That was rude. Sorry.:hang:

I didn't think for a second you were suggesting that.


I've added ${NSD_SetStretchedImage} for 2.36.