Page 1 of 1

Cor e tamanho das janelas!

Posted: 17 Dec 2020, 08:24
by robertoseifert
Sou novo aqui, desculpa se fizer algo errado!

Code: Select all

WinMinimizeAll
DATA_ATUAL := A_YYYY . A_MM . A_DD
DATA_VALIDADE := (A_YYYY - 2000) * A_MM * A_DD * 3
                   msgbox % DATA_VALIDADE
estou usando o código acima para gerar uma senha diária, como faço pra mudar tamanho e cores da janela ?

Re: Cor e tamanho das janelas!

Posted: 17 Dec 2020, 15:01
by garry
a GUI , use x,y,w,h x-position y-position w-width h-height

Example-1

Code: Select all

;- use F7 to show DATA_VALIDADE / GUI only like msgbox
#persistent

~$F7::
Gui,1: +AlwaysOnTop -DPIScale -Theme -caption
Gui,1:Color,Black,Black                        ; GUI black   / EDIT is BLACK
Gui,1:Font,CYellow s12,Lucida Console          ; set FONT , SIZE=12 , EDIT-TEXT is Yellow 
;-------
A:= A_YYYY . A_MM . A_DD                       ;- today 
B:= (A_YYYY - 2000) * A_MM * A_DD * 3
;Gui,1:add,Text,    x10    y10   cWhite,DATA_ATUAL=                       ;- text white
;Gui,1:add,Edit,    x270   y10   w180 h40    right  readonly vA1 , %a%    ;- today 
Gui,1:add,Text,    x10    y60   cWhite,DATA_VALIDADE=
Gui,1:add,Edit,    x270   y60   w180 h40    right  readonly vB1 , %b%
Gui,1:add,Text,vT1,
Gui,1:Add, Button, x20 y110 w250 h37 gOK1,OK
Gui,1:Show,x1 y1 w500 h160 ,TEST            ;- GUI position and size
GuiControl,1: Focus,T1                        ;- set focus to the first field
Return
;-------------
OK1:
Guiclose:
Gui,1: destroy
return
esc::exitapp
;-------------

Example-2

Code: Select all

;- use F7 to show DATA_VALIDADE
#persistent

~$F7::
Gui,1: +AlwaysOnTop -DPIScale -Theme
Gui,1:Color,Black,Black                        ; GUI black   / EDIT is BLACK
Gui,1:Font,CYellow s12,Lucida Console          ; set FONT , SIZE=12 , EDIT-TEXT is Yellow 
;-------
A:= A_YYYY . A_MM . A_DD                       ;- today 
B:= (A_YYYY - 2000) * A_MM * A_DD * 3
Gui,1:add,Text,    x10    y10   cWhite,DATA_ATUAL=                       ;- text white
Gui,1:add,Edit,    x270   y10   w180 h40    right  readonly vA1 , %a%    ;- today 
;Gui,1:add,Text,    x10    y60   cWhite,DATA_VALIDADE=
;Gui,1:add,Edit,    x270   y60   w180 h40    right  readonly vB1 , %b%
Gui,add,Text,vT1,
Gui,1:Add, Button, x20 y110 w250 h37 gOK1,DATA_VALIDADE
Gui,1:Show,x1 y1 w500 h160 ,TEST            ;- GUI position and size
GuiControl, Focus,T1                        ;- set focus to the first field
Return
;-------------
Guiclose:
exitapp
esc::exitapp
;-------------
OK1:
Gui,1:submit,nohide
;msgbox, 262208,DATA_VALIDADE,%B%,
Gui,2: +AlwaysOnTop -DPIScale -Theme
Gui,2:Color,Black,Black                        ; GUI black   / EDIT is BLACK
Gui,2:Font,CYellow s12,Lucida Console          ; set FONT , SIZE=12 , EDIT-TEXT is Yellow 
Gui,2:add,Text,    x10    y10   cWhite,DATA_VALIDADE=
Gui,2:add,Edit,    x270   y10   w180 h40    right  readonly vB1 , %b%
Gui,2:add,Text,vT2,
Gui,2:Add, Button, x20 y80 w250 h37 gOK2,OK
Gui,2:Show,x700 y400 w500 h130 ,TEST2            ;- GUI position and size
GuiControl,2: Focus,T2                        ;- set focus to the first field
return

OK2:
Gui,1: destroy
Gui,2: destroy
return
;=============
Example-3

Code: Select all

#warn
#noenv
name1:="MATHE-TEST" 
setworkingdir,%a_scriptdir%
Gui,1: -dpiscale
Gui,1:default
Gui,1: +AlwaysOnTop -DPIScale -Theme
;Gui,1:Color,C8D0D4,Black                      ;-GUI gray    / EDIT is BLACK
;Gui,1:Color,762e1c,Black                      ; GUI bordeaux/ EDIT is BLACK
Gui,1:Color,Black,Black                        ; GUI black   / EDIT is BLACK
Gui,1:Font,CYellow s12,Lucida Console          ; set FONT , SIZE=12 , EDIT-TEXT is Yellow 
;-------
A:= A_YYYY . A_MM . A_DD                       ;- today 
;B:= (A_YYYY - 2000) * A_MM * A_DD * 3
Gui,1:add,Text,    x10    y10   cWhite,DATA_ATUAL=               ;- text white
Gui,1:add,Edit,    x270   y10   w180 h40    right   vA1 , %a%    ;- today ( can overwrite )
;Gui,1:add,Text,    x10    y70   cWhite,DATA_VALIDADE=
;Gui,1:add,Edit,    x270   y70   w180 h40    right  readonly vB1 , %b%
Gui,1:add,Text,    x10    y130  cRED,RESULT=
Gui,1:add,Edit,    x270   y130  w180 h40    right   vResult readonly cWhite,
;Gui,1: Add, Button, x20 y350 w250 h37 gCALC,CALCULATE
;- or color button
Gui,1: Add, Progress, x20 y350 w250 h37 Disabled Background87CEEB
;Gui,1: Add, Progress, x20 y350 w250 h37 Disabled BackgroundGRAY    ;- button color GRAY
Gui,1: Add, Text, xp yp wp hp BackgroundTrans 0x201 cBlack vText +Border gCALC,CALCULATE
;--
Gui,1: Add, Button, x300 y350 w150 h37 gClear,CLEAR
;--------
Gui,1:Show,x1 y1 w800 h420 ,%name1%         ;- GUI position and size
GuiControl, Focus,A1                        ;- set focus to the first field
send,{end}
Return
;-------------
Guiclose:
exitapp
;-------------
CALC:
Gui,1:submit,nohide
;-  20201217 calculate dependig year in edit A1 ----------
stringmid,year ,a1,1,4    ;- 2020
stringmid,month,a1,5,2    ;- 12
stringmid,day  ,a1,7,2    ;- 17
DATA_VALIDADE:= (year - 2000) * month * day * 3
Guicontrol,1:,Result,%DATA_VALIDADE%
msgbox, 262208,RESULT ,%DATA_VALIDADE%,2           ;- msgbox alwaysontop for 2 seconds  ( not needed )
return
;-------------
CLEAR:
;Guicontrol,1:,A1
;Guicontrol,1:,B1
Guicontrol,1:,Result,  ;- clear only result 
GuiControl, Focus,A1                        ;- set focus to the first field
send,{end}
return
;=====================================================

Re: Cor e tamanho das janelas!

Posted: 18 Dec 2020, 10:45
by Gio
Bom dia Robertoseifert.

Seja bem-vindo ao fórum da comunidade do AutoHotkey.

Você está utilizando atualmente uma msgbox para exibir o resultado do cálculo. Este tipo de janela é apenas uma caixa de mensagem, cujo propósito é ser uma ferramenta de mais simples implementação para informar o usuário de alguma coisa. Janela completas (chamadas GUIs ou "Interface Gráfica do Usuário") dão um pouco mais de trabalho para implementar, mas você pode conferir um tutorial básico sobre elas aqui.

No caso do seu código, um código simples que controlasse a cor e o tamanho da janela seria como este:

Code: Select all

DATA_ATUAL := A_YYYY . A_MM . A_DD
DATA_VALIDADE := (A_YYYY - 2000) * A_MM * A_DD * 3
Gui, Add, Text, x20 y20, %DATA_VALIDADE% ; ESTA LINHA ESCREVE UM TEXTO NAS POSIÇÕES HORIZONTAL 20 E VERTICAL 20 DA JANELA, CUJO CONTEÚDO É O QUE ESTIVER NA VARIÁVEL DATA_VALIDADE (OU SEJA, O RESULTADO DO CÁLCULO).
Gui, Color, 009090 ; ESTA LINHA ALTERA A COR DE FUNDO DA JANELA PARA UMA COR DE COMPOSICAO RGB: 00 VERMELHO, 90 VERDE E 90 AZUL. (A COR FINAL SERIA UM TURQUESA UM POUCO ESCURO). OS VALORES SÃO HEXADECIMAIS (DE 00 ATÉ FF).
Gui, Show, w700 h200 ; ESTA LINHA EXIBE A JANELA COM AS CONFIGURAÇÕES ACIMA, E TAMBÉM É AQUI QUE DEFINIMOS O TAMANHO DA JANELA. NESTE CASO, 700 PIXELS HORIZONTAL E 200 PIXELS VERTICAL.
Espero ter ajudado, se ainda tiver alguma dúvida sobre este tópico, basta postar abaixo :thumbup: