CENSOR BOX erweitern Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

effel
Posts: 537
Joined: 16 Jan 2018, 13:34

CENSOR BOX erweitern

21 Oct 2021, 08:22

Hallo Forum,
ich versuche das Censor Script von SpeedMaster viewtopic.php?p=339761#p339761 zu erweitern.

Das funktioniert auch toll.

Meine Erweiterungen sind F7 bis F10.

; f7 save all boxes > (box_1,2771,569,281,172) > [ GuiVars.csv ]
; f8 destroy all boxes
; f9 rebuild all boxes
; todo f10:: gespeichterte guis reload


Mit F7 werden die Daten der schon erstellten Boxen in GuisArr und in GuiVars.csv abgespeichert, damit sie z.b. nach reload zur Verfügung stehen. F8 zerstört alle Boxen und mit F9 werden alle Boxen aus GuisArr wieder aufgebaut.

Mit F10 müsste ich normalerweise alle Boxen aus der GuiVars.csv einlesen, in GuisArr ablegen und dann aus diesem neu angelegten Array die Boxen wieder neu etablieren.

Und das will nicht wie es soll. Obwohl das neu aufbauen der Boxen aus genau der gleichen Routine ist wie die funktionierende F9

Wenn ich die Zeilen

Code: Select all

;/*
GuisArr := []
count =
FileRead, guiVar, K:\Eigene Dateien\Autohotkey\Lib\GuiVars.csv
xSplit := strSplit(guiVar,"`n")

MsgBox,,%A_LineNumber%,% isObject(xSplit)
MsgBox,,%A_LineNumber%,% guiVar

for each, guiVar in xSplit 
{
split := strSplit(guiVar,",")
if !split[5]
continue
GuisArr["box_" a_index] := ("box_" a_index) "," split[2] "," split[3] "," split[4] "," split[5]
;MsgBox,,%A_LineNumber%,% GuisArr["box_" a_index] ,1
}
;*/
deaktiviere, funktioniert F10 und baut aus dem vorhandenen Array die Boxen auf


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.

; =================================================================================================================================
; Name:           CENSOR BOX 
; Description:    Hide parts of the screen with a colored box
; credits:        Speedmaster, Lexikos, flyingDman, rommmcek, MancioDellaVega
; Topic:          https://www.autohotkey.com/boards/viewtopic.php?f=6&t=78160
; Sript version:  1.4
; AHK Version:    1.1.24.03 (A32/U32/U64)
; Tested on:      Win 7 
; shortcuts::     F1 add a new box
;                 F2 color the box with the top left pixel
;                 F2 Long press (> 0.6 sec) highlight box in red
;                 F3 freeze/unfreeze all boxes
;                 F4 remove selected box
;                 F5 hide/show all boxes
;                 F6 make current box semi transparent
;              f7 save all boxes > (box_1,2771,569,281,172) > [ GuiVars.csv ]
;              f8 destroy all boxes
;              f9 rebuild all boxes
;   todo       f10:: gespeichterte guis reload
;                 Shift + Left Button show x-cross
;                 Shift Up (while LButton down) start drawing rectangle
;                 ESC exit script
;                 all boxes are resizable with the mouse

#SingleInstance force

OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")
OnMessage(0x86, "WM_NCACTIVATE")
CoordMode, pixel, screen
CoordMode, mouse, screen

BW := 2           				; Border width (and height) in pixels
BC := "FF8800"       			; Border color
FirstCall := True
Gui, -Caption  +LastFound +AlwaysOnTop
Gui, Color, %BC%

Gui, Cross1: -Caption +AlwaysOnTop 
Gui, Cross1: Color, % bc
Gui, Cross2: -Caption +AlwaysOnTop 
Gui, Cross2: Color, % bc
count:= 0
Return

+LButton::
While GetKeyState("Shift", "P") {
    MouseGetPos, OriginX, OriginY
    ;OriginX-=8, OriginY-=5
    Gui, Cross1: show, % "NA y0 w1 x" OriginX " h" A_ScreenHeight
    Gui, Cross2: show, % "NA x0 h1 y" OriginY " w" A_ScreenWidth
    Sleep, 10
}
Gui, Cross1: Hide
Gui, Cross2: Hide
if !GetKeyState("LButton", "P")
    Return
WinGetActiveStats, Title, WindowWidth, WindowHeight, WindowX, WindowY
SetTimer, DrawRectangle, 20
Return

DrawRectangle: ; thx flyingDman
MouseGetPos, X2, Y2
Gui, +LastFound

X2<OriginX? (X1:=X2, X2:=OriginX): X1:=OriginX, Y2<OriginY? (Y1:=Y2, Y2:=OriginY): Y1:=OriginY
W1 := X2 - X1, H1 := Y2 - Y1, W2 := W1 - BW, H2 := H1 - BW
WinSet, Region, 0-0 %W1%-0 %W1%-%H1% 0-%H1% 0-0 %BW%-%BW% %W2%-%BW% %W2%-%H2% %BW%-%H2% %BW%-%BW%
If (FirstCall) {
    Gui, Show, NA x%X1% y%Y1% w%W1% h%H1%
	FirstCall := False
}
else WinMove, , , X1, Y1, W1, H1
Return

+LButton Up::
SetTimer, DrawRectangle, Off
Gui, Cancel
FirstCall := True
if GetKeyState("Shift", "P")
    Return
newbox:
count++
Gui box_%count%: -caption -DPIScale +AlwaysOnTop +resize ;+LabelGui +LastFound
        Gui box_%count%: Margin, 0,0
Gui box_%count%: color, black
Gui box_%count%: show, % "NA x" X1 " y" Y1 " w" W1-16 " h" H1-16, box_%count% ; offset (-16) might be PC/OS specific
currentgui:="box_" count
return

f1:: ; add a new box
w1:=100
h1:=100
x1:=a_screenwidth//2-w1//2
y1:=a_screenheight//2-h1//2
goto newbox
return

F2:: ; color the box with the top left pixel
     ; Long press (> 0.6 sec) highlight box in red
    transparency:=100  ; 0-255 level of transparency (0 =Transparent , 255=full visibile)

    KeyWait, F2, U T0.6    ; Long press (> 0.6 sec) 
    If ErrorLevel   
    {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent,%transparency% ; Set Box to transparency
        Gui, %currentgui%:Color, FF0000
    }
	else
	{
        WinGetPos,px,py,,, %currentgui%
        PixelGetColor, outcolor, % px-1, % py-1, RGB
        Gui,%currentgui%: +LastFound
        WinSet,Transparent,255 ; Set Box to No transparency
        Gui %currentgui%: color, % outcolor
    }
    
    KeyWait, F2, U T0.6   ;Wait no more than 0.6 sec for key release (also suppress auto-repeat)
return


f3:: ; freeze/unfreeze all boxes
freeze:=!freeze
if freeze
    loop, % count
        gui box_%a_index%: -resize
else
    loop, % count
        gui box_%a_index%: +resize
return

f4:: ; remove selected box
gui %currentgui%: Destroy ; Thx MancioDellaVega
return

F5:: ; show/hide all boxes
hide:=!hide
if hide
    loop, % count {
            Gui, box_%a_index%:Default
            gui box_%a_index% : -caption
            gui box_%a_index%: hide   
        }
else
    loop, % count {
            Gui, box_%a_index%:Default
            GuiGetPos( X,Y,W,H, "box_" a_index )
            gui box_%a_index%: show
            WinMove, box_%a_index%,,x,y,w,h
        }
return

f6:: ; make current box semi transparent
        transparency:=100  ; 0-255 level of transparency (0 =Transparent , 255=full visibile)
trans:=!Trans
if trans 
    {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent, %transparency% ; Set Box to transparency
    }
    else {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent, 255
    }
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f7:: ; save all boxes [ GuiVars.csv ]
GuisArr := []
arrCount := 0
res := ""
loop, % count {
WinGetPos,x1,y1,w1,h1, box_%a_index%
GuisArr["box_" a_index] := ("box_" a_index) "," x1 "," y1 "," w1 "," h1
}
for each, box in GuisArr {
   res .= box "`n"
kill := strSplit(box,",")

;         killThis :=  kill[1] ; option ; save and destroy all boxes

if killThis
try gui %killThis%: Destroy
;sleep, 100
tooltip % res
settimer, toolOff, -3000
try filedelete, GuiVars.csv
fileAppend,% res, GuiVars.csv
}
return

f8:: ; destroy all boxes
for each, guiVar in GuisArr 
gui box_%A_Index%: Destroy
count =
ToolTip
return

f9:: ; rebuild all boxes
for each, guiVar in GuisArr {
reBuild := strSplit(GuiVar,",")
if !reBuild[2]
continue
count++
Gui box_%count%: -caption -DPIScale +AlwaysOnTop +resize ;+LabelGui +LastFound
Gui box_%count%: color, black
Gui box_%count%: show, % "NA x" reBuild[2] " y" reBuild[3] " w" reBuild[4]-16 " h" reBuild[5]-16, box_%count% ; offset (-16) might be PC/OS specific
currentgui:="box_" count
}
return

f10:: ; todo - gespeichterte guis reload
;/*
GuisArr := []
count =
FileRead, guiVar, K:\Eigene Dateien\Autohotkey\Lib\GuiVars.csv
xSplit := strSplit(guiVar,"`n")

MsgBox,,%A_LineNumber%,% isObject(xSplit)
MsgBox,,%A_LineNumber%,% guiVar

for each, guiVar in xSplit 
{
split := strSplit(guiVar,",")
if !split[5]
continue
GuisArr["box_" a_index] := ("box_" a_index) "," split[2] "," split[3] "," split[4] "," split[5]
;MsgBox,,%A_LineNumber%,% GuisArr["box_" a_index] ,1
}
;*/
for each, guiVar in GuisArr 
{
split := strSplit((GuisArr["box_" a_index]),",")
if !split[5]
continue
;MsgBox,,%A_LineNumber%,% GuisArr["box_" a_index]
;MsgBox,,%A_LineNumber%,% split[1] "`n" split[2] "`n" split[3] "`n" split[4] "`n" split[5]
/*
w1:= split[4]
h1:= split[5]
x1:= split[2]
y1:= split[3]
goto newbox
*/
count++
Gui box_%count%: -caption -DPIScale +AlwaysOnTop +resize ;+LabelGui +LastFound
Gui box_%count%: color, black
Gui box_%count%: show, % "NA x" split[2] " y" split[3] " w" split[4]-16 " h" split[5]-16, box_%count% ; offset (-16) might be PC/OS specific
currentgui:="box_" count
}
return

/* ; GuiVars.csv
box_1,1916,0,14,786
box_2,1927,570,561,240
box_3,2469,740,720,84
box_4,3185,6,14,746
box_5,3051,569,137,180
box_6,1919,0,1270,114
*/

toolOff() {
tooltip
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

WM_LBUTTONDOWN() {
    global currentgui, freeze
    MouseGetPos, xpos, ypos 
¬:= (A_Gui) && currentgui:=a_gui
¬:= (A_Gui) && (!freeze)  && move()
}

move() { 
	PostMessage, 0xA1, 2 ; WM_NCLBUTTONDOWN
}

; thx Lexikos
; https://autohotkey.com/board/topic/23969-resizable-window-border/
; Sizes the client area to fill the entire window.
WM_NCCALCSIZE()
{
    if A_Gui
        return 0
}

; Prevents a border from being drawn when the window is activated.
WM_NCACTIVATE()
{
    if A_Gui
        return 1
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.
WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}


;thx VxE's , Icarus
GuiGetPos( ByRef X, ByRef Y, ByRef W, ByRef H, GuiID=1 ) {
	Gui %GuiID%:+LastFound Exist
	IfWinExist
	{
		WinGetPos X, Y
		VarSetCapacity( rect, 16, 0 )
		DllCall("GetClientRect", uint, MyGuiHWND := WinExist(), uint, &rect )
		W := NumGet( rect, 8, "int" )
		H := NumGet( rect, 12, "int" )
	}
}


return
guiclose:
~esc::
exitapp
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: CENSOR BOX erweitern

22 Oct 2021, 03:48

Moin effel,

ein paar Dinge, die mir aufgefallen sind:

Im Originalskript gbt es kein GuisArr. Bevor mindestens einmal F7:: ausgelöst wurde, existiert es nicht. Danach wird es von den Originalroutinen nicht mehr verändert.

In F9:: werden weder noch vorhanden Fenster zerstört noch wird der Fensterzähler count zurückgesetzt. Die im Array gespeicherten Fenster werden also hinzugefügt und ersetzen nicht die vorhandenen.

F7:: und F10:: verwenden unterschiedliche Pfade für das Speichern bzw. Lesen der CSV-Datei. Ob das gut geht, kann ich von hier aus nicht beurteilen. In F7:: wird die CSV-Datei außerdem für jedes Fenster erst gelöscht und danach neu geschrieben.

Vielleicht hift Dir das weiter.
effel
Posts: 537
Joined: 16 Jan 2018, 13:34

Re: CENSOR BOX erweitern

28 Oct 2021, 13:02

Hallo Just Me,
ich habe es auf eine ^F1 Taste begrenzt.

Meine Veränderungen am Original Script beschränken sich auf diese F Taste und das speichern jeder Box (beim erstellen) in CENSORBOX.csv

Ich habe es nun in verschiedenen Versionen probiert, aber egal was ich mache, ich kann den Vorgang nicht automatisieren.

Es sollen alle einmal erstellten Boxen, deren Koordinaten in einer Datei gespeichert wurden, nach Programm Neustart mit einem ^F1 Tastendruck wieder hergestellt werden.

Die zu sendenen Koordinaten sind vorhanden:
#1.png
#1.png (2.17 KiB) Viewed 1146 times
aber ich bekomme trotzdem eine Fehlermeldung:
#2.png
#2.png (18 KiB) Viewed 1146 times

Code: Select all

^f1::
thisCount := count
count=
loop, % thisCount
Gui, box_%a_index%:Destroy 
FileRead, BoxVar,% (A_ScriptDir "\CENSORBOX.csv")
loop, parse, BoxVar, `n 
{
IF !A_Loopfield
continue
split := strSplit(A_Loopfield,"`t")
W1:= split[3]
H1:= split[4]
X1:= split[1]
Y1:= split[2]
MsgBox,,%A_LineNumber%,% split[1] "`t" split[2] "`t" split[3] "`t" split[4]
gosub newbox
}
return

Code: Select all

; =================================================================================================================================
; Name:           CENSOR BOX 
; Description:    Hide parts of the screen with a colored box
; credits:        Speedmaster, Lexikos, flyingDman, rommmcek, MancioDellaVega
; Topic:          https://www.autohotkey.com/boards/viewtopic.php?f=6&t=78160
; Sript version:  1.4
; AHK Version:    1.1.24.03 (A32/U32/U64)
; Tested on:      Win 7 
; shortcuts::     F1 add a new box
;                 F2 color the box with the top left pixel
;                 F2 Long press (> 0.6 sec) highlight box in red
;                 F3 freeze/unfreeze all boxes
;                 F4 remove selected box
;                 F5 hide/show all boxes
;                 F6 make current box semi transparent
;                 Shift + Left Button show x-cross
;                 Shift Up (while LButton down) start drawing rectangle
;                 ESC exit script
;                 all boxes are resizable with the mouse

#SingleInstance force


OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")
OnMessage(0x86, "WM_NCACTIVATE")
CoordMode, pixel, screen
CoordMode, mouse, screen

BW := 2           				; Border width (and height) in pixels
BC := "FF8800"       			; Border color
FirstCall := True
Gui, -Caption  +LastFound +AlwaysOnTop
Gui, Color, %BC%

Gui, Cross1: -Caption +AlwaysOnTop 
Gui, Cross1: Color, % bc
Gui, Cross2: -Caption +AlwaysOnTop 
Gui, Cross2: Color, % bc
count:= 0
Return

+LButton::
While GetKeyState("Shift", "P") {
    MouseGetPos, OriginX, OriginY
    ;OriginX-=8, OriginY-=5
    Gui, Cross1: show, % "NA y0 w1 x" OriginX " h" A_ScreenHeight
    Gui, Cross2: show, % "NA x0 h1 y" OriginY " w" A_ScreenWidth
    Sleep, 10
}
Gui, Cross1: Hide
Gui, Cross2: Hide
if !GetKeyState("LButton", "P")
    Return
WinGetActiveStats, Title, WindowWidth, WindowHeight, WindowX, WindowY
SetTimer, DrawRectangle, 20
Return

DrawRectangle: ; thx flyingDman
MouseGetPos, X2, Y2
Gui, +LastFound

X2<OriginX? (X1:=X2, X2:=OriginX): X1:=OriginX, Y2<OriginY? (Y1:=Y2, Y2:=OriginY): Y1:=OriginY
W1 := X2 - X1, H1 := Y2 - Y1, W2 := W1 - BW, H2 := H1 - BW
WinSet, Region, 0-0 %W1%-0 %W1%-%H1% 0-%H1% 0-0 %BW%-%BW% %W2%-%BW% %W2%-%H2% %BW%-%H2% %BW%-%BW%
If (FirstCall) {
    Gui, Show, NA x%X1% y%Y1% w%W1% h%H1%
	FirstCall := False
}
else WinMove, , , X1, Y1, W1, H1
Return

+LButton Up::
SetTimer, DrawRectangle, Off
Gui, Cancel
FirstCall := True
if GetKeyState("Shift", "P")
    Return

newbox:
count++
Gui box_%count%: -caption -DPIScale +AlwaysOnTop +resize ;+LabelGui +LastFound
Gui box_%count%: Margin, 0,0
Gui box_%count%: color, black
Gui box_%count%: show, % "NA x" X1 " y" Y1 " w" W1-16 " h" H1-16, box_%count% ; offset (-16) might be PC/OS specific
currentgui:="box_" count
gosub RefreshThis
return

f1::
w1:=100
h1:=100
x1:=a_screenwidth//2-w1//2
y1:=a_screenheight//2-h1//2
goto newbox
return

^f1::
thisCount := count
count=
loop, % thisCount
Gui, box_%a_index%:Destroy 
FileRead, BoxVar,% (A_ScriptDir "\CENSORBOX.csv")
loop, parse, BoxVar, `n 
{
IF !A_Loopfield
continue
split := strSplit(A_Loopfield,"`t")
W1:= split[3]
H1:= split[4]
X1:= split[1]
Y1:= split[2]
MsgBox,,%A_LineNumber%,% split[1] "`t" split[2] "`t" split[3] "`t" split[4]
gosub newbox
}
return

RefreshThis:
BoxVar := ""
    loop, % Count {
            Gui, box_%a_index%:Default
            GuiGetPos( xX,yY,wW,hH, "box_" a_index )
            if !((xX=0) and (yY=0) and (wW=0) and (wW=0))
            BoxVar .= xX "`t" yY "`t" wW "`t" hH "`n"
            if FileExist(A_ScriptDir "\CENSORBOX.csv")
            FileDelete,% (A_ScriptDir "\CENSORBOX.csv")
            FileAppend,% BoxVar,% (A_ScriptDir "\CENSORBOX.csv")
        }
            tooltip % BoxVar 
            settimer, toolTipOff, -5000
    return

toolTipOff() {
tooltip
}

F2::
    transparency:=100  ; 0-255 level of transparency (0 =Transparent , 255=full visibile)

    KeyWait, F2, U T0.6    ; Long press (> 0.6 sec) 
    If ErrorLevel   
    {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent,%transparency% ; Set Box to transparency
        Gui, %currentgui%:Color, FF0000
    }
	else
	{
        WinGetPos,px,py,,, %currentgui%
        PixelGetColor, outcolor, % px-1, % py-1, RGB
        Gui,%currentgui%: +LastFound
        WinSet,Transparent,255 ; Set Box to No transparency
        Gui %currentgui%: color, % outcolor
    }
    
    KeyWait, F2, U T0.6   ;Wait no more than 0.6 sec for key release (also suppress auto-repeat)
return


f3::
freeze:=!freeze
if freeze 
    loop, % count
        gui box_%a_index%: -resize
else 
    loop, % count
        gui box_%a_index%: +resize
return

f4::
gui %currentgui%: Destroy ; Thx MancioDellaVega
gosub RefreshThis
return

F5::
hide:=!hide
if hide
    loop, % count {
            Gui, box_%a_index%:Default
            gui box_%a_index% : -caption
            gui box_%a_index%: hide   
        }
else
    loop, % count {
            Gui, box_%a_index%:Default
            GuiGetPos( X,Y,W,H, "box_" a_index )
            gui box_%a_index%: show
            WinMove, box_%a_index%,,x,y,w,h
        }
return

f6::
        transparency:=100  ; 0-255 level of transparency (0 =Transparent , 255=full visibile)
trans:=!Trans
if trans 
    {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent, %transparency% ; Set Box to transparency
    }
    else {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent, 255
    }
return

WM_LBUTTONDOWN() {
    global currentgui, freeze
    MouseGetPos, xpos, ypos 
¬:= (A_Gui) && currentgui:=a_gui
¬:= (A_Gui) && (!freeze)  && move()
}

move() { 
	PostMessage, 0xA1, 2 ; WM_NCLBUTTONDOWN
}

; thx Lexikos
; https://autohotkey.com/board/topic/23969-resizable-window-border/
; Sizes the client area to fill the entire window.
WM_NCCALCSIZE()
{
    if A_Gui
        return 0
}

; Prevents a border from being drawn when the window is activated.
WM_NCACTIVATE()
{
    if A_Gui
        return 1
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.
WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}


;thx VxE's , Icarus
GuiGetPos( ByRef X, ByRef Y, ByRef W, ByRef H, GuiID=1 ) {
	Gui %GuiID%:+LastFound Exist
	IfWinExist
	{
		WinGetPos X, Y
		VarSetCapacity( rect, 16, 0 )
		DllCall("GetClientRect", uint, MyGuiHWND := WinExist(), uint, &rect )
		W := NumGet( rect, 8, "int" )
		H := NumGet( rect, 12, "int" )
	}
}


return
guiclose:
~esc::
exitapp
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: CENSOR BOX erweitern  Topic is solved

29 Oct 2021, 02:38

Moin @effel,

der Zeilenwechsel in Textdateien besteht für Windows aus zwei Zeichen: CR / `r und LF / `n.

Code: Select all

loop, parse, BoxVar, `n
entfernt nur das`n vom Zeilenende und lässt das `r stehen. Nach dem

Code: Select all

split := strSplit(A_Loopfield,"`t")
hängt an Split[4] deshalb ebendieses `r. Das wird auch nach H1 übertragen und führt zur Fehlermeldung.

Deshalb, wann immer man den Inhalt von Textdateien zeilenweise parsen will:

Code: Select all

loop, parse, BoxVar, `n, `r
effel
Posts: 537
Joined: 16 Jan 2018, 13:34

Re: CENSOR BOX erweitern

31 Oct 2021, 00:14

Danke Just Me, das war genau mein Problem.

Ich habe den Code weiter modifiziert und versuche auch die Farben und den Transparenten Status mit abzuspeichern.

Das läuft noch nicht rund kann sich aber schon sehen lassen. Ich poste mal den Zwischenstand:

Code: Select all

SetBatchLines, -1
; =================================================================================================================================
; Name:           CENSOR BOX 
; Description:    Hide parts of the screen with a colored box
; credits:        Speedmaster, Lexikos, flyingDman, rommmcek, MancioDellaVega
; Topic:          https://www.autohotkey.com/boards/viewtopic.php?f=6&t=78160
; Sript version:  1.4
; AHK Version:    1.1.24.03 (A32/U32/U64)
; Tested on:      Win 7 
; shortcuts::     F1 add a new box
;                 F2 color the box with the top left pixel
;                 F2 Long press (> 0.6 sec) highlight box in red
;                 F3 freeze/unfreeze all boxes
;                 F4 remove selected box
;                 F5 hide/show all boxes
;                 F6 make current box semi transparent
;                 Shift + Left Button show x-cross
;                 Shift Up (while LButton down) start drawing rectangle
;                 ESC exit script
;                 all boxes are resizable with the mouse

#SingleInstance force

if !fileExist(A_ScriptDir "\CENSORBOX - default.csv")
fileAppend, 838	423	98	98	0xFF0000	1`n484	336	98	98	0x000000	0
          ,% (A_ScriptDir "\CENSORBOX - default.csv")

transparency:=100

OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")
OnMessage(0x86, "WM_NCACTIVATE")
CoordMode, pixel, screen
CoordMode, mouse, screen

BW := 2           				; Border width (and height) in pixels
BC := "FF8800"       			; Border color
FirstCall := True
Gui, -Caption  +LastFound +AlwaysOnTop
Gui, Color, %BC%

Gui, Cross1: -Caption +AlwaysOnTop 
Gui, Cross1: Color, % bc
Gui, Cross2: -Caption +AlwaysOnTop 
Gui, Cross2: Color, % bc
count:= 0
goto ^F1
Return

+LButton::
While GetKeyState("Shift", "P") {
    MouseGetPos, OriginX, OriginY
    ;OriginX-=8, OriginY-=5
    Gui, Cross1: show, % "NA y0 w1 x" OriginX " h" A_ScreenHeight
    Gui, Cross2: show, % "NA x0 h1 y" OriginY " w" A_ScreenWidth
    Sleep, 10
}
Gui, Cross1: Hide
Gui, Cross2: Hide
if !GetKeyState("LButton", "P")
    Return
WinGetActiveStats, Title, WindowWidth, WindowHeight, WindowX, WindowY
SetTimer, DrawRectangle, 20
Return

DrawRectangle: ; thx flyingDman
MouseGetPos, X2, Y2
Gui, +LastFound

X2<OriginX? (X1:=X2, X2:=OriginX): X1:=OriginX, Y2<OriginY? (Y1:=Y2, Y2:=OriginY): Y1:=OriginY
W1 := X2 - X1, H1 := Y2 - Y1, W2 := W1 - BW, H2 := H1 - BW
WinSet, Region, 0-0 %W1%-0 %W1%-%H1% 0-%H1% 0-0 %BW%-%BW% %W2%-%BW% %W2%-%H2% %BW%-%H2% %BW%-%BW%
If (FirstCall) {
    Gui, Show, NA x%X1% y%Y1% w%W1% h%H1%
	FirstCall := False
}
else WinMove, , , X1, Y1, W1, H1
Return

+LButton Up::
SetTimer, DrawRectangle, Off
Gui, Cancel
FirstCall := True
if GetKeyState("Shift", "P")
    Return

newbox:
count++
Gui box_%count%: -caption -DPIScale +AlwaysOnTop +resize ;+LabelGui +LastFound
Gui box_%count%: Margin, 0,0
Gui box_%count%: color, black
Gui box_%count%: show, % "NA x" x1 " y" y1 " w" w1-16 " h" h1-16, box_%count% ; offset (-16) might be PC/OS specific
currentgui:="box_" count
if (split[5]="0x000000")
{
        Gui,box_%count%: +LastFound
        WinSet,Transparent,255 ; Set Box to transparency
        Gui, box_%count%:Color, 0x000000
}else{
        Gui,box_%count%: +LastFound
        WinSet,Transparent,%transparency% ; Set Box to transparency
        Gui, box_%count%:Color,% split[5]
}
gosub RefreshThis
return

f1::
w1:=100
h1:=100
x1:=a_screenwidth//2-w1//2
y1:=a_screenheight//2-h1//2
goto newbox
return

^f1::
thisCount := count
count=
loop, % thisCount
Gui, box_%a_index%:Destroy 
LoadDefault := true
if LoadDefault
FileRead, BoxVar,% (A_ScriptDir "\CENSORBOX - default.csv")
else
FileRead, BoxVar,% (A_ScriptDir "\CENSORBOX - default - Kopie.csv")
loop, parse, BoxVar, `n, `r
{
IF !A_Loopfield
continue
split := strSplit(A_Loopfield,"`t")
w1:= split[3]+2
h1:= split[4]+2
x1:= split[1]
y1:= split[2]
ReadColor:= split[5]
istransparency := split[6]
ToolTip % "A_LineNumber : " A_LineNumber "`n" split[1] "`t" split[2] "`t" split[3] "`t" split[4] "`t" split[5] "`t" split[6]
settimer, toolTipOff, -2000
gosub newbox
}
return

RefreshThis:
BoxVar := ""
    loop, % Count {
            Gui, box_%a_index%:Default
            GuiGetPos( xX,yY,wW,hH, "box_" a_index )
            PixelGetColor, outcolor,  xX,  yY, RGB
            if ((xX=0) and (yY=0) and (wW=0) and (wW=0))
continue
            if inStr(outcolor, "0x000000")
            BoxVar .= xX "`t" yY "`t" wW "`t" hH "`t" outcolor "`t" false "`n"
            else
            BoxVar .= xX "`t" yY "`t" wW "`t" hH "`t" "0xFF0000" "`t" true "`n"
outcolor=
        }
             if FileExist(A_ScriptDir "\CENSORBOX.csv")
            FileDelete,% (A_ScriptDir "\CENSORBOX.csv")
            FileAppend,% BoxVar,% (A_ScriptDir "\CENSORBOX.csv")
           tooltip % BoxVar 
            settimer, toolTipOff, -5000
    return

toolTipOff() {
tooltip
}

F2::
  ;  transparency:=100  ; 0-255 level of transparency (0 =Transparent , 255=full visibile)

    KeyWait, F2, U T0.6    ; Long press (> 0.6 sec) 
    If ErrorLevel   
    {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent,%transparency% ; Set Box to transparency
        Gui, %currentgui%:Color, 0x000000
;       Gui, %currentgui%:Color, 0xFF9B9B
    }
	else
	{
        WinGetPos,px,py,,, %currentgui%
        PixelGetColor, outcolor, % px-1, % py-1, RGB
        Gui,%currentgui%: +LastFound
        WinSet,Transparent,255 ; Set Box to No transparency
;        Gui %currentgui%: color, % outcolor
        Gui %currentgui%: color, 0x000000
    }
    
    KeyWait, F2, U T0.6   ;Wait no more than 0.6 sec for key release (also suppress auto-repeat)
gosub RefreshThis
return


f3::
freeze:=!freeze
if freeze 
    loop, % count
        gui box_%a_index%: -resize
else 
    loop, % count
        gui box_%a_index%: +resize
gosub RefreshThis
return

f4::
gui %currentgui%: Destroy ; Thx MancioDellaVega
gosub RefreshThis
return

F5::
hide:=!hide
if hide
    loop, % count {
            Gui, box_%a_index%:Default
            gui box_%a_index% : -caption
            gui box_%a_index%: hide   
        }
else
    loop, % count {
            Gui, box_%a_index%:Default
            GuiGetPos( X,Y,W,H, "box_" a_index )
            gui box_%a_index%: show
            WinMove, box_%a_index%,,x,y,w,h
        }
gosub RefreshThis
return

f6::
        transparency:=100  ; 0-255 level of transparency (0 =Transparent , 255=full visibile)
trans:=!Trans
if trans 
    {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent, %transparency% ; Set Box to transparency
    }
    else {
        Gui,%currentgui%: +LastFound
        WinSet,Transparent, 255
    }
gosub RefreshThis
return

WM_LBUTTONDOWN() {
    global currentgui, freeze
    MouseGetPos, xpos, ypos 
¬:= (A_Gui) && currentgui:=a_gui
¬:= (A_Gui) && (!freeze)  && move()
}

move() { 
	PostMessage, 0xA1, 2 ; WM_NCLBUTTONDOWN
gosub RefreshThis
}

; thx Lexikos
; https://autohotkey.com/board/topic/23969-resizable-window-border/
; Sizes the client area to fill the entire window.
WM_NCCALCSIZE()
{
gosub RefreshThis
    if A_Gui
        return 0
}

; Prevents a border from being drawn when the window is activated.
WM_NCACTIVATE()
{
    if A_Gui
        return 1
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.
WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}


;thx VxE's , Icarus
GuiGetPos( ByRef X, ByRef Y, ByRef W, ByRef H, GuiID=1 ) {
	Gui %GuiID%:+LastFound Exist
	IfWinExist
	{
		WinGetPos X, Y
		VarSetCapacity( rect, 16, 0 )
		DllCall("GetClientRect", uint, MyGuiHWND := WinExist(), uint, &rect )
		W := NumGet( rect, 8, "int" )
		H := NumGet( rect, 12, "int" )
	}
}


return
guiclose:
~esc::
exitapp
farbenSpiele.png
farbenSpiele.png (20.65 KiB) Viewed 1066 times

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: gero and 25 guests