dwhiting Posted August 1, 2008 Posted August 1, 2008 In this script, I have successfully got it to display the text on screen. The only thing I cannot get it to do is remove the text. The text remains onscreen after the script exits. It does not disappear until I refresh the screen or open a new window. I thought the Redraw line would do this for me but is not working. I hope someone can tell me how to remove the text from the screen without having to refresh or open a new window. Thanks. #Include<StructureConstants.au3> #Include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> $hDC = _WinAPI_GetDC(0);Gets handle of entire screen _WinAPI_SetTextColor($hDC, "0x0000FF");Sets color of text $bkmode = DllCall("GDI32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", "TRANSPARENT");Sets background of text to Transparent $font = _WinAPI_CreateFont(50,15);Creates a font 50 pixels high and 15 pixels/character wide _WinAPI_SelectObject($hDC, $font);Selects newly created font $sText = "Hello world, this is my test message!";Sets actual message to be displayed. $rect = DllStructCreate($tagRECT);Creates region where text is to be displayed. DllStructSetData($rect,1,0) DllStructSetData($rect,2,0) DllStructSetData($rect,3,1280) DllStructSetData($rect,4,50) $iFlags = "$DT_CENTER";Sets how text is positioned in region. _WinAPI_DrawText($hDC, $sText, $rect, $DT_RIGHT);Draws the text sleep(1000);Waits 1 second _WinAPI_RedrawWindow("","","",$RDW_UPDATENOW);Should repaint the entire screen to remove the text but does not work.
ProgAndy Posted August 1, 2008 Posted August 1, 2008 Just use _WinAPI_GetDesktopWindow() and some more flags _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(),"","",BitOR($RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN)) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
dwhiting Posted August 1, 2008 Author Posted August 1, 2008 ProgAndy said: Just use _WinAPI_GetDesktopWindow() and some more flags _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(),"","",BitOR($RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN))Awesome, thank you very much.
dwhiting Posted August 2, 2008 Author Posted August 2, 2008 dwhiting said: Awesome, thank you very much.Hi, you helped me with my DrawText problem and clearing it off the screen. I now have a new problem. I can't seem to get drawtext to show up over video. Here is my script again. I am just using it to display date and time while watching movies. Do you know how I can get it to work when full screen video is playing?Thank you again.#Include<StructureConstants.au3>#Include <WinAPI.au3>#include <GUIConstantsEx.au3>#include <WindowsConstants.au3>#include <FontConstants.au3>#include <date.au3>Opt("TrayIconHide", 1)$hDC = _WinAPI_GetDC(0);Gets handle of entire screen_WinAPI_SetTextColor($hDC, "0x0000FF");Sets color of text$bkmode = DllCall("GDI32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", "TRANSPARENT");Sets background of text to Transparent$font = _WinAPI_CreateFont(80,25,0,0,1500);Creates a font 50 pixels high and 15 pixels/character wide_WinAPI_SelectObject($hDC, $font);Selects newly created font$sText = _Now ( );Sets actual message to be displayed.$rect = DllStructCreate($tagRECT);Creates region where text is to be displayed.DllStructSetData($rect,1,1340)DllStructSetData($rect,2,20)DllStructSetData($rect,3,2440)DllStructSetData($rect,4,100)$iFlags = $DT_LEFT;Sets how text is positioned in region._WinAPI_DrawText($hDC, $sText, $rect, $iFlags);Draws the textsleep(10000);Waits 1 second$hwnd = _WinAPI_GetDesktopWindow();Gets Desktop Handle_WinAPI_RedrawWindow($hwnd,"","",BitOR($RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN)) ;Clears the TEXT
rasim Posted August 3, 2008 Posted August 3, 2008 dwhitingExample:expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> Global Const $TRANSPARENT = 1 Global Const $OPAQUE = 2 HotKeySet("{ESC}", "_Exit") $string = "Hello world!" $hDC = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", 0) $hDC = $hDC[0] $tRECT = DllStructCreate("dword[4]") DllStructSetData($tRECT, 1, 5, 1) DllStructSetData($tRECT, 1, 5, 2) DllStructSetData($tRECT, 1, 250, 3) DllStructSetData($tRECT, 1, 50, 4) Global $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", 50, "int", 0, _ "int", 0, "int", 0, "int", 400, "dword", BitAND(0, 2), _ "dword", BitAND(0, 4), "dword", BitAND(0, 8), "int", $DEFAULT_CHARSET, _ "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _ "str", "Arial") $hFont = $hFont[0] DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", 0x0000FF) DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", 0x000000) Local $OldFont = _WinAPI_SelectObject($hDC, $hFont) While 1 _DrawText() Sleep(10) WEnd _Exit() Func _DrawText() ;DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", $TRANSPARENT) DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $string, "int", StringLen($string), _ "ptr", DllStructGetPtr($tRECT), "int", $DT_CENTER) EndFunc Func _Exit() _WinAPI_SelectObject($hDC, $OldFont) _WinAPI_DeleteObject($hFont) _WinAPI_ReleaseDC("", $hDC) _WinAPI_InvalidateRect(0, 0) Exit EndFunc
Zedna Posted August 4, 2008 Posted August 4, 2008 rasim said: dwhiting Example: rasim I converted your example to use all possible standard WinAPI functions: expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> Global Const $TRANSPARENT = 1 Global Const $OPAQUE = 2 Global $tRECT, $hFont, $OldFont, $hDC HotKeySet("{ESC}", "_Exit") $tRECT = DllStructCreate("dword[4]") DllStructSetData($tRECT, 1, 5, 1) DllStructSetData($tRECT, 1, 5, 2) DllStructSetData($tRECT, 1, 250, 3) DllStructSetData($tRECT, 1, 50, 4) $hDC = _WinAPI_GetDC(0) $hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') $OldFont = _WinAPI_SelectObject($hDC, $hFont) _WinAPI_SetTextColor($hDC, 0x0000FF) _WinAPI_SetBkColor($hDC, 0x000000) While 1 _DrawText("Hello world!") Sleep(100) WEnd Func _DrawText($string) ;DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", $TRANSPARENT) _WinAPI_DrawText($hDC, $string, $tRECT, $DT_CENTER) EndFunc Func _Exit() _WinAPI_SelectObject($hDC, $OldFont) _WinAPI_DeleteObject($hFont) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_InvalidateRect(0, 0) Exit EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search
rasim Posted August 5, 2008 Posted August 5, 2008 Zedna Quote I converted your example to use all possible standard WinAPI functionsOk, my laziness
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now