[Solved] I've to RTFM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

[Solved] I've to RTFM

20 Jul 2017, 17:11

WISH:
GuiControl,,,HBITMAP:%hBM% and Gui, Add, Picture,, HBITMAP:%hBM% should not stretch-to-fit the image when SS_CENTERIMAGE flag is in effect

If a 1000x1000 image is applied to a w100 h100 picture control then only the center 100² pixels should be displayed...
This is the default behaviour SS_CENTERIMAGE flag is in effect.
This wasn't important when Filename was used to create a picture control. Now that we have
HBITMAP: parameter as well as a LoadPicture() function, it is possible to find the dimensions
and scale down the image to perfectly fit the picture control.
I will post a working demo and link it here.

Meanwhile, here are snippets to show the problem.

Image

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir %A_ScriptDir% 

IfNotExist, logo.png
URLDownloadToFile, https://autohotkey.com/assets/images/ahk-logo-no-text241x78-180.png, logo.png
hBM := LoadPicture( "logo.png" ) 

OPTIONS := ( SS_CENTERIMAGE := 0x200 )
Gui, Add, Picture, w400 h200 %OPTIONS% vPicture
GuiControl,, Picture, HBITMAP:%hbm%
Gui, Show,, SS_CENTERIMAGE is ignored by GuiControl
Return

GuiClose:
GuiEscape:
 ExitApp
Image

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir %A_ScriptDir% 

IfNotExist, logo.png
URLDownloadToFile, https://autohotkey.com/assets/images/ahk-logo-no-text241x78-180.png, logo.png

hBM := LoadPicture( "logo.png" ) 

OPTIONS := ( SS_BITMAP := 0xE ) | ( SS_CENTERIMAGE := 0x200 )
Gui, Add, Picture, w400 h200 %OPTIONS% vPicture hwndhwndPic Border
oBM := DllCall( "SendMessage", "Ptr",hwndPic, "UInt",0x172, "Ptr",0, "Ptr",hBM ) ; STM_SETIMAGE = 0x172
Gui, Show,, Workaround with STM_SETIMAGE
Return

GuiClose:
GuiEscape:
 ExitApp
My Scripts and Functions: V1  V2
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Picture control: Image shouldn't be stretched-to-fit when SS_CENTERIMAGE flag is in effect

20 Jul 2017, 17:48

Hello.
GuiControl wrote:Specify *w0 *h0to use the image's actual width and height.

Edit:
SKAN wrote:Is it alright with you if I delete this useless topic?
I do not mind.
Last edited by Helgef on 21 Jul 2017, 02:03, edited 1 time in total.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Picture control: Image shouldn't be stretched-to-fit when SS_CENTERIMAGE flag is in effect

20 Jul 2017, 18:56

Helgef wrote:Hello.
GuiControl wrote:Specify *w0 *h0to use the image's actual width and height.
Woah! Thanks Helgef!
Is it alright with you if I delete this useless topic?
My Scripts and Functions: V1  V2

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 237 guests