Bild ändern

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

Optimus Prime
Posts: 69
Joined: 04 Feb 2020, 02:47

Bild ändern

18 Aug 2021, 15:30

Hallo Zusammen,

ich würde gerne eine Reihe von Bildern in ein Fenster laden und diese als Steuerlemente gezielt im Vordergrund darstellen.
Gibt es einen Befehl dafür?

Code: Select all

Gui, Show, x127 y87 h442 w1056, Test


Gui, Add, Picture, x1 y-1 w1050 h440 , C:\Users\admin\Documents\Bild 01.png
Gui, Add, Picture, x1 y-1 w1050 h440 , C:\Users\admin\Documents\Bild 02.png
Gui, Add, Picture, x1 y-1 w1050 h440 , C:\Users\admin\Documents\Bild 03.png
Gui, Add, Picture, x1 y-1 w1050 h440 , C:\Users\admin\Documents\Bild 04.png
Gui, Add, Picture, x1 y-1 w1050 h440 , C:\Users\admin\Documents\Bild 05.png
Gui, Add, Picture, x1 y-1 w1050 h440 , C:\Users\admin\Documents\Bild 06.png


Sleep, 5000

; Hier müsste zum Beispiel Bild 5 im Vordergrund erscheinen

Sleep, 5000

;Hier müsste ein weiteres Bild in den Vordergund wandern.


return



GuiClose:
ExitApp
Die reinste Form des Wahnsinns ist es, alles so zu belassen wie es ist und zu hoffen, dass sich etwas ändert [Albert Einstein]
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Bild ändern

19 Aug 2021, 01:37

hier nur ein Beispiel , zeigt Bilder von einem Ordner , z.B. für 3 Sekunden oder benütze SPACE-Taste

Code: Select all

;-----------------------------------
#warn
setworkingdir,%a_scriptdir%
SetBatchLines, -1

;------ your variables -------------
mf=D:\m_media\m_foto                   ;- <<<< your PATH here
extensions :="jpg,bmp,png"
seconds    := 3
;-----------------------------------
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
e:=""
seconds:=(seconds*1000)
x:=(wa*16)/xx , y:=(ha*.1)/xx , w:=(wa*67)/xx,  h:=(ha*95)/xx
Gui,2:default
Gui,2: +HwndAId  +0x2000000
Gui,2: -DPIScale
Gui,2: +AlwaysOnTop -Caption
Gui,2: Margin, 0, 0
Gui,2:Color,Black,Black
loop,%mf%\*.*,0,1
  {
  SplitPath,a_loopfilefullpath, name, dir, ext, name_no_ext, drive
  if ext in %extensions%
    e .= a_loopfilefullpath . "`r`n"
  }
gui,2: show ,x%x% y%y% w%w%,Test1
if e=
{
msgbox, 262208,FILES ,No pictures found`nDefine your pictures-folder in this script
exitapp
}
Loop,parse,e,`n,`r
{
xc:=a_loopfield
if xc=
  continue
gosub,childnew1
}
return
;---------------------
esc::
2Guiclose:
Gui,3:destroy
sleep,1000
exitapp
;---------------------
childnew1:
Gui,2:submit,nohide
Gui,3:default
imgSize(x,imgw,imgh)
Gui,3: -DPIScale
Gui,3: +AlwaysOnTop -Caption
Gui,3: Margin, 0, 0
Gui,3: +HwndBId  -Caption -Border
Gui,3: Color,Black,Black
if (imgw>imgh)
  gui,3:add, Picture, x0 y0 h-1 w%w%,%xc%
else
  gui,3:add, Picture, x0 y0 h%h% w-1 ,%xc%
Gui,3:Show,x0 y0  ,Test2
WinGetPos,,,Width2,Height2,Test2
Gui,3:+Parent%AId%
Winmove,,Test2,,,,%height2%
sleep,%seconds%
;keywait,space,D                      ;- <<< instead sleep seconds use SPACE-key to continue
Gui,3:destroy
return
;------------------------------------
imgSize(img, ByRef width , ByRef height) { ; Get image's dimensions
 If FileExist(img) {
  GUI, Add, Picture, hwndpic, %img%
  ControlGetPos,,, width, height,, ahk_id %pic%
  Gui, Destroy
 } Else height := width := 0
}
;=============== END SCRIPT Foto Slide-Show ============
Optimus Prime
Posts: 69
Joined: 04 Feb 2020, 02:47

Re: Bild ändern

19 Aug 2021, 13:43

Hi Garry, danke für diese Information.
Es geht bei der Idee jedoch nicht um einen Bildwechsel.
Ich will versuchen einen "Menu-Pie" umzusetzen. Final soll duch einen Mousover gewährleistet werden,
dass sich das gesamte Hintergundbild ändert und der gerade vom Cursor berührte Button farblich hervorgehoben wird.
Verlässt man den Bereich des Buttons wird das ursprüngliche Bild hergestellt.
Deshalb muss sich das Bild im Fenster komplett ändern.
Hast du eine Idee / Herangehensweise?
Last but not least soll dann auch noch durch das anklicken der eigens grafisch konstruierten Buttons eine Aktion ausgeführt werden.
Angehängt ist der Pie mit einer hervorgehobenen Fläche.
Gruß
grafik.png
grafik.png (35.02 KiB) Viewed 719 times
[attachment=0]
Die reinste Form des Wahnsinns ist es, alles so zu belassen wie es ist und zu hoffen, dass sich etwas ändert [Albert Einstein]
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Bild ändern

19 Aug 2021, 14:09

Ich habe da keine Erfahrung
hier lediglich ein bestehendes Bild in GUI angefügt , besteht Möglichkeit auf eine bestimte Position zu klicken und eine Aktion zu starten
( d.h. man könnte Dein Bild brauchen aber die Farbe ändert sich nicht )
Test mit 4K Monitor , Positionen sind prozentual berechnet, funktioniert's mit anderen Auflösungen ?
Fontsize müsste noch berücksichtigt werden

Code: Select all

;- click on first picture with 4 buttons & 2nd color button
#warn
setworkingdir,%a_scriptdir%
CoordMode, Mouse , Relative
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100  ;- 4k= 3840*2160
filename1=TEST CLICK PICTURE-BUTTON
url=https://i.imgur.com/eGQLMcU.png
pic01=%a_scriptdir%\Button_Picture_20210413.png
ifnotexist,%pic01%
  urldownloadtofile,%url%,%pic01%
Gui,3:default
Gui,3: -DPIScale -Caption +AlwaysOnTop
gui,3:color,black,black
content :=
(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Nec ultrices dui sapien eget. Feugiat scelerisque
varius morbi enim nunc faucibus a."
)
;-- maybe change the FontSize / not proportional to screen resolution
Gui,3: Font, s18 cYellow, Verdana
x:=(wa*1)/xx,y:=(ha*1.5)/xx
Gui,3: Add, Text,x%x% y%y% +0x200, Title
;-----------
Gui,3: Font, s12 Bold
y:=(ha*6)/xx
Gui,3: Add, Text, x%x% y%y% +0x200, Subtitle
;-----------
Gui,3: Font, s10 Norm
y:=(ha*10)/xx
Gui,3: Add, Text,x%x% y%y%, % content
;-----------
x:=(wa*.2)/xx,y:=(ha*21)/xx,w:=(wa*10)/xx,h:=(ha*5)/xx
Gui,3:add,Picture, x%x% y%y% w%w% h%h% gDnlX ,%pic01%
;-----------
x:=(wa*11)/xx,y:=(ha*21)/xx,w:=(wa*7)/xx,h:=(ha*2.8)/xx
Gui,3:Add,Progress,            x%x%    y%y%    w%w%   h%h%  Disabled BackgroundRed
Gui,3:Add,Text,                xp    yp     wp    hp   cYellow  BackgroundTrans Center 0x200 gA1,TEST
;-------------------
x:=(wa*10)/xx,y:=(ha*10)/xx,w:=(wa*35)/xx,h:=(ha*33)/xx
Gui,3:show,x%x% y%y% w%w% h%h%,%filename1%
OnMessage(0x201, "WM_LBUTTONDOWN")
return
;----------------------------------------------
esc::exitapp
;----------------------------------------------
3Guiclose:
exitapp
;----------------------------------------------
A1:
msgbox, 262208, ,Button-TEST,2
return
;----------------------------------------------
DNLx:
mousegetpos,x,y,,CL
;-----------------
wdf:=(wa*1.56)/xx
hdf:=(ha*2.55)/xx
;-----------------
y11:=(ha* 22 )/xx
;-----------------
x11:=(wa* 0.68)/xx
x12:=(wa* 3.15)/xx
x13:=(wa* 5.68)/xx
x14:=(wa* 8.20)/xx
;------------------
if (CL = "Static4")
  {
  if (x>x11) and x<(x11+wdf) and (y>y11) and y<(y11+hdf)
    msgbox, 262208, ,Button-1 Loudspeaker,2
  if (x>x12) and x<(x12+wdf) and (y>y11) and y<(y11+hdf)
    msgbox, 262208, ,Button-2 Microfon,2
  if (x>x13) and x<(x13+wdf) and (y>y11) and y<(y11+hdf)
    msgbox, 262208, ,Button-3 Camera,2
  if (x>x14) and x<(x14+wdf) and (y>y11) and y<(y11+hdf)
    msgbox, 262208, ,Button-4 Telephon,2
  }
return
;------------------- function drag & move the GUI -----------------
WM_LBUTTONDOWN(wParam, lParam, msg, hwnd)
{
Gui, +LastFound
Checkhwnd := WinExist()
if hwnd = %Checkhwnd%
   PostMessage, 0xA1, 2
;- 0x201 is the number for Windows Message WM_LBUTTONDOWN, which is the message Windows sends when the mouse clicks on our window.
;- 0xA1 is WM_NCLBUTTONDOWN, to make Windows think we clicked on the non-client area of the window (the border).
;- The "2" tells windows we clicked on caption at the top of the window, as if to drag it.
}
;================= END SCRIPT ============================
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Bild ändern

20 Aug 2021, 04:25

Moin,

Deine Buttons ließen sich recht einfach mit [Class] ImageButton realisieren. Dann bliebe noch das Update der inneren Kreise.

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: gero and 42 guests