Jump to content

Recommended Posts

Posted

Hi all,

 

I was wondering if it is possible (and how) to put text on video on-the-fly (like VLC displays Title movie at the begining)

and of course doing that in AutoIt

Thanks in advance...

 

C.

Posted

I think that may be problematic, because a video constantly "repaints" a certain area, at least that's the way i think about it, but there's a possibility that creating a window with certain flags can ensure that it stays over everything else, and unaffected.

See this example:

#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;#include <WinAPISysWin.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

; #FUNCTION# ====================================================================================================================
; Name ..........: OverlayWindow
; Description ...:  Throws up a child window with transparent background over current window
;
; Parameters :
;   $hwndParent         parent hwnd
;   $rectToHighlight    rect to draw (or if null, skip)
;   $rectForText    rect for textToWrite
;   $textToWrite    the text to write
; ===============================================================================================================================
Func OverlayWindow($hwndParent, $rectToHighlight, $rectForText, $textToWrite)

   $style = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS)
   $exstyle = BitOR($WS_EX_TOPMOST, $WS_EX_COMPOSITED, $WS_EX_TRANSPARENT)

   $hGUI = GUICreate("transparent overlay", -1, -1, -1, -1, $style, $exstyle)

    GUISetBkColor(0xFFFFFF)
  _WinAPI_SetLayeredWindowAttributes($hGUI, 0xFFFFFF, 0, $LWA_COLORKEY)

   ConsoleWrite("**** $hGUI: " & $hGUI & @CRLF)
   ConsoleWrite("**** @error: " & @error & @CRLF)
   ConsoleWrite("**** @extended: " & @extended & @CRLF)

   GUISetOnEvent($GUI_EVENT_CLOSE, "OverlayWindow_Exit")
   GUISetState(@SW_SHOW, $hGUI)

   $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
   ConsoleWrite("**** $hGraphics : " & $hGraphics & @CRLF)
   _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

   $hPen = _GDIPlus_PenCreate(0xFFFF0000, 4)    ; Red

   If ($rectToHighlight <> Null) Then
      _GDIPlus_GraphicsDrawRect($hGraphics, $rectToHighlight[0], $rectToHighlight[1], $rectToHighlight[2], $rectToHighlight[3], $hPen)
   EndIf

   _GDIPlus_PenDispose($hPen)

   $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)  ; RED
   $hFormat = _GDIPlus_StringFormatCreate()
   $hFamily = _GDIPlus_FontFamilyCreate("Arial")
   $hFont = _GDIPlus_FontCreate($hFamily, 14, 2)
   $tLayout = _GDIPlus_RectFCreate($rectForText[0], $rectForText[1], $rectForText[2], $rectForText[3])
   $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $textToWrite, $hFont, $tLayout, $hFormat)
   _GDIPlus_GraphicsDrawStringEx($hGraphics, $textToWrite, $hFont, $aInfo[0], $hFormat, $hBrush)

   _GDIPlus_BrushDispose($hBrush)
   _GDIPlus_StringFormatDispose($hFormat)
   _GDIPlus_FontFamilyDispose($hFamily)
   _GDIPlus_FontDispose($hFont)
   _GDIPlus_GraphicsDispose($hGraphics)

   Return $hGUI
EndFunc

Func OverlayWindow_Exit()
   ConsoleWrite("* * * Exit event called" & @CRLF)
EndFunc

Func Handle_Esc()
   $Done = True
EndFunc

;-----------------------------------------------------------------
;Main()

_GDIPlus_Startup()

Global $Done = False
Local $rect = [10, 10, 400, 400]
Local $rectForText = [15, 15, 380, 380]
$hGUI = OverlayWindow(Null, $rect, $rectForText, "This is a test with long text long text and should automatically wrap long text " & @CRLF & "and " & @CRLF & " handle " & @CRLF & "cariage returns and line feeds")

HotKeySet ( "{Esc}", Handle_Esc)

While Not $Done
   Sleep(100)

WEnd

GUIDelete($hGUI)
_GDIPlus_Shutdown ()
Exit 0

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

Hi,

 

Thanks, but I get some errors... I can't solve them...

 

C.

Posted

"got some errors" doesn't tell us much, what errors?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

error found... the include file was commented

BUT,... it doesn't get the behaviour I am looking for.

Posted
Posted
  On 10/23/2018 at 5:22 PM, cramaboule said:

BUT,... it doesn't get the behaviour I am looking for.

Expand  

Why not, what is it doing that it's not supposed to be doing, or what is it not doing that it is supposed to be doing? You could try being a whole lot less vague in your error descriptions, otherwise no one has a clue what you are doing wrong.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Yes... sorry I must be more acurate:

I got the same behaviour as this post: 

 

and I tried to play a bit with the child and parent window but didn't get trough...

How to put the video underneath and the text above?

Posted

Try again, untested.

#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

; #FUNCTION# ====================================================================================================================
; Name ..........: OverlayWindow
; Description ...:  Throws up a child window with transparent background over current window
;
; Parameters :
;   $hwndParent         parent hwnd
;   $rectToHighlight    rect to draw (or if null, skip)
;   $rectForText    rect for textToWrite
;   $textToWrite    the text to write
; ===============================================================================================================================
Func OverlayWindow($hwndParent, $rectToHighlight, $rectForText, $textToWrite)

   $style = $WS_POPUP
   $exstyle = BitOR($WS_EX_TOPMOST, $WS_EX_TRANSPARENT, $WS_EX_LAYERED)

   $hGUI = GUICreate("transparent overlay", 420, 420, 0, 0, $style, $exstyle)
   GUISetBkColor(0x112233)
  _WinAPI_SetLayeredWindowAttributes($hGUI, 0x112233, 0, $LWA_COLORKEY)

   ConsoleWrite("**** $hGUI: " & $hGUI & @CRLF)
   ConsoleWrite("**** @error: " & @error & @CRLF)
   ConsoleWrite("**** @extended: " & @extended & @CRLF)

   GUISetOnEvent($GUI_EVENT_CLOSE, "OverlayWindow_Exit")
   GUISetState(@SW_SHOW, $hGUI)

   $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
   ConsoleWrite("**** $hGraphics : " & $hGraphics & @CRLF)
   _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

   $hPen = _GDIPlus_PenCreate(0xFFFF0000, 4)    ; Red

   If ($rectToHighlight <> Null) Then
      _GDIPlus_GraphicsDrawRect($hGraphics, $rectToHighlight[0], $rectToHighlight[1], $rectToHighlight[2], $rectToHighlight[3], $hPen)
   EndIf

   _GDIPlus_PenDispose($hPen)

   $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)  ; RED
   $hFormat = _GDIPlus_StringFormatCreate()
   $hFamily = _GDIPlus_FontFamilyCreate("Arial")
   $hFont = _GDIPlus_FontCreate($hFamily, 14, 2)
   $tLayout = _GDIPlus_RectFCreate($rectForText[0], $rectForText[1], $rectForText[2], $rectForText[3])
   $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $textToWrite, $hFont, $tLayout, $hFormat)
   _GDIPlus_GraphicsDrawStringEx($hGraphics, $textToWrite, $hFont, $aInfo[0], $hFormat, $hBrush)

   _GDIPlus_BrushDispose($hBrush)
   _GDIPlus_StringFormatDispose($hFormat)
   _GDIPlus_FontFamilyDispose($hFamily)
   _GDIPlus_FontDispose($hFont)
   _GDIPlus_GraphicsDispose($hGraphics)

   Return $hGUI
EndFunc

Func OverlayWindow_Exit()
   ConsoleWrite("* * * Exit event called" & @CRLF)
EndFunc

Func Handle_Esc()
   $Done = True
EndFunc

;-----------------------------------------------------------------
;Main()

_GDIPlus_Startup()

Global $Done = False
Local $rect = [10, 10, 400, 400]
Local $rectForText = [15, 15, 380, 380]
$hGUI = OverlayWindow(Null, $rect, $rectForText, "This is a test with long text long text and should automatically wrap long text " & @CRLF & "and " & @CRLF & " handle " & @CRLF & "cariage returns and line feeds")

HotKeySet ( "{Esc}", Handle_Esc)

While Not $Done
   Sleep(100)

WEnd

GUIDelete($hGUI)
_GDIPlus_Shutdown ()
Exit 0

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...