Modificar el texto de una GUI Topic is solved

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

Moderator: Flipeador

Archa

Modificar el texto de una GUI

Post by Archa » 19 Mar 2023, 01:10

Hola gente,

Este programa muestra una GUI con la palabra "Texto" y un contador, tal que así: "Texto 00:06"

Me gustaría que mostrase el mismo contador pero sustituyendo la palabra "Texto" por cualquier otra frase, así por ejemplo: "Las rosas son rojas, las violetas son azules 00:06"

Si cambio la palabra "Texto" deja de funcionar correctamente y no sé el motivo, si alguien lo sabe le agradecería la info.

Code: Select all

;----------------------------------------------------------Programa-------------------------------------------------------------
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Gui, MyGui:-Caption +Hwndhwnd +AlwaysOnTop +ToolWindow +E0x20
Gui, MyGui:Font, s32, Arial
Gui, MyGui:Add, Text, cRed, Texto 00:00
Gui, MyGui:Color, ff3300
Gui, MyGui:Show, NA ;x0 y400
WinSet, Transparent, 255, ahk_id %hwnd%
WinSet, TransColor, ff3300, ahk_id %hwnd%

StartTime := A_TickCount

loop
{
ElapsedTime := (A_TickCount - StartTime) / 1000

;-----------------TOOLTIP ElapsedTime----------------------------
minutos := Floor(ElapsedTime / 60)
segundos := Floor(ElapsedTime - ((Floor(ElapsedTime / 60)) * 60))
if ((minutos < 10) && (segundos < 10))
{
	;ToolTip, ElapsedTime = %ElapsedTime%  0%minutos%:0%segundos%, 1920, 55
	GuiControl, MyGui:, Text, Texto 0%minutos%:0%segundos%
}
else if ((minutos < 10) && (segundos >= 10))
{
	;ToolTip, ElapsedTime = %ElapsedTime%  0%minutos%:%segundos%, 1920, 55
	GuiControl, MyGui:, Text, Texto 0%minutos%:%segundos%
}
else if ((minutos >= 10) && (segundos < 10))
{
	;ToolTip, ElapsedTime = %ElapsedTime%  %minutos%:0%segundos%, 1920, 55
	GuiControl, MyGui:, Text, Texto %minutos%:0%segundos%
}
else if ((minutos >= 10) && (segundos >= 10))
{
	;ToolTip, ElapsedTime = %ElapsedTime%  %minutos%:%segundos%, 1920, 55
	GuiControl, MyGui:, Text, Texto %minutos%:%segundos%
}
sleep, 100
}
return

Numpad1::
StartTime := A_TickCount
return

[Moderator edit: Added [code][/code] tags. Please use them yourself when posting code.]

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Modificar el texto de una GUI  Topic is solved

Post by garry » 19 Mar 2023, 06:20

ejemplo

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn   ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
xx:=100,WA:=A_screenwidth,HA:=A_screenheight
Gui,2:  -DPIScale
Gui, 2:-Caption +Hwndhwnd +AlwaysOnTop +ToolWindow +E0x20
Gui, 2:Font, s32 cYellow, Lucida Console
T2:="  Texto                                           00:00:00"
w:=(WA*75)/xx
Gui, 2:Add, Text,vT1 w%w%,%t2%
Gui, 2:Color, ff3300
WinSet, Transparent, 255, ahk_id %hwnd%
WinSet, TransColor, ff3300, ahk_id %hwnd%
x:=(WA*10)/xx,y:=(HA*10)/xx,w:=(WA*75)/xx,h:=(HA*10)/xx
Gui, 2:Show, NA x%x% y%y% w%w% h%h%
sleep,2000
gosub,a1
return
;-----------------------------
2Guiescape:
2Guiclose:
Exitapp
;-----------------------------
A1:
timerh := timerm := timers := "00"
T2:="Las rosas son rojas, las violetas son azules    "
SetTimer, Stopwatch, 1000
gosub,stopwatch
return
;-------------------------------------
Stopwatch:
If (++timers > 59)
 timerm += 1, timers := "00"
If (timerm > 59)
 timerh += 1, timerm := "00"
GuiControl,2:, T1,% Format("{:50}{:02}:{:02}:{:02}",t2, timerh, timerm, timers)
Return
;-----------------------------------
esc::exitapp
;==================================

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Modificar el texto de una GUI

Post by garry » 19 Mar 2023, 10:07

START/PAUSE/RESET

Code: Select all

;---
;- Modificar el texto de una GUI 
;- https://www.autohotkey.com/boards/viewtopic.php?f=40&t=115182

;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=95025
#NoEnv                         ;- Recommended for performance and compatibility with future AutoHotkey releases.
#Warn                          ;- Enable warnings to assist with detecting common errors.
SendMode Input                 ;- Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%    ;- Ensures a consistent starting directory.
xx:=100,WA:=A_screenwidth,HA:=A_screenheight
Gui,2:  -DPIScale
Gui,2:Color,Black,black
Gui,2:Font, s32 cYellow, Lucida Console
T2:="  TEXT                                              00:00:00"
x:=(WA*2)/xx,y:=(HA*2)/xx,w:=(WA*71)/xx,h:=(HA*10)/xx
Gui,2: add, Edit  ,x%x% y%y% w%w% h%h% cRed vTText,%t2%
;-
x:=(WA*2)/xx,y:=(HA*14)/xx,w:=(WA*10)/xx,h:=(HA*3.5)/xx
Gui,2:Add, Button,x%x% y%y% w%w% h%h% vStart1 gStart,START
;-
x:=(WA*14)/xx,y:=(HA*14)/xx,w:=(WA*10)/xx,h:=(HA*3.5)/xx
Gui,2:Add, Button,x%x% y%y% w%w% h%h% vPause gPause,PAUSE
;-
x:=(WA*26)/xx,y:=(HA*14)/xx,w:=(WA*10)/xx,h:=(HA*3.5)/xx
Gui,2:Add, Button,x%x% y%y% w%w% h%h% gReset , RESET
;-
Gui,2:add,text,x0 y0 w0 h0 vT1
x:=(WA*10)/xx,y:=(HA*10)/xx,w:=(WA*75)/xx,h:=(HA*20)/xx
Gui, 2:Show, x%x% y%y% w%w% h%h%,TEST
GuiControl,2: Focus,T1
gosub,reset
return
;-----------------------------
2Guiescape:
2Guiclose:
Exitapp
;-----------------------------
;-------------------------------------
Stopwatch:                             ; Timed routine to advance the stopwatch time
If (++timers > 59)
 timerm += 1, timers := "00"
If (timerm > 59)
 timerh += 1, timerm := "00"
Gosub, Update
Return
;-------------------------------------
Pause:                                  ; Pause or resume
GuiControlGet, stopped,, Pause
If (stopped = "Pause") {                ; User clicked "Pause"
 SetTimer, Stopwatch, Off
 GuiControl,2:, Pause, Resume           ; Button: Pause -> Resume
 Gui,2: Color, FFFDCD                   ; Yellow
 SoundBeep, 1000
 Return
} Else GuiControl,2:, Pause, Pause      ; Button: Resume -> Pause
;-----------------------------------
Start:                                 ; Start the timer
SetTimer, Stopwatch, 1000
Gui,2: Color, E7FFEB                   ; Green
SoundBeep, 1500
Return
;----------------------------------
Reset:                                 ; Reset the timer
timerh := timerm := timers := "00"
SetTimer, Stopwatch,off
SoundBeep, 1900
;----------------------------------
Update:
aa:=Format("{:02}:{:02}:{:02}",timerh, timerm, timers)
ab:=Format("{:02}{:02}{:02}",timerh, timerm, timers) 
ac:=6,ad:=10
if ((ab>=ac) and (ab<=ad))     ;- if between 6-10 /  if between ac-ad 
  {
  T2:="Las rosas son rojas, las violetas son azules    "
  GuiControl,2:, TText,`n%t2% %aa%
  }
else
  {
  T2:=" TEXT                                           "
  GuiControl,2:, TText,`n%t2% %aa%
  }   
Return
;----------------------------------
/*
aa:="00069"
ac:=ceil(aa)
if (ac<70)
  msgbox,%ac% is smaller than 70
if (ac>=70)
  msgbox,%ac% is = > than 70
return
*/
;==================================

Archa

Re: Modificar el texto de una GUI

Post by Archa » 20 Mar 2023, 03:13

Muchísimas gracias garry, eres un crack ;)

arsantallaAHK
Posts: 1
Joined: 08 Apr 2023, 07:32

Re: Modificar el texto de una GUI y depurador simplon de regalo

Post by arsantallaAHK » 08 Apr 2023, 08:00

Proporcionaste la ayuda que necesitaba! Gracias
Soy ultra novato.

Y este es mi regalo de vuelta (la macro para el Notepad++ es lo valioso junto con este AHK)
Con esto puedes insertar paros en el AHK que te muestran la variable y su contenido
con solo pinchar encima y pulsar F2 (atajo de teclado que hay que añadir a la macro)
----------------------------------------------------------------- esto es un ejemplo de AHK...

Code: Select all

; probando mi depurador simplon...
v1 = mi depurador simplon
pspc(A_LineNumber " v1`r`n<" v1 ">`r`n")
v2 = esto funciona!
pspc(A_LineNumber " v2`r`n<" v2 ">`r`n")
v3 = hola Juan, como estás?
tooltip, %v3%
sleep 1000
tooltip fin
return

pspc(elmensaje := "", latecla := "Shift")
{
	Tooltip, %elmensaje%
	KeyWait, %latecla%, D
	tooltip
	KeyWait, %latecla%, U
	sleep 100
}
esc::exitapp
[Mod edit: He añadido tags de código a tu mensaje. Por favor, utilízalas tú también en futur.]

-------------------------- esto es una macro para insertar entre las otras macros
-------------------------- del Notepad++ (en shortcuts.html del Roaming\Notepad++

Code: Select all

        </Macro>
        <Macro name="pspc()" Ctrl="no" Alt="no" Shift="no" Key="113">
            <Action type="0" message="2308" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2442" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2178" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2451" wParam="0" lParam="0" sParam="" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="p" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="s" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="p" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="c" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="(" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="A" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="_" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="L" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="i" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="n" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="e" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="N" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="u" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="m" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="b" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="e" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="r" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam='&quot;' />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
            <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="`" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="r" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="`" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="n" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&lt;" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam='&quot;' />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
            <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam='&quot;' />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&gt;" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="`" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="r" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="`" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="n" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam='&quot;' />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=")" />
        </Macro>
----------------------------------

Post Reply

Return to “Pedir Ayuda”