aus eins mach drei ? Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
glnklein
Posts: 116
Joined: 23 Oct 2020, 04:26

aus eins mach drei ?

10 May 2024, 03:20

ich wollte anstelle von einem kreis 3 kreise haben und der einzige weg den ich gefunden habe war alles 3 mal ins Skript ein zu binden , geht das nicht auch einfacher ? :-)


Code: Select all

#SingleInstance Force



X_OFFSET := 0
Y_OFFSET := 0
hCircle := makeCircle(0x00FF00, r := 55, 2, 240)
hCircle2 := makeCircle2(0x00FF00, r := 25, 2, 240)
hCircle3 := makeCircle3(0xFF0000, r := 2, 1, 240)
msgbox , Verschiebe einfach irgent wo hin , beim schließen des fensters verschwindet auch das Fadenkreuz
ExitApp


makeCircle(color, r := 50, thickness := 10, transparency := 254) {
	static HWND := MakeGui()
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}




makeCircle2(color, r := 50, thickness := 10, transparency := 254) {
	static HWND := MakeGui2()
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui2() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}

makeCircle3(color, r := 50, thickness := 10, transparency := 254) {
	static HWND := MakeGui2()
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui3() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}

~END::ExitApp


guiclose:
ExitApp







:D verwende AutoHotkey104805 :D ------------------------UPDATE auf ..1.1.33.02 erfolgreich , jetzt kommen neue Probleme :lolno:
just me
Posts: 9525
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: aus eins mach drei ?  Topic is solved

10 May 2024, 05:21

Moin,

ich weiß nicht so recht, warum Du das tust. Die Grundfunktionen makeCircle() und MakeGui() schaffen das auch allein. Du darfst die Variable HWND in makeCircle() allerdings nicht als Static deklarieren, weil die Funktion MakeGui() dann nur einmal und bereits vor dem ersten Aufruf der Funktion makeCircle() aufgerufen wird:

Code: Select all

#SingleInstance Force

X_OFFSET := 0
Y_OFFSET := 0
hCircle := makeCircle(0x00FF00, r := 55, 2, 240)
hCircle2 := makeCircle(0x00FF00, r := 25, 2, 240)
hCircle3 := makeCircle(0xFF0000, r := 2, 1, 240)
msgbox , Verschiebe einfach irgent wo hin , beim schließen des fensters verschwindet auch das Fadenkreuz
ExitApp

makeCircle(color, r := 50, thickness := 10, transparency := 254) {
	HWND := MakeGui() ; darf nicht Static sein
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}

~END::ExitApp


guiclose:
ExitApp
User avatar
glnklein
Posts: 116
Joined: 23 Oct 2020, 04:26

Re: aus eins mach drei ?

10 May 2024, 06:00

danke , da war ich echt blöd :-)
:D verwende AutoHotkey104805 :D ------------------------UPDATE auf ..1.1.33.02 erfolgreich , jetzt kommen neue Probleme :lolno:
User avatar
glnklein
Posts: 116
Joined: 23 Oct 2020, 04:26

Re: aus eins mach drei ?

10 May 2024, 06:07

oh gerade bemerkt , mit welchem befehl kann ich den jetzt die grösse aus einem gui heraus ändern , einfach hCircle neu definieren erzeugt ja nun einen 4 kreis

Code: Select all

#SingleInstance Force

X_OFFSET := 0
Y_OFFSET := 0
hCircle := makeCircle(0x00FF00, r := 55, 2, 240)
hCircle2 := makeCircle(0x00FF00, r := 25, 2, 240)
hCircle3 := makeCircle(0xFF0000, r := 2, 1, 240)
msgbox , Verschiebe einfach irgent wo hin , beim schließen des fensters verschwindet auch das Fadenkreuz
hCircle := makeCircle(0x00FF00, r := 550, 2, 240)
msgbox
ExitApp

makeCircle(color, r := 50, thickness := 10, transparency := 254) {
	HWND := MakeGui() ; darf nicht Static sein
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}

~END::ExitApp


guiclose:
ExitApp
:D verwende AutoHotkey104805 :D ------------------------UPDATE auf ..1.1.33.02 erfolgreich , jetzt kommen neue Probleme :lolno:
just me
Posts: 9525
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: aus eins mach drei ?

12 May 2024, 02:32

glnklein wrote:... , einfach hCircle neu definieren erzeugt ja nun einen 4 kreis
Stimmt, und deshalb musst Du das Fenster mit der ID hCircle vorher mit Destroy entfernen.

Falls Du die Zeit findest, Deinen Blick einmal auf diese Antwort zu richten, geht es um eine Spielsteuerung?
User avatar
Noitalommi_2
Posts: 274
Joined: 16 Aug 2023, 10:58

Re: aus eins mach drei ?

12 May 2024, 10:59

Hi.

Ich habe mir für eigene Zwecke aus dieser Funktion eine Klasse gebastelt und hier gepostet. (v2)

@glnklein
In der CreateEllipticRgn-Dokumentation von MS wird empfohlen, dass HRGN-Objekt mit der DeleteObject-Funktion zu löschen wenn man es nicht mehr benötigt. Dies kannst du tun, in dem du DllCall("DeleteObject", "Ptr", inner) irgendwo nach dem Zeigen des Guis einfügst.

Für "outer" ist dies scheinbar nicht nötig, da es wohl von der CombineRgn-Funktion automatisch freigegeben wird. (?)
(Nur eine Vermutung, weil DllCall("DeleteObject", "Ptr", outer) einen Misserfolg zurückgibt.)
just me
Posts: 9525
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: aus eins mach drei ?

13 May 2024, 02:29

Moin,

nach dem Aufruf von CombineRgn wird nur noch die 'kombinierte' Region outer benötigt. Die Region inner kann direkt danach gelöscht werden.

Die Region outer geht mit dem Aufruf der Funktion SetWindowRgn in den Besitz des Systems/Fensters über (Quelle). Damit ist sie anschließend für das Skript tabu.

GDI-Objekte werden vom System automatisch gelöscht, wenn die Anwendung beendet wird. Sie belegen aber Speicherplatz und die Gesamtzahl der gleichzeitig existierenden Objekte ist begrenzt. Deshalb ist es eine gute Idee DeleteObject aufzurufen, sobald das Objekt nicht mehr benötigt wird.

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 11 guests