exchanging images using buttons Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
BielGuitarJP
Posts: 1
Joined: 16 Apr 2024, 21:42

exchanging images using buttons  Topic is solved

30 Apr 2024, 14:07

The logic that is happening is the following:

1- When the Option3 button is pressed, the background image is added.
2-When the Option2 button is pressed, the GUI color is changed to gray, and the background image is successfully hidden.
3- When the Option3 button is pressed again, the background image is added successfully.
4- When the Option2 button is pressed again, the background image remains on the screen above the gui and does not leave.

I need each button to perform a function regardless of the number of times it is pressed, because in this case I can only add and remove the background image 2 times, the 3rd time it stays stuck on ;the screen and doesn't come out, I don't know why this is happening. Can someone help me?

Code: Select all

#SingleInstance, Force
#NoEnv
ListLines, Off
SetBatchLines, -1
#include C:\Users\Gabriel\AHK Advanced\Scripts class e biblioteca\Gdip.ahk

; Inicializa o token GDI+
pToken := Gdip_Startup()

; Cria a GUI principal
Gui, 1: +LastFound -DPIScale -Caption
Gui, 1: Color, B1B1B1
Gui, 1: Font, Bold s11, Segoe UI

; Define os botões de rádio como AlwaysOnTop
global HB_RadioGroup1 := []
HB_RadioGroup1.Push(New Flat_Round_Radio_Type_1(x:=160, y:=10, w:=100, Text:="Option 1", Font:="Arial", FontSize:=14 " Bold", FontColor:="FFFFFF", Window:=1, Background_Color:="3A3C40", HighLightColor:="A866E2", State:=1, GroupArray:=HB_RadioGroup1))
HB_RadioGroup1.Push(New Flat_Round_Radio_Type_1(x:=160, y+=60, w:=100, Text:="Option 2", Font:="Arial", FontSize:=14 " Bold", FontColor:="FFFFFF", Window:=1, Background_Color:="3A3C40", HighLightColor:="A866E2", State:=0, GroupArray:=HB_RadioGroup1))
HB_RadioGroup1.Push(New Flat_Round_Radio_Type_1(x:=160, y+=60, w:=100, Text:="Option 3", Font:="Arial", FontSize:=14 " Bold", FontColor:="FFFFFF", Window:=1, Background_Color:="3A3C40", HighLightColor:="A866E2", State:=0, GroupArray:=HB_RadioGroup1))

Global BackgroundImagePath := "C:\Users\Gabriel\AHK Advanced\Scripts variados e Gdip\Imagens testes\Background_Teste_fullscreen.png"

; Função para remover a imagem de fundo
Remove_Background_Image()
{
    GuiControl, 1:Hide, %BackgroundImagePath%
}

; Função para adicionar a imagem de fundo
Add_Background_Image()
{
    Gui, 1: Add, Picture, x0 y0 w1920 h1080 BackgroundTrans, %BackgroundImagePath%
}

; Atualiza a cor da janela e a visibilidade da imagem de fundo
Update_Window_Color() {
    global BackgroundImagePath
    if (HB_RadioGroup1[1].State) {
        Remove_Background_Image()
        Gui, 1: Color, Red
    } else if (HB_RadioGroup1[2].State) {
        Remove_Background_Image()
        Gui, 1: Color, 444444  ; Define a cor cinza como fundo
    } else if (HB_RadioGroup1[3].State) {
        Add_Background_Image()
    }

}

Update_Window_Color()
Gui, 1: Show, x0 y0 w1920 h1080



AbrirCalc(){
    Run, Calc.exe
    WinWait, ahk_class ApplicationFrameWindow
    WinSet, AlwaysOnTop, on, ahk_class ApplicationFrameWindow
}
GuiClose:
GuiContextMenu:
~ESC::
    Gdip_DisposeImage(pBitmapBackground)
   Gdip_Shutdown(pToken)
    ExitApp

class Flat_Round_Radio_Type_1 {
	__New(x, y, w:=19, Text:="Text", Font:="Arial", FontSize:= "10 Bold", FontColor:="FFFFFF", Window:="1", Background_Color:="36373A", HighLightColor:="1A1C1F", State:=0, GroupArray:="") {
		This.State := State
		This.X := x
		This.Y := y
		This.W := W
		This.H := 19
		This.Text := Text
		This.Font := Font
		This.FontSize := FontSize
		This.FontColor := "0xFF" FontColor
		This.HighLightColor := "0xFF" HighLightColor
		This.GroupArray := GroupArray
		This.Name := This.GroupArray.Length() + 1
		This.Background_Color := "0xFF" Background_Color
		This.Window := Window

		Loop, % This.GroupArray.Length() {
			if (This.GroupArray[A_Index].State = 1){
				This.Value := A_Index
				break
			}
		}
		Loop, % This.GroupArray.Length() {
			GroupArray[A_Index].Value := This.Value
		}
		This.Create_Off_Bitmap()
		This.Create_On_Bitmap()
		This.Create_Trigger()
		sleep, 20
		if (This.State)
			This.Draw_On()
		else
			This.Draw_Off()
	}

	Create_Trigger() {
		Gui, % This.Window ": Add", Picture, % "x" This.X " y" This.Y " w" This.W " h" This.H " 0xE hwndHwnd"
		This.Hwnd := hwnd
		BD := THIS.Switch_State.BIND(THIS)
		GuiControl, +BackgroundTrans, % This.Hwnd  ; Define o fundo do controle como transparente
		GUICONTROL +G, % This.Hwnd, % BD
	}

	Switch_State() {
		if(This.State != 1) {
			This.State := 1
			This.Draw_On()
			Loop, % This.GroupArray.Length() {
				if(This.GroupArray[A_Index].Name != This.Name){
					This.GroupArray[A_Index].State := 0
					This.GroupArray[A_Index].Draw_Off()
				}
			}
			Loop, % This.GroupArray.Length() {
				if(This.GroupArray[A_Index].State = 1){
					This.Value := A_Index
					break
				}
			}
			Loop, % This.GroupArray.Length() {
				This.GroupArray[A_Index].Value := This.Value
			}
			Update_Window_Color()
		}
	}

	Draw_Off() {
		SetImage(This.Hwnd , This.Off_Bitmap)
	}

	Draw_On() {
		SetImage(This.Hwnd , This.On_Bitmap)
	}

	Create_Off_Bitmap() {
		; Adjusting size
		multiplier := 2
		adjusted_width := 100 * multiplier
		adjusted_height := 19 * multiplier
		adjusted_radius := 8 * multiplier

		; Creating the bitmap
		pBitmap := Gdip_CreateBitmap(adjusted_width, adjusted_height)
		G := Gdip_GraphicsFromImage(pBitmap)
		Gdip_SetSmoothingMode(G, 4)

		; Background
		Brush := Gdip_BrushCreateSolid(This.Background_Color)
		Gdip_FillRectangle(G, Brush, -1, -1, 102 * multiplier, 21 * multiplier)
		Gdip_DeleteBrush(Brush)

		; Drawing inner circle
		Brush := Gdip_BrushCreateSolid("0xFF313436")
		Gdip_FillEllipse(G, Brush, 1 * multiplier, 1 * multiplier, 17 * multiplier, 17 * multiplier)
		Gdip_DeleteBrush(Brush)

		; Drawing outer circle
		Brush := Gdip_BrushCreateSolid("0xFF1A1C1F")
		Gdip_FillEllipse(G, Brush, 1 * multiplier, 0, 17 * multiplier, 17 * multiplier)
		Gdip_DeleteBrush(Brush)

		; Details
		Brush := Gdip_BrushCreateSolid("0xFF4D5055")
		Gdip_FillEllipse(G, Brush, 7 * multiplier, 7 * multiplier, 5 * multiplier, 6 * multiplier)
		Gdip_DeleteBrush(Brush)

		Brush := Gdip_BrushCreateSolid("0xFF222325")
		Gdip_FillEllipse(G, Brush, 7 * multiplier, 6 * multiplier, 5 * multiplier, 5 * multiplier)
		Gdip_DeleteBrush(Brush)

		; Adding text
		Brush := Gdip_BrushCreateSolid(This.FontColor)
		Gdip_TextToGraphics(G, This.Text, "s" This.FontSize " vCenter c" Brush " x45 y-5", This.Font, 150, 50)
		Gdip_DeleteBrush(Brush)

		Gdip_DeleteGraphics(G)
		This.Off_Bitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
		Gdip_DisposeImage(pBitmap)
	}

	Create_On_Bitmap() {
		multiplier := 2
		adjusted_width := 100 * multiplier
		adjusted_height := 19 * multiplier

		pBitmap := Gdip_CreateBitmap(adjusted_width, adjusted_height)
		G := Gdip_GraphicsFromImage(pBitmap)
		Gdip_SetSmoothingMode(G, 4)

		Brush := Gdip_BrushCreateSolid(This.Background_Color)
		Gdip_FillRectangle(G, Brush, -1, -1, (102) * multiplier, (21) * multiplier)
		Gdip_DeleteBrush(Brush)

		Brush := Gdip_BrushCreateSolid("0xFF484A4B")
		Gdip_FillEllipse(G, Brush, 1 * multiplier, 1 * multiplier, 17 * multiplier, 17 * multiplier)
		Gdip_DeleteBrush(Brush)

		Brush := Gdip_BrushCreateSolid("0xFF1A1C1F")
		Gdip_FillEllipse(G, Brush, 1 * multiplier, 0, 17 * multiplier, 17 * multiplier)
		Gdip_DeleteBrush(Brush)

		Brush := Gdip_BrushCreateSolid("0xFF29292F")
		Gdip_FillEllipse(G, Brush, 2 * multiplier, 1 * multiplier, 15 * multiplier, 15 * multiplier)
		Gdip_DeleteBrush(Brush)

		Brush := Gdip_BrushCreateSolid("0xFF4D5055")
		Gdip_FillEllipse(G, Brush, 7 * multiplier, 7 * multiplier, 5 * multiplier, 5 * multiplier)
		Gdip_DeleteBrush(Brush)

		Brush := Gdip_BrushCreateSolid(This.HighLightColor)
		Gdip_FillEllipse(G, Brush, 7 * multiplier, 6 * multiplier, 5 * multiplier, 5 * multiplier)
		Gdip_DeleteBrush(Brush)

		Brush := Gdip_BrushCreateSolid(This.FontColor)
		Gdip_TextToGraphics(G, This.Text, "s" This.FontSize " vCenter c" Brush " x45 y-5", This.Font, 150, 50)
		Gdip_DeleteBrush(Brush)

		Gdip_DeleteGraphics(G)
		This.On_Bitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
		Gdip_DisposeImage(pBitmap)
	}
}
Last edited by joedf on 30 Apr 2024, 14:13, edited 2 times in total.
Reason: fix [code] tags

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 118 guests