Что нового

[Элементы GUI] Показ содержимого буфера обмена на экране

YangierBola

Новичок
Сообщения
1
Репутация
0
Имеется скрипт, который отображает текущее содержимое буфера обмена на экране. Через некоторое время скрипт зависает, не могу найти где ошибка:
Код:
Opt("OnExitFunc", "endscript")

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

HotKeySet('{Esc}', '_Exit')


$hwnd = GUICreate("Text Region", 740, 25, 255, 538, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_CONTROLPARENT))
GUISetBkColor(0x000000)
GUISetState()

While 1
    $rgn = CreateTextRgn($hwnd, ClipGet(), 18, "Arial", 600)
    SetWindowRgn($hwnd, $rgn) 
    Sleep(300)
WEnd

Func endscript()
    ControlShow("Program Manager", "", "[CLASSNN:SHELLDLL_DefView1]")
EndFunc   ;==>endscript

Func SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc   ;==>SetWindowRgn

Func CreateTextRgn(ByRef $CTR_hwnd, $CTR_Text, $CTR_height, $CTR_font = "Times New Roman", $CTR_weight = 1000)
    Local Const $ANSI_CHARSET = 1
    Local Const $OUT_CHARACTER_PRECIS = 2
    Local Const $CLIP_DEFAULT_PRECIS = 0
    Local Const $PROOF_QUALITY = 2
    Local Const $FIXED_PITCH = 1
    Local Const $RGN_XOR = 3

    If $CTR_font = "" Then $CTR_font = "Microsoft Sans Serif"
    If $CTR_weight = -1 Then $CTR_weight = 1000
    Local $gdi_dll = DllOpen("gdi32.dll")
    Local $CTR_hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $CTR_hwnd)
    Local $CTR_hMyFont = DllCall($gdi_dll, "hwnd", "CreateFont", "int", $CTR_height, "int", 0, "int", 0, "int", 0, _
            "int", $CTR_weight, "int", 0, "int", 0, "int", 0, "int", $ANSI_CHARSET, "int", $OUT_CHARACTER_PRECIS, _
            "int", $CLIP_DEFAULT_PRECIS, "int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $CTR_font)
    Local $CTR_hOldFont = DllCall($gdi_dll, "hwnd", "SelectObject", "int", $CTR_hDC[0], "hwnd", $CTR_hMyFont[0])
    DllCall($gdi_dll, "int", "BeginPath", "int", $CTR_hDC[0])
    DllCall($gdi_dll, "int", "TextOut", "int", $CTR_hDC[0], "int", 0, "int", 0, "str", $CTR_Text, "int", StringLen($CTR_Text))
    DllCall($gdi_dll, "int", "EndPath", "int", $CTR_hDC[0])
    Local $CTR_hRgn1 = DllCall($gdi_dll, "hwnd", "PathToRegion", "int", $CTR_hDC[0])
    Local $CTR_rc = DllStructCreate("int;int;int;int")
    DllCall($gdi_dll, "int", "GetRgnBox", "hwnd", $CTR_hRgn1[0], "ptr", DllStructGetPtr($CTR_rc))
    Local $CTR_hRgn2 = DllCall($gdi_dll, "hwnd", "CreateRectRgnIndirect", "ptr", DllStructGetPtr($CTR_rc))
    DllCall($gdi_dll, "int", "CombineRgn", "hwnd", $CTR_hRgn2[0], "hwnd", $CTR_hRgn2[0], "hwnd", $CTR_hRgn1[0], "int", $RGN_XOR)
    DllCall($gdi_dll, "int", "DeleteObject", "hwnd", $CTR_hRgn1[0])
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $CTR_hwnd, "int", $CTR_hDC[0])
    DllCall($gdi_dll, "int", "SelectObject", "int", $CTR_hDC[0], "hwnd", $CTR_hOldFont[0])
    DllClose($gdi_dll)
    Return $CTR_hRgn2[0]
EndFunc   ;==>CreateTextRgn

Func _Exit()
    Exit
EndFunc
 

InnI

AutoIT Гуру
Сообщения
4,948
Репутация
1,443
YangierBola [?]
Шрифт не удалялся - происходила утечка объектов GDI
Код:
...
    DllCall($gdi_dll, "int", "DeleteObject", "hwnd", $CTR_hRgn1[0])
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $CTR_hwnd, "int", $CTR_hDC[0])
    DllCall($gdi_dll, "int", "SelectObject", "int", $CTR_hDC[0], "hwnd", $CTR_hOldFont[0])
    DllCall($gdi_dll, "int", "DeleteObject", "hwnd", $CTR_hMyFont[0]) ; <================= добавить удаление шрифта
    DllClose($gdi_dll)
    Return $CTR_hRgn2[0]
EndFunc   ;==>CreateTextRgn
 
Верх