Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

resizing a picture in a gui


  • Please log in to reply
8 replies to this topic
Bartimus
  • Members
  • 237 posts
  • Last active: Nov 10 2016 05:01 PM
  • Joined: 10 Nov 2005

Okay... I tried looking up on how to do this in the forum, but nothing I found with GuiControl, Move quite addressed my needs.

 

What I want to do is take a picture control and resize the image like it's a progress bar.  Yes, I know there are progress bar controls in AHK, but I wanted to get creative wink.png

 

I'm actually trying to use an animated GIFs, but not sure if the function is getting in the way.  So for testin purpose, I took one of the other images to see if I could resize it and found I couldn't.

 

If anyone could help, I'd greatly appreciate it.  grin.png

 

So here's the main code (and it's not cleaned up any and the tabs are for easy readability in my editor):

GUIWidth := 640

Loop, 7
{
	hGui := WinExist()
	Gui, %A_Index%: Color, 000011
	If ( A_Index != 1 )
		Gui, %A_Index%: +LastFound -Caption +ToolWindow +Owner 1
	else
		Gui, %A_Index%: +LastFound -Caption +ToolWindow 
}

Gui, 1: Add, Picture,Transparent	w%GUIWidth%		h-1		x0		y0			, LauncherUI-L3.png
;~ Gui, 1: Add, Picture,	Transparent	w%GUIWidth%		h-1		x0		y0			, LauncherUI-L1.png
;~ Gui, 2: Add, Picture,	Transparent	w%GUIWidth%		h-1		x0		y0			, LauncherUI-L2.png

Gui, 4: Font, cWhite s12, Verdana 
Gui, 4: Add, Picture,	Transparent		w160		h160	x10		y10			, Logo.png
Gui, 4: Add, Text,		Transparent							x180	y10			, LauncherUI:
Gui, 4: Add, Text,		Transparent							xp		y30			, Setting up ....
Gui, 4: Add, Text,		Transparent							xp		y130		, Actions:
Gui, 4: Font, cGray s9, Tahoma 
Gui, 4: Add, ListBox,	Transparent		w450		r5		xp		yp+20		vColorChoice, Red|Green|Blue|Black|White
Gui, 4: Font, cWhite s12, Verdana 
Gui, 4: Add, Text,		Transparent							x21		y237		, Progress of Actions:
;~ AnimatedGifControl("5", A_ScriptDir . "\Bar-02.gif",  "y255 x21 w550 h23 bgc777700", "ProgA")
AnimatedGifControl("5", A_ScriptDir . "\Bar-02.gif",  "y280 x21 w110 h23 bgc007777", "ProgB")
Gui, 5: Add, Picture,	Transparent	w-1	 			y170 x21 w110 h23		vProgA, LauncherUI-L4.png
Gui, 6: Add, Picture,	Transparent	w-1	 			h25		x10		y255 		, LauncherUI-L4.png
Gui, 6: Add, Picture,	Transparent	w-1	 			h25	 	x10		y280		, LauncherUI-L4.png
;~ Gui, 7: Add, Picture,	Transparent	w%GUIWidth%		h-1		x0		y0		hwndhText12	, LauncherUI-L3.png


Loop, 7
{
	Gui, %A_Index%: Show,w640 h320
	Gui, %A_Index%: +LastFound
	hGui := WinExist()
	WinSet, Redraw,, ahk_id %hGui%
	WinSet, TransColor, 000011
	Sleep, 500
}
LongProg :=

TotalFiles := 5
FileSize := 128

Loop, %TotalFiles%
{
	Loop, %FileSize%
	{
		ShortProg := 110 + ( A_Index / FileSize  * 440 )
		GuiControl, Move, ProgA, w%ShortProg%
		TrayTip,,ShortProg = %ShortProg%`nLongProg  = %LongProg%
		Sleep, 1
	}
	
	LongProg := 110 + ( A_Index / TotalFiles  * 440 )
	GuiControl, Move, ProgB, w%LongProg%
	Sleep, 100
}

MsgBox, done
Return

#Include, AnimatedGifControl_2.ahk

Here's the "AnimatedGifControl_2.ahk" include (slightly modified from the original found elsewhere in the forums):

AnimatedGifControl(GuiNameOrHwnd, GifFilePath, ControlOptions="", hCntL="ProgZ") {
	Static
	Static CallCount := 0
	Local pos, ObjectName, bgColor
	; Create a variable name for ActiveX Object 
	ObjectName := "WB" ++CallCount
	
	; Retrieve the given image dimenstions
	AnimatedGifControl_GetImageDimensions(GifFilePath, GifWidth, GifHeight)
	if RegExMatch(ControlOptions, "O)(\s|^)(w(\d+))(\s|$)", oM) {
		GifWidth := oM.Value(3)
		StringReplace, ControlOptions, ControlOptions, % oM.Value(2),		; Remove the found option
	}
	if pos := RegExMatch(ControlOptions, "O)(\s|^)(h(\d+))(\s|$)", oM) {
		GifHeight := oM.Value(3)
		StringReplace, ControlOptions, ControlOptions, % oM.Value(2),		; Remove the found option
	}
	; Retrieve the background color option
	if RegExMatch(ControlOptions, "O)(\s|^)(bgc(\w{6}))(\s|$)", oM) {
		bgColor := oM.Value(3)
		StringReplace, ControlOptions, ControlOptions, % oM.Value(2),		; Remove the found option
	} else 
		bgColor := AnimatedGifControl_GetSysColor(15) ;COLOR_3DFACE :Face color for three-dimensional display elements and for dialog box backgrounds.

	; Add the Gif Animation Control
	Gui, %GuiNameOrHwnd%: Add, ActiveX, v%hCntL% v%ObjectName% w%GifWidth% h%GifHeight% Disabled %ControlOptions% Transparent, Shell.Explorer ;Mozilla.Browser
	;~ Gui, %GuiNameOrHwnd%: Add, ActiveX, % "hwndhText" HwndhCntL "v" ObjectName " w" GifWidth " h" GifHeight " Disabled " ControlOptions, Shell.Explorer ;Mozilla.Browser

	%ObjectName%.Navigate("about:blank")
	;How Do you Stretch a Background Image in a Web Page
	;http://webdesign.about.com/od/css3/f/blfaqbgsize.htm	
	%ObjectName%.Document.Write("
	(Ltrim
		<html>
		<header>
			<style type='text/css'>
				img#bg {
					position:fixed;
					top:0;
					left:0;
					width:100%;
					height:100%;
				} 
			</style>
			<!--[if IE 6]>
			<![endif]-->
			<!--[if IE 6]>
				<style type='text/css'>
				html { overflow-y: hidden; }
				body { overflow-y: hidden; }
				img#bg { position:absolute; z-index:-1; }
				#content { position:static; }
				</style>
			<![endif]--> 			
		</header>
		<body style='height: 100%; width: 100%; margin: 0; padding: 0; overflow-x: hidden; overflow-y: hidden; background-color: #" bgColor ";' />
		<img src='" GifFilePath "' id='bg'  />
		</body>
		</html>
	)")

	%ObjectName%.Document.close
	%ObjectName% := ""	;release the object
	Return
}
AnimatedGifControl_GetImageDimensions(ImgPath, Byref width, Byref height) {
	DHW := A_DetectHiddenWIndows
	DetectHiddenWindows, ON
	Gui, AnimatedGifControl_GetImageDimensions: Add, Picture, hwndhWndImage, % ImgPath
	GuiControlGet, Image, AnimatedGifControl_GetImageDimensions:Pos, % hWndImage
	Gui, AnimatedGifControl_GetImageDimensions: Destroy
	DetectHiddenWindows, % DHW
	width := ImageW, 	height := ImageH
}

AnimatedGifControl_GetSysColor(d_element) {
	;Thanks SKAN ;http://www.autohotkey.com/forum/post-66521.html#66521
	A_FI:=A_FormatInteger
	SetFormat, Integer, Hex
	BGR:=DllCall("GetSysColor"
	 ,Int,d_element)+0x1000000
	SetFormat,Integer,%A_FI%
	StringMid,R,BGR,8,2
	StringMid,G,BGR,6,2
	StringMid,B,BGR,4,2
	RGB := R G B
	StringUpper,RGB,RGB
	Return RGB
}

/*
	by A_Samurai 
	2012/01/25 version 1.0.5
		Added:
			- background color option: bgcNNNNNN where Ns is 6-digit RGB color value.
	2012/01/24 version 1.0.4
		Added:
			- image resize support
	2012/01/22 version 1.0.3
		Removed:
			- the ObjectName parameter
	2012/01/22 version 1.0.2
		Fixed:
			- a bug that does not retrieve image dimensions properly.
	2012/01/22 version 1.0.1
		Fixed:
			- to use IE components from Firefox.
		Changed:
			- to allow wN and hN options.
	2012/01/22 version 1.0.0
	
	Licence: Public Domain
*/

... again, thanks



just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

Sorry, nonsense!


Prefer ahkscript.org for the time being.


Bartimus
  • Members
  • 237 posts
  • Last active: Nov 10 2016 05:01 PM
  • Joined: 10 Nov 2005

Sorry, nonsense!

 

nonsense?  please explain.



Bartimus
  • Members
  • 237 posts
  • Last active: Nov 10 2016 05:01 PM
  • Joined: 10 Nov 2005

I'm guessing this can't be done?



dangerdogL2121
  • Members
  • 636 posts
  • Last active: Nov 19 2015 03:39 AM
  • Joined: 22 Dec 2012

You've probably already seen this:

Gui, +Resize
Gui, Add, Button, default, &Load New Image
Gui, Add, Radio, ym+5 x+10 vRadio checked, Load &actual size
Gui, Add, Radio, ym+5 x+10, Load to &fit screen
Gui, Add, Pic, xm vPic
Gui, Show
return

ButtonLoadNewImage:
FileSelectFile, file,,, Select an image:, Images (*.gif; *.jpg; *.bmp; *.png; *.tif; *.ico; *.cur; *.ani; *.exe; *.dll)
if file =
    return
Gui, Submit, NoHide ; Save the values of the radio buttons.
if Radio = 1  ; Display image at its actual size.
{
    Width = 0
    Height = 0
}
else ; Second radio is selected: Resize the image to fit the screen.
{
    Width := A_ScreenWidth - 28  ; Minus 28 to allow room for borders and margins inside.
    Height = -1  ; "Keep aspect ratio" seems best.
}
GuiControl,, Pic, *w%width% *h%height% %file%  ; Load the image.
Gui, Show, xCenter y0 AutoSize, %file%  ; Resize the window to match the picture size.
return

GuiClose:
ExitApp

There is a new AutoHotkey forum here.


Puzzled Greatly
  • Members
  • 612 posts
  • Last active: May 22 2017 11:15 PM
  • Joined: 15 Aug 2009
Why would you want to use an image as a progress? Surely that would mean stretching the image out of proportion? I suppose you could duplicate the image over time and place one next to the other...

rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011
I think the problem here is that your question isn't very clear.

My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


Bartimus
  • Members
  • 237 posts
  • Last active: Nov 10 2016 05:01 PM
  • Joined: 10 Nov 2005

I think the problem here is that your question isn't very clear.

Okay... let me try to clarify...  I want to take an image and move (or resize) it behind another image, much like this:
button.gif

I can't seem to accomplish this in my script and am hoping somebody can tell me what I've done wrong.  I can't resize or move any picture element regardless of the filetype.

 

Why would you want to use an image as a progress? Surely that would mean stretching the image out of proportion? I suppose you could duplicate the image over time and place one next to the other...

I just want to add a little creativity to a universal loader script that has a pair of progress bars.  I know it's "over the top" unnecessary, but I figure why not challenge myself and make something look nice at the same time.  I'm not too concerned about the stretching factor.  Might add to the fun.  Or if I can move the bar behind another picture element and just move it.

 

 

You've probably already seen this:

Gui, +Resize
....

I saw something similar to this that actually resized the picture contents when I resized the open window, but is not what I'm looking for.  Thanks though



just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

The "nonsense" above is related to my withdrawn answer.

 

Here are two hopefully better answers:

 

Spoiler

Prefer ahkscript.org for the time being.