Что нового

Нарисовать текст на экране

musicstashall

Знающий
Сообщения
322
Репутация
7
Всем привет.
Как нарисовать такой же текст на экране, но без фона, только буквы?

Код:
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>

_DrawText('Hello world', 80, 'Verdana', 0xFFFFFF, 3000)

;===================================================
; Параметры:    $Text   - Текст.
;               $Size   - Размер текста.
;               $Font   - Шрифт текста.
;               $Color  - Цвет текста.
;               $Time   - Время отображения текста.
;===================================================
Func _DrawText($Text, $Size, $Font, $Color, $Time)
    $tRECT = DllStructCreate($tagRect)
    DllStructSetData($tRECT, "Left", 0)
    DllStructSetData($tRECT, "Top", (@DesktopHeight / 2) - ($Size / 2))
    DllStructSetData($tRECT, "Right", @DesktopWidth)
    DllStructSetData($tRECT, "Bottom", @DesktopHeight)

    $hDC = _WinAPI_GetDC(0)
    $hFont = _WinAPI_CreateFont($Size, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, _
            $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, $Font)
    $hOldFont = _WinAPI_SelectObject($hDC, $hFont)

    _WinAPI_SetTextColor($hDC, $Color)
    _WinAPI_SetBkColor($hDC, 0x000000)
    _WinAPI_SetBkMode($hDC, $TRANSPARENT)

    $init = TimerInit()
    Do
        _WinAPI_DrawText($hDC, $Text, $tRECT, $DT_CENTER)
        Sleep(100)
    Until TimerDiff($init) > $Time

    _WinAPI_SelectObject($hDC, $hOldFont)
    _WinAPI_DeleteObject($hFont)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_InvalidateRect(0, 0)
    $tRECT = 0
EndFunc


Окно, в качестве подложки, нежелательно.
 
Автор
M

musicstashall

Знающий
Сообщения
322
Репутация
7
На оф сайте нашел старый UDF FreeText.au3, вроде бы всё устраивает, но текст совсем без сглаживания, не красиво, всё портит.
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
musicstashall
текст будет меняться или один и тот же?
 
Автор
M

musicstashall

Знающий
Сообщения
322
Репутация
7
Текст динамический, будет меняться.


Добавлено:
Сообщение автоматически объединено:

Нашел на оф сайте примерчик и на его основе сделал такой вот UDF:

Код:
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>
;~ Global Const $WS_POPUP                = 0x80000000
;~ Global Const $WS_EX_TOOLWINDOW            = 0x00000080
;~ Global Const $WS_EX_TOPMOST                = 0x00000008

Local $__asData[0][4]

Func _FloatingTextCrate($aText = 'Text', $aX = -1, $aY = -1, $CTR_height = 100, $CTR_font="Microsoft Sans Serif", $sColor = '0x' & Hex(_WinAPI_GetSysColor($COLOR_WINDOWTEXT), 6))
	Local $sLong = StringLen($aText)
	$aWidth = $CTR_height * $sLong * 0.50
	Local $hwnd = GUICreate("", $aWidth, $CTR_height, $aX, $aY, $WS_POPUP, BitOR($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
	GUISetBkColor($sColor) ; text color
	$rgn = CreateTextRgn($hwnd, $aText, $CTR_height, $CTR_font, $aWidth)
	SetWindowRgn($hwnd,$rgn)
	GUISetState()
	_ArrayAdd($__asData, $hwnd & '|' & $CTR_height & '|' & $CTR_font & '|' & $sColor)
	Return $hwnd
EndFunc

Func _FloatingTextSetText($hwnd, $aText, $CTR_height = '', $CTR_font = '', $sColor = '')
	Local $i = _ArraySearch($__asData, $hwnd, 0, 0, 0, 0, 1, 0)
	If $i > -1 Then 
		If $CTR_height = '' Then $CTR_height = $__asData[$i][1]
		If $CTR_font = '' Then $CTR_font = $__asData[$i][2]	
		If $sColor = '' Then $sColor = $__asData[$i][3]		
	Else
		Return -1		
	EndIf
	Local $sLong = StringLen($aText)
	$CTR_weight = $CTR_height * $sLong * 0.50
	GUISetBkColor($sColor) ; text color
	$rgn = CreateTextRgn($hwnd, $aText, $CTR_height, $CTR_font, $CTR_weight)
	SetWindowRgn($hwnd,$rgn)
EndFunc

Func _FloatingTextDelete($hwnd)
	Local $i = _ArraySearch($__asData, $hwnd, 0, 0, 0, 0, 1, 0)
	If $i > -1 Then 
		_ArrayDelete($__asData, $i)
		GUIDelete($hwnd)
	Else
		Return -1	
	EndIf
EndFunc

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

;Func CombineRgn(ByRef $rgn1, ByRef $rgn2)
;    DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 2)
;EndFunc

Func CreateTextRgn(ByRef $CTR_hwnd,$CTR_Text,$CTR_height,$CTR_font="Microsoft Sans Serif",$CTR_weight=1000)
    Local Const $ANSI_CHARSET = 0
    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


Рисует на окне, но оно обрезается по буквам и нигде никогда не появится, например, если применить _WinAPI_DwmEnableBlurBehindWindow(). Меня вполне устраивает.
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
примерная реализация кода на 3.3.12.0

Код:
#include <GUIConstants.au3>
#include <Array.au3>
#include <FontConstants.au3>
#include <WinAPIEx.au3>

Global $__asData[0][4]
HotKeySet('{ESC}', '_exit')
Local $hGui = _FloatingTextCrate('Wait', -1, -1, 100, 'Arial Black', 0xFF0000)
Local $t = 0
Sleep(3000)
While 1
	_FloatingTextSetText($hGui, $t, 100, 'Microsoft Sans Serif', 0x0000FF)
	Sleep(1000)
	$t += 1
WEnd
Func _exit()
	Exit
EndFunc   ;==>_exit


Func _FloatingTextCrate($aText = 'Text', $aX = -1, $aY = -1, $CTR_height = 100, $CTR_font = "Microsoft Sans Serif", $sColor = '0x' & Hex(_WinAPI_GetSysColor($COLOR_WINDOWTEXT), 6))
	Local $sLong = StringLen($aText)
	Local $aWidth = $CTR_height * $sLong * 0.5
	Local $hwnd = GUICreate("", $aWidth, $CTR_height, $aX, $aY, $WS_POPUP, $WS_EX_TOPMOST)
	GUISetBkColor($sColor) ; text color
	$rgn = CreateTextRgn($hwnd, $aText, $CTR_height, $CTR_font, $aWidth)
	_WinAPI_SetWindowRgn($hwnd, $rgn)
	_WinAPI_DeleteObject($rgn)
	GUISetState()
	_ArrayAdd($__asData, $hwnd & '|' & $CTR_height & '|' & $CTR_font & '|' & $sColor)
	Return $hwnd
EndFunc   ;==>_FloatingTextCrate

Func _FloatingTextSetText($hwnd, $aText, $CTR_height = '', $CTR_font = '', $sColor = '')
	Local $i = _ArraySearch($__asData, $hwnd, 0, 0, 0, 0, 1, 0)
	If $i > -1 Then
		If $CTR_height = '' Then $CTR_height = $__asData[$i][1]
		If $CTR_font = '' Then $CTR_font = $__asData[$i][2]
		If $sColor = '' Then $sColor = $__asData[$i][3]
	Else
		Return -1
	EndIf
	Local $sLong = StringLen($aText)
	$CTR_weight = $CTR_height * $sLong * 0.5
	GUISetBkColor($sColor) ; text color
	$rgn = CreateTextRgn($hwnd, $aText, $CTR_height, $CTR_font, $CTR_weight)
	_WinAPI_SetWindowRgn($hwnd, $rgn)
	_WinAPI_DeleteObject($rgn)
EndFunc   ;==>_FloatingTextSetText

Func _FloatingTextDelete($hwnd)
	Local $i = _ArraySearch($__asData, $hwnd, 0, 0, 0, 0, 1, 0)
	If $i > -1 Then
		_ArrayDelete($__asData, $i)
		GUIDelete($hwnd)
	Else
		Return -1
	EndIf
EndFunc   ;==>_FloatingTextDelete

Func CreateTextRgn(ByRef $CTR_hwnd, $CTR_Text, $CTR_height, $CTR_font = "Microsoft Sans Serif", $CTR_weight = 1000)
	If $CTR_font = "" Then $CTR_font = "Microsoft Sans Serif"
	If $CTR_weight = -1 Then $CTR_weight = 1000
	Local $CTR_hDC = _WinAPI_GetDC($CTR_hwnd)
	Local $CTR_hMyFont = _WinAPI_CreateFont($CTR_height, 0, 0, 0, $CTR_weight, False, False, False, $DEFAULT_CHARSET, _
			$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, $CTR_font)
	Local $CTR_hOldFont = _WinAPI_SelectObject($CTR_hDC, $CTR_hMyFont)
	_WinAPI_BeginPath($CTR_hDC)
	_WinAPI_TextOut($CTR_hDC, 0, 0, $CTR_Text)
	_WinAPI_EndPath($CTR_hDC)
	Local $CTR_hRgn1 = _WinAPI_PathToRegion($CTR_hDC)
	Local $CTR_rc = DllStructCreate("int;int;int;int")
	_WinAPI_GetRgnBox($CTR_hRgn1, $CTR_rc)
	Local $CTR_hRgn2 = _WinAPI_CreateRectRgnIndirect($CTR_rc)
	_WinAPI_CombineRgn($CTR_hRgn2, $CTR_hRgn2, $CTR_hRgn1, $RGN_XOR)
	_WinAPI_DeleteObject($CTR_hRgn1)
	_WinAPI_ReleaseDC($CTR_hwnd, $CTR_hDC)
	_WinAPI_SelectObject($CTR_hDC, $CTR_hOldFont)
	Return $CTR_hRgn2
EndFunc   ;==>CreateTextRgn
 

InnI

AutoIT Гуру
Сообщения
4,912
Репутация
1,429
musicstashall
Нашел на оф сайте примерчик
Сложный, какой-то, примерчик. В справке к функции _GDIPlus_GraphicsDrawStringEx есть попроще примерчик. Вот код на его основе
Код:
#include <GDIPlus.au3>

_GDIPlus_Startup()

$sString = "Simple Text"
$hDC = _WinAPI_GetDC(0)
$hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 72, 1)
$tLayout = _GDIPlus_RectFCreate(100, 100, 0, 0)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)

Sleep(3333)

_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_ReleaseDC(0, $hDC)

ControlSend(WinGetHandle("Program Manager"), "", "", "{F5}")

_GDIPlus_Shutdown()
 
Автор
M

musicstashall

Знающий
Сообщения
322
Репутация
7
InnI сказал(а):
В справке к функции _GDIPlus_GraphicsDrawStringEx есть попроще примерчик.

Благодарю. Я пересмотрел эти примеры, они все мерцают, так как, видимо, приходится бороться с перерисовкой рабочего стола. Или я что-то недоразумею??
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
musicstashall
мерцает рабочий стол, для стирания текст используется обновление рабочего стола.
вообще, если использовать GDI, то нужна будет функция стирания текста - RedrawWindow
для нее нужно будет указать структуру с координатами обновления.
 

InnI

AutoIT Гуру
Сообщения
4,912
Репутация
1,429
musicstashall
они все мерцают
Вы просили нарисовать текст. На короткое время. Такой же, но без фона. А попробуйте запустить функцию _DrawText() в цикле или откройте любое окно поверх этого текста. ;)

Вот без мерцания. Если хотите кликать сквозь текст, то добавьте окну GUI стиль $WS_EX_TRANSPARENT. Но тогда пропадёт возможность перемещения текста мышью
Код:
#include <GDIPlus.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()
$sString = "Simple Text"
$hDC = _WinAPI_GetDC(0)
$hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 72, 1)
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
$iWidth = $aInfo[0].Width
$iHeight = $aInfo[0].Height
$hImage = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
$hGraph = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsDrawStringEx($hGraph, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
$GUI = GUICreate("", $iWidth, $iHeight, 100, 100, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_CONTROLPARENT))
_WinAPI_UpdateLayeredWindowEx($GUI, -1, -1, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 255, True)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hGraph)
_GDIPlus_ImageDispose($hImage)
_WinAPI_ReleaseDC(0, $hDC)
_GDIPlus_Shutdown()
GUISetState()
Do
Until GUIGetMsg() = -3
 
Автор
M

musicstashall

Знающий
Сообщения
322
Репутация
7
Inni, а теперь попробуйте применить к окну _WinAPI_DwmEnableBlurBehindWindow()....
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
musicstashall [?]
_WinAPI_DwmEnableBlurBehindWindow()....
Код:
_WinAPI_DwmEnableBlurBehindWindow($GUI,False)

останется прозрачным
А что ты хочешь достичь этой функцией?
 

InnI

AutoIT Гуру
Сообщения
4,912
Репутация
1,429
musicstashall
попробуйте применить к окну _WinAPI_DwmEnableBlurBehindWindow
На Win7 замечательно применяется. На Win10, да, фон становится чёрным. Но на Win10 и пример из справки не работает.

Хорошо. Вот окно с постоянно прозрачным фоном. Даже EnableBlur на него не действует
Код:
#include <GDIPlus.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()
$sString = "Simple Text"
$tLayout = _GDIPlus_RectFCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 1, 72)
$aBounds = _GDIPlus_PathGetWorldBounds($hPath)
$iWidth = $aBounds[2] + $aBounds[0] * 2
$iHeight = $aBounds[3] + $aBounds[1] * 2
$GUI = GUICreate("", $iWidth, $iHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_CONTROLPARENT))
GUISetState()
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($GUI)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
_GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush)
$hRegion = _GDIPlus_RegionCreateFromPath($hPath)
$hRgn = _GDIPlus_RegionGetHRgn($hRegion)
_WinAPI_SetWindowRgn($GUI, $hRGN)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_RegionDispose($hRegion)
_WinAPI_DeleteObject($hRgn)

;~ Sleep(2222)
;~ _WinAPI_DwmEnableBlurBehindWindow($GUI, 1)
;~ ConsoleWrite("DwmEnableBlur" & @CRLF)

Do
Until GUIGetMsg() = -3

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_PathDispose($hPath)
_GDIPlus_Shutdown()

Func WM_ERASEBKGND()
  _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush)
  Return 1
EndFunc
В случае применения стиля $WS_EX_TRANSPARENT, нужно добавить
Код:
WinSetTrans($GUI, "", 255)
 
Автор
M

musicstashall

Знающий
Сообщения
322
Репутация
7
Отлично, Inni! Теперь бы еще сглаживание как-то осуществить, а то так и хочется взять напильник и скруглить края))

Делаю так и ничего не изменяется:

Код:
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY)



Добавлено:
Сообщение автоматически объединено:

Такой UDF набросал:

Код:
#Include-once
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

Local $__asData[0][6]

Func _GDIPlus_FloatingTextCreate($sString = "Simple Text", $left = -1, $top = -1, $Size = 72, $sFont = "Arial", $Style = 0, $sColor = '0xFF' & Hex(_WinAPI_GetSysColor($COLOR_WINDOWTEXT), 6), $Flag = 0)
	_GDIPlus_Startup()
	Local $tLayout = _GDIPlus_RectFCreate()
	Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
	Local $hPath = _GDIPlus_PathCreate()
	_GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, $Style, $Size)
	Local $aBounds = _GDIPlus_PathGetWorldBounds($hPath)
	Local $iWidth = $aBounds[2] + $aBounds[0] * 2
	Local $iHeight = $aBounds[3] + $aBounds[1] * 2
	Local $hWnd = GUICreate("", $iWidth, $iHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
	If $Flag = 1 Then GUISetStyle(-1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_CONTROLPARENT)
	GUISetState()
	WinSetTrans($hWnd, "", StringMid($sColor, 1, 4))
	Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)	
	Local $hBrush = _GDIPlus_BrushCreateSolid('0xFF' & StringMid($sColor, 5))
	_GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush)
	Local $hRegion = _GDIPlus_RegionCreateFromPath($hPath)
	Local $hRgn = _GDIPlus_RegionGetHRgn($hRegion)
	_WinAPI_SetWindowRgn($hWnd, $hRGN)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_RegionDispose($hRegion)
	_WinAPI_DeleteObject($hRgn)
	_GDIPlus_GraphicsDispose($hGraphic)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_PathDispose($hPath)
	_GDIPlus_Shutdown()
	_ArrayAdd($__asData, $hwnd & '|' & $sString & '|' & $Size & '|' & $sFont & '|' & $Style & '|' & $sColor)
	Return $hwnd
EndFunc

Func _GDIPlus_FloatingTextSetText($hwnd, $sString, $Size = '', $sFont = '', $Style = '', $sColor = '')
	Local $i = _ArraySearch($__asData, $hwnd, 0, 0, 0, 0, 1, 0)
	If $i > -1 Then 
		If $Size = '' Then $Size = $__asData[$i][2]
		If $sFont = '' Then $sFont = $__asData[$i][3]	
		If $Style = '' Then $Style = $__asData[$i][4]	
		If $sColor = '' Then $sColor = $__asData[$i][5]			
	Else
		Return -1		
	EndIf
	WinSetTrans($hWnd, "", 0)
	_GDIPlus_Startup()
	Local $tLayout = _GDIPlus_RectFCreate()
	Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
	Local $hPath = _GDIPlus_PathCreate()
	_GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, $Style, $Size)
	Local $aBounds = _GDIPlus_PathGetWorldBounds($hPath)
	Local $iWidth = $aBounds[2] + $aBounds[0] * 2
	Local $iHeight = $aBounds[3] + $aBounds[1] * 2
	Local $pos = WinGetPos($hwnd)
	Local $left = $pos[0] + $pos[2]/2 - $iWidth/2
	Local $top = $pos[1] + $pos[3]/2 - $iHeight/2
	WinMove($hWnd, '', $left, $top, $iWidth, $iHeight)
	Local $rgn = _WinAPI_CreateRectRgn(0, 0, $iWidth, $iHeight)
	_WinAPI_SetWindowRgn($hwnd, $rgn)
	
	Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)	
	Local $hBrush = _GDIPlus_BrushCreateSolid('0xFF' & StringMid($sColor, 5))
	_GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush)
	Local $hRegion = _GDIPlus_RegionCreateFromPath($hPath)
	Local $hRgn = _GDIPlus_RegionGetHRgn($hRegion)
	_WinAPI_SetWindowRgn($hWnd, $hRGN)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_RegionDispose($hRegion)
	_WinAPI_DeleteObject($hRgn)
	_GDIPlus_GraphicsDispose($hGraphic)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_PathDispose($hPath)
	_GDIPlus_Shutdown()
	$__asData[$i][2] = $Size
	$__asData[$i][3] = $sFont
	$__asData[$i][4] = $Style	
	$__asData[$i][5] = $sColor		
	WinSetTrans($hWnd, "", StringMid($sColor, 1, 4))
	Return 1
EndFunc

Func _GDIPlus_FloatingTextGetAttributeText($hWnd)
	Local $i = _ArraySearch($__asData, $hwnd, 0, 0, 0, 0, 1, 0)
	If $i > -1 Then 
		Local $__anData[1][4] = [[$__asData[$i][2], $__asData[$i][3], $__asData[$i][4], $__asData[$i][5]]]
		Return $__anData
	Else
		Return -1	
	EndIf
EndFunc

Func _GDIPlus_FloatingTextDelete($hWnd, $sSleep = 0)
	Local $i = _ArraySearch($__asData, $hwnd, 0, 0, 0, 0, 1, 0)
	If $i > -1 Then 
		_ArrayDelete($__asData, $i)
	Else
		Return -1	
	EndIf
	For $i = 0 to 25.5
		WinSetTrans($hWnd, "", ($i - 25.5)*-10)
		Sleep($sSleep)
	Next
	GUIDelete($hWnd)
	Return 1
EndFunc


Применение:

Код:
$hWnd = _GDIPlus_FloatingTextCreate("Simple Text", -1, -1, 72, $sFont, 1, '0x' & Hex(255, 2) & 'ffffff')
	Sleep(3000)
	$data = _GDIPlus_FloatingTextGetAttributeText($hWnd)
	_ArrayDisplay($data)
	For $i = 0 to 10
		_GDIPlus_FloatingTextSetText($hwnd, ($i - 10)*-1)
		Sleep(1000)
	Next
	Sleep(3000)
	_GDIPlus_FloatingTextSetText($hwnd, 'New Text', 72, $sFont, 1, '0x' & Hex(0, 2) & 'ffffff')
	For $i = 0 To 25
		WinSetTrans($hwnd, '', $i)
		Sleep(50)
	Next
	For $i = 25 To 50
		WinSetTrans($hwnd, '', $i)
		Sleep(25)
	Next
	For $i = 50 To 255
		WinSetTrans($hwnd, '', $i)
		Sleep(1)
	Next
	
	Sleep(3000)
	For $i = 300 to 1000
		WinMove($hwnd, '', $i, -1)
	Next
	_GDIPlus_FloatingTextDelete($hWnd, 5)
 

InnI

AutoIT Гуру
Сообщения
4,912
Репутация
1,429
musicstashall
сглаживание как-то осуществить
Сгладить текст можно в примере с UpdateLayeredWindow (ответ #8), добавив
Код:
_GDIPlus_GraphicsSetTextRenderingHint($hGraph, 3)
Но там у вас проблемы с blur.

Делаю так и ничего не изменяется
Вы увидите изменения, если закомментируете
Код:
;~ _WinAPI_SetWindowRgn($GUI, $hRGN)
Дело в том, что эта функция из user32 и не умеет сглаживать.
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
blur как я понял, нужна для размытия подложки текста?
если так скомбинировать?
у меня на вин 10 работает
Код:
#include <GDIPlus.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()
$sString = "Simple Text"
$hDC = _WinAPI_GetDC(0)
$hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 72, 1)
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
$iWidth = $aInfo[0].Width
$iHeight = $aInfo[0].Height
$hImage = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
$hGraph = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsSetTextRenderingHint($hGraph, 3)
_GDIPlus_GraphicsDrawStringEx($hGraph, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
$GUI = GUICreate("", $iWidth, $iHeight, 100, 100, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_CONTROLPARENT))
_WinAPI_UpdateLayeredWindowEx($GUI, -1, -1, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 255, True)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hGraph)
_GDIPlus_ImageDispose($hImage)
_WinAPI_ReleaseDC(0, $hDC)
_GDIPlus_Shutdown()
_WinAPI_DwmEnableBlurBehindWindow10($GUI)
GUISetState()
Do
Until GUIGetMsg() = -3

Func _WinAPI_DwmEnableBlurBehindWindow10($hWnd, $bEnable = True)
	Local $tAccentPolicy = DllStructCreate("int AccentState; int AccentFlags; int GradientColor; int AnimationId")
	Local $tAttrData = DllStructCreate("dword Attribute; ptr DataBuffer; ulong Size")
	$tAccentPolicy.AccentState = $bEnable ? 3 : 0
	$tAttrData.Attribute = 19 ; WCA_ACCENT_POLICY
	$tAttrData.DataBuffer = DllStructGetPtr($tAccentPolicy)
	$tAttrData.Size = DllStructGetSize($tAccentPolicy)

	Local $aResult = DllCall("user32.dll", "bool", "SetWindowCompositionAttribute", "hwnd", $hWnd, "ptr", DllStructGetPtr($tAttrData))
	If @error Then Return SetError(@error, @extended, 0)

	Return $aResult[0]
EndFunc


Добавлено:
Сообщение автоматически объединено:

InnI
в твоем примере можно удалить текст не пересоздавая окно?
 
Верх