Text background transparent

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hihixd123123
Posts: 3
Joined: 14 Dec 2021, 20:38

Text background transparent

05 Mar 2023, 14:46

Trying to make the background of a text transparent in a gui


This is what I have:
(This is supposed to be a simple counter that increases anytime you press a key (1 in this case))

Code: Select all

#SingleInstance, Force
#Include Class_CtlColors.ahk
SetWorkingDir, %A_ScriptDir%


OnMessage(0x0014, "WM_ERASEBKGND")
OnMessage(0x0201, "WM_LBUTTONDOWN")
Gui, +hwndHGUI -Caption
Gui, Margin, 0, 0
Gui, Font, cWhite s36
Gui, add, text, center w150 h50 x25 y10 vCount, %Count%
Gui, Font,
Gui, add, Button, gSave x20 w75 h25 y+10, Save
Gui, add, Button, gReset x+10 w75 h25 , Reset
Gui, show, h100 w200, GR Counter

return

GrCount := 0

Save:
return

Reset:
GrCount := 0
GuiControl, text, Count, 0
return

1::
GrCount++
GuiControl, text, Count, %GrCount%
return

GuiEscape:
ExitApp

WM_ERASEBKGND(W, L, M, H) {
   Global HGUI
   If (H = HGUI)
      Return True
}

WM_LBUTTONDOWN() {
   If (A_Gui) && (A_GuiControl = "")
      PostMessage, 0xA1, 2
}
return

This is the result (the background of the gui itself is transparent) :
(https://imgur.com/xgwPdjj)
Image

I tried putting "+BackgroundTrans" here:

Code: Select all

Gui, add, text, center w150 h50 x25 y10 vCount +BackgroundTrans, %Count%
However I get this (the previous number stays underneath the new number so it quickly becomes unreadable) :
(https://imgur.com/fBrqu12)
Image

[Mod edit: Moved topic to v1 help. The main section is now for AHK v2.]
User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Text background transparent

05 Mar 2023, 18:00

Check this, I think it has what you are looking for.

https://www.autohotkey.com/docs/v1/lib/Gui.htm#Color
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Text background transparent

05 Mar 2023, 18:32

Just for fun as well, here is an example using my Overlay class =P

Code: Select all

#singleinstance,force

#include ShinsOverlayClass.ahk ;assumes you download the class file to this directory

overlay := new ShinsOverlayClass(500,500,200,130,0,0,0) ;x,y,w,h,alwaysontop,vsync,clickthrough


OnMessage(0x200,"WM_MOUSEMOVE")
OnMessage(0x201,"WM_LBUTTONDOWN")
OnMessage(0x14, "WM_ERASEBKGND")

overlay.data.update := 1 ;controls when the gui should be redrawn
overlay.data.count := 0 ;the count of 1 presses

;create some custom buttons
overlay.data.buttons := []
overlay.data.buttons.push(new buttonClass(overlay,10,overlay.height-40,80,30,"Save","Save"))
overlay.data.buttons.push(new buttonClass(overlay,overlay.width-90,overlay.height-40,80,30,"Reset","Reset"))


loop {
	if (overlay.data.update) {
		Draw(overlay)
	}
	sleep 10
}

return


~1::
overlay.data.count++
overlay.data.update := 1 ;tells the overlay to redraw
return

save:
msgbox save
return

reset:
overlay.data.count := 0
overlay.data.update := 1
return




f9::reload
f8::exitapp





Draw(overlay) {
	overlay.data.update := 0
	if (overlay.BeginDraw()) {

		overlay.FillRectangle(0,0,overlay.Width,overlay.Height,0xAA000000)
		overlay.DrawRectangle(1,1,overlay.Width-1,overlay.Height-1,0xFF888888)
		
		overlay.DrawText(overlay.data.count,0,18,48,0xFFFFFFFF,"Arial","acenter w" overlay.width)
		
		for k,v in overlay.data.buttons
			v.draw()

		overlay.EndDraw()
	}
}


WM_LBUTTONDOWN(a,b) {
	global overlay
	mx := b & 0xFFFF
	my := b >> 16
	for k,v in overlay.data.buttons
	{
		if (v.Hover(mx,my)) {   ;if hovering a button call it's label and return
			label := v.label
			settimer,%label%,-1
			return
		}
	}
	PostMessage, 0xA1, 2
}
WM_MOUSEMOVE(a,b) {
	global overlay
	mx := b & 0xFFFF
	my := b >> 16
	for k,v in overlay.data.buttons
	{
		if (v.Hover(mx,my)) {
			if (!v.state) {
				v.state := 1
				overlay.data.update := 1
			}
		} else if (v.state) {
			v.state := 0
			overlay.data.update := 1
		}
	}
}

WM_ERASEBKGND() {
	return 0
}


class buttonClass {
	__New(overlay,x,y,w,h,text,label) {
		this.overlay := overlay
		this.x := x
		this.y := y
		this.x2 := x+w
		this.y2 := y+h
		this.w := w
		this.h := h
		this.text := text
		this.label := label
		this.state := 0
	}
	
	Hover(mx,my) {
		return (mx >= this.x and my >= this.y and mx <= this.x2 and my <= this.y2)
	}
	
	Draw() {
		if (this.state) {
			this.overlay.FillRectangle(this.x,this.y,this.w,this.h,0xFFFFFFFF)
			this.overlay.FillRectangle(this.x+1,this.y+1,this.w-2,this.h-2,0xFF999999)
			this.overlay.DrawText(this.text,this.x,this.y,24,0xFF000000,"Arial","acenter w" this.w)
		} else {
			this.overlay.FillRectangle(this.x,this.y,this.w,this.h,0xFFFFFFFF)
			this.overlay.FillRectangle(this.x+1,this.y+1,this.w-2,this.h-2,0xFF222222)
			this.overlay.DrawText(this.text,this.x,this.y,24,0xFFFFFFFF,"Arial","acenter w" this.w)
		}
	}
}


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk and 338 guests