#include <ProgressConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiConstants.au3>
#include <ButtonConstants.au3>
#include <BorderConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <ComboConstants.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#include <WinApi.au3>
#Include <Misc.au3>
Global $Color = 0x0
Global $hSquare_GUI = 0
Global $CurWin = 0 ;保存所在窗口
Global $CurWinPos[2] = [-1, -1] ;窗口位置
While 1
Sleep(200)
If $Color = 0xFFFFFF Then
$Color =0xFF0000
Else
$Color = 0xFFFFFF
If $hSquare_GUI <> 0 Then GUISetState(@SW_HIDE, $hSquare_GUI) ;隐藏边框
ContinueLoop
EndIf
Global $Struct = DllStructCreate($tagPoint)
DllStructSetData($Struct, "x", MouseGetPos(0))
DllStructSetData($Struct, "y", MouseGetPos(1))
$hWinCtrl = _WinAPI_WindowFromPoint($Struct)
Local $aCtrlPos = WinGetPos($hWinCtrl)
;当鼠标移到其他窗口,或所在窗口位置改变,重绘边框,否则显示边框
If $CurWin <> $hWinCtrl Or ($aCtrlPos[0] <> $CurWinPos[0] Or $aCtrlPos[1] <> $CurWinPos[1]) Then
$CurWin = $hWinCtrl
GUIDelete($hSquare_GUI)
$hSquare_GUI = 0
$CurWinPos[0] = $aCtrlPos[0]
$CurWinPos[1] = $aCtrlPos[1]
GUICreateSquare($aCtrlPos[0], $aCtrlPos[1], $aCtrlPos[2], $aCtrlPos[3], $Color)
Else
If $hSquare_GUI <> 0 Then GUISetState(@SW_SHOWNOACTIVATE, $hSquare_GUI) ;显示边框
EndIf
WEnd
Func GUICreateSquare($i_X=-1, $i_Y=-1, $i_W=-1, $i_H=-1, $sColor=0x0)
$hSquare_GUI = GUICreate("", $i_W, $i_H, $i_X, $i_Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
Local $Frame_Width = 3
GUISetBkColor($sColor)
_GUISetHole($hSquare_GUI, $Frame_Width, $Frame_Width, $i_W - ($Frame_Width * 2), $i_H - ($Frame_Width * 2))
GUISetState(@SW_SHOWNOACTIVATE, $hSquare_GUI)
EndFunc
;裁剪
Func _GUISetHole(ByRef $hWin, $i_X, $i_Y, $i_SizeW, $i_SizeH)
Local $aWinPos, $Outer_Rgn, $Inner_Rgn, $Wh, $Combined_Rgn
Local Const $RGN_DIFF = 4
$aWinPos = WinGetPos($hWin)
$Outer_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", $aWinPos[2], "long", $aWinPos[3])
$Inner_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $i_X, "long", $i_Y, "long", $i_Y + $i_SizeW, "long", $i_Y + $i_SizeH)
$Combined_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
DllCall("gdi32.dll", "long", "CombineRgn", "long", $Combined_Rgn[0], "long", $Outer_Rgn[0], "long", $Inner_Rgn[0], "int", $RGN_DIFF)
DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWin, "long", $Combined_Rgn[0], "int", 1)
EndFunc