corrección de IF para detectar cambios de Titulo de ventana

Esta sección es para preguntas sobre programación/scripting usando AutoHotkey.

Moderator: Flipeador

Dsalomon
Posts: 22
Joined: 02 Mar 2021, 23:01

corrección de IF para detectar cambios de Titulo de ventana

28 Sep 2021, 01:51

Un gusto saludarles nuevamente, hoy estoy varado en una mini aplicación para mostrar el cover art de las peliculas que se reproducen en el reproductor Media Player Classic.
cada archivo contiene una imagen de cover en formato JPG o PNG (eso es otra cosa que no he añadido a este codigo).

la ruta la obtiene de la clase: ahk_class MediaPlayerClassicW (configuración en MPC: Opciones> Reproductor> Barra de título y establezca el valor en "Mostrar ruta completa"), y con SplitPath extraigo los datos por medio de sus variables
la cosa viene al añadir el if que comprueba si cambia el titulo por defecto de la ventana "Media Player Classic Home Cinema", en teoria debe cambia la imagen cada vez que se detecte el cambio del nombre, ya me sature, si alguna buena alma me puede corregir el codigo, sin complejidades, estere atento y agradecido

Code: Select all

#Persistent
DetectHiddenWindows, On

SetTimer, revisar, 1000
return

revisar:
TituloMPC := "Media Player Classic Home Cinema"
WinGetTitle, Titulo, ahk_class MediaPlayerClassicW

if (TituloMPC =! Titulo)
{
	SplitPath, Titulo, vNombre, vRuta, vExt, vNombreNoExt, vDrive
	Gui, Add, Pic, w250 H-1 vPic Border, %vRuta%\%vNombreNoExt%.jpg
	Gui, Show
	return
}
return
Attachments
Sin título.png
Sin título.png (386.27 KiB) Viewed 1480 times
sofista
Posts: 650
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: corrección de IF para detectar cambios de Titulo de ventana

28 Sep 2021, 07:27

Hola: Noto un problema de sintaxis. Probá con

Code: Select all

if (TituloMPC != Titulo)

; o también:

if !(TituloMPC = Titulo)
Saludos
garry
Posts: 3768
Joined: 22 Dec 2013, 12:50

Re: corrección de IF para detectar cambios de Titulo de ventana

29 Sep 2021, 07:27

ejemplo

Code: Select all

;-----------------------------------
;- MPC-BE x64 , select video , show picture with same name as video
;-----------------------------------
#warn
setworkingdir,%a_scriptdir%
SetBatchLines, -1
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
x:=(wa*.1)/xx,y:=(ha*.1)/xx,w:=(wa*25)/xx,h:=(ha*25)/xx  ;- picture x y w h 
folder=C:\Test\M_VIDEO                                   ;- here are videos and picture with the same name
;-                                                        - Maitetxu mia.mp4 > Maitetxu mia.jpg
Gui,2:default
Gui,2: +HwndAId  +0x2000000 +AlwaysOnTop -Caption -DPIScale
Gui,2: Margin, 0, 0
Gui,2:Color,Black,Black
Gui,2: show ,x%x% y%y% w%w%,Test1
before:=""
settimer,revisar,1000
return
;------
esc::                                                    ;- close with ESC
2Guiclose:
Gui,3:destroy
sleep,1000
exitapp
;---------------------
revisar:
WinGetTitle, Titulo, ahk_class MPC-BE
new:=titulo
if !(before=new)                              ;- if MPC change title 
  {
  aa:= " - MPC-BE x64 1.5.6"                  ;- remove this from title
  stringreplace,title,new,%aa%,,all
  SplitPath,Title, name1, dir1, ext1, name_no_ext1, drive1
  xc:= Folder . "\" . name_no_ext1 . ".jpg"   ;- C:\Test\M_VIDEO\Maitetxu mia.jpg
  ;GuiControl,2: ,Pic,%xc% 
  ;msgbox, 262208, ,NAME=%xc% ,
  before:=new
  gosub,childnew1                             ;- show picture
  }
return
;----------------------
childnew1:
Gui,2:submit,nohide
Gui,3:destroy
Gui,3:default
imgSize(xc,imgw,imgh)
Gui,3: +HwndBId  
Gui,3: -Caption -Border +AlwaysOnTop -DPIScale
Gui,3: Margin, 0, 0
Gui,3: Color,Black,Black
if (imgw>imgh)
  {
  ;msgbox, 262208, ,width,2
  gui,3:add, Picture, x0 y0 h-1 w%w%,%xc%
  }
else if (imgh>imgw)
  {
  ;msgbox, 262208, , height,2
  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%
return
;------------------------------------
;- user mikeyww
;- Get the height / width of an image - to an array (object) 
;- https://www.autohotkey.com/boards/viewtopic.php?t=81665
;--
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
}
;====================================


Return to “Pedir Ayuda”

Who is online

Users browsing this forum: No registered users and 17 guests