Jump to content

Floating text


Recommended Posts

Is there any way to have text float any where?

Like no background just have text on the screen.

so kind of like ToolTip() but no background

Is there any way to make the ToolTip() background transparent?

or use a Gui and some how make that transparent except text?

Link to comment
Share on other sites

Hi,

Opt("OnExitFunc", "endscript")
#include <GUIConstants.au3>
$hwnd = GUICreate("Text Region", @DesktopWidth, @DesktopHeight, @DesktopWidth / 2 - 250, @DesktopHeight / 2 - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0x00FF00)
Send("#m")
GUISetState()

ControlHide("Program Manager", "", "[CLASSNN:SHELLDLL_DefView1]")
While 1
    $rgn = CreateTextRgn($hwnd, 3000, 250, "Arial", 1000)
    SetWindowRgn($hwnd, $rgn)
    Sleep(500)
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 = "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   ;==>CreateTextRgn

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

sure.

Erase those lines:

Send("#m") <-- Mimimize ALL!!!

ControlHide("Program Manager", "", "[CLASSNN:SHELLDLL_DefView1]") <-- Hides Desktop symbols

This func for showing the icons back when script ends:

Func endscript()

ControlShow("Program Manager", "", "[CLASSNN:SHELLDLL_DefView1]")

EndFunc ;==>endscript

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 2 months later...

Hi,

show your test script, please.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

show your test script, please.

In my case, all I've done is change the dimensions of the created GUI, but the text is on the left of the gui, which makes it look a bit odd with different lengths of text.

In LIMITER's case, if you change the font size ($CTR_height) from 250 to something much smaller than about 70, the text becomes quite jaggard, rather than the nice smooth font usually presented.

Link to comment
Share on other sites

Really, no problem for me.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

@Xenobiologist

At this font size (25), the text looks pretty chunky ... I want it to be smooth

Here's the code

Opt("OnExitFunc", "endscript")
#include <GUIConstants.au3>
$hwnd = GUICreate("Text Region", @DesktopWidth, @DesktopHeight, @DesktopWidth / 2 - 250, @DesktopHeight / 2 - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0x00FF00)
GUISetState()

While 1
    $rgn = CreateTextRgn($hwnd, "LMP : Playing -> Yahel - Bomb Creator", 25, "Arial", 1000)
    SetWindowRgn($hwnd, $rgn)
    Sleep(500)
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 = "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  ;==>CreateTextRgn
Link to comment
Share on other sites

The previous floating text example was based gdi32.dll.

This is another example based on gdiplus.dll, which makes text rotation possible.

In this example of the function :-

Spacebar or middle mouse button rotates the smaller text across the screen.

Esc to exit.

Each new rotation creates another Gui. On exit they all disappear. It's only an example of what can be done.

Tested on xp 512mb mem. 1280x1024 resolution. Worked ok.

When I changed to the present large text, the "le"was missing in "example". By increasing to 28 on line 72, from 26, the "le" appeared.

So, on different system configurations - screen resolutions, tweaking the text rectangle may be necessary.

I am not certain if GDIPlus works successfully on all Vista setups.

Mega, I'd like to ask about one enhancement:

Is it possible to add $GUI_WS_EX_PARENTDRAG somewhere in CreateTextRgn to make the text block draggable?

Thanks for the nice script.

The addin I keep using to enable gui's to be draggable at any point of the gui is the three parter. It is comment labeled in the script (WinMove - 3rd part). I have seen other addin functions which enable gui draggability on posts.

qwert, if you are fine with Xenobiologist example and still need draggability of the text, try extracting the three part addin I used. That should make the text draggable, which is a gui window.

I tried the addin on Xenobiologist example and it worked. The 3000 is draggable.

My eg.

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>

;Run Beta Version Includes
#include <WindowsConstants.au3>
#include <Misc.au3>

Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin

Local $nText, $init = 1, $angle = -5, $xpos = 0
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
         
$nText = "AutoIt GDIPlus rotate text Example"  ;Enter text to be displayed here

;CreateFloatAngleText($nText,$Left=-1,$Top=-1,$nAngle=0,$nFontName="Arial",$nFontSize=12,$iARGB=0xFFFF00FF)
 CreateFloatAngleText($nText,    -130,    -45,       38,                -1,           70 ) ; Large text 70 

; $init = 1 allows initial flow through to display text. 
; 2nd time through Do-Until loop, spaceBar or middle mouse button need to be pressed to display text. 
Do  
    If _IsPressed("20") Or _IsPressed("04") Or $init = 1 Then ; SpaceBar or middle mouse button key
        $init  = 2
        $angle = Mod($angle + 5, 360)
        $xpos += 20
        CreateFloatAngleText($nText, $xpos, -1, $angle, -1, -1, 0) ;0 for random color; increment X position. 
    EndIf
    Sleep(250)
Until _IsPressed("1B")  ; ESC key

; #FUNCTION# ================================================================
; Name...........: CreateFloatAngleText
; Description ...: Puts text on screen at any angle.
; Syntax.........: CreateFloatAngleText($nText, $Left = -1, $Top = -1, $nAngle = 0, $nFontName = "Arial", _
;                                       $nFontSize = 12, $iARGB = 0xFFFF00FF)
; Parameters ....: $nText   - Text string to be displayed
;                  $Left    - Approximate Top left position of text from left of screen (default = -1 )
;                  $Top     - Approximate Top left position of text from top of screen  (default = -1 )
;                  $nAngle     - the angle which the text will be place.                 (default = 0 )
;                  $nFontName  - The name of the font to be used                   (default = "Arial" )
;                  $nFontSize  - The font size to be used                               (default = 12 )
;                  $iARGB      - Alpha, Red, Green and Blue color. (0=random color)(default=0xFFFF00FF)
; Return values .: 1
; Author ........: Malkey 31/03/08
; Modified.......: 
; Remarks .......: Tested on xp 512mb mem. 1280x1024 resolution. Worked ok. 
;                  Enter 0 for color, generates random color of text.
; Related .......:
; Link ..........; 
; Example .......; Yes
; ========================================================================================
Func CreateFloatAngleText($nText, $Left = -1, $Top = -1, $nAngle = 0, $nFontName = "Arial", _
                          $nFontSize = 12, $iARGB = 0xFFFF00FF)
                          
    Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    Local $iOpacity = 200
    Local $ULW_ALPHA = 2
    Local $nPI = 3.1415926535897932384626433832795
    Local $hGui, $hGraphic
    Local $GuiSize, $x, $y, $nX, $ny, $GuiWidth, $GuiHeight, $nWidth, $nHeight, $txtlen
    Local $hMatrix, $nXt, $nYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    
    ; Default values
    If $nAngle    = "" Or $nAngle    = -1 Then $nAngle    = 0
    If $nFontName = "" Or $nFontName = -1 Then $nFontName = "Arial" ; "Microsoft Sans Serif"
    If $nFontSize = "" Or $nFontSize = -1 Then $nFontSize = 12
    If $iARGB = 0 Then  ;Randomize ARGB color
        $iARGB = "0xff" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2)
    EndIf
    
    $txtlen    = StringLen($nText)
    $nWidth    = Int($nFontSize * $txtlen * 28/ 40)         ;Tweak here to de/increase text box width size
    $nHeight   = Int(($nFontSize * 37 / 30) * (1280 / 1024)) ;Tweak here to de/increase text box height size    
    $GuiWidth  = $nWidth - Abs($nHeight * Sin($nAngle * $nPI / 180))    
    $GuiHeight = $nHeight + Abs($nWidth * Sin($nAngle * $nPI / 180)) 
    
    $nX   = $GuiWidth  / 2      
    $ny   = $GuiHeight / 2      
    $hGui = GUICreate("Rotate Text", $GuiWidth, $GuiHeight, $Left, $Top, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
    GUISetState()
    
    _GDIPlus_Startup ()
    $hWnd = _WinAPI_GetDC (0)
    $hDC = _WinAPI_CreateCompatibleDC ($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $GuiWidth, $GuiHeight) ; $iWidth, $iHeight)
    _WinAPI_SelectObject ($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)   
    
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate ()
    _GDIPlus_MatrixRotate ($hMatrix, $nAngle, 1)
    _GDIPlus_GraphicsSetTransform ($hGraphic, $hMatrix)
    
    ;x, y are display coordinates of center of width and height of the rectanglular text box. 
    ;x, y increment in a circular path with radius (width of text box)/2.
    ;Parametric equations for a circle
    ; and adjusts for center of text box
    $x = ($nWidth / 2) * Cos($nAngle * $nPI / 180) - ($nHeight / 2) * Sin($nAngle * $nPI / 180)
    $y = ($nWidth / 2) * Sin($nAngle * $nPI / 180) + ($nHeight / 2) * Cos($nAngle * $nPI / 180)
    
    ;Rotation of Coordinate Axes formulae
    ;Use $nXt, $nYt in  _GDIPlus_RectFCreate. These x, y values is the position of the rectangular 
    ;text box point before rotation. (before translation of the matrix)
    $nXt =  ($nX - $x) * Cos($nAngle * $nPI / 180) + ($ny - $y) * Sin($nAngle * $nPI / 180) 
    $nYt = -($nX - $x) * Sin($nAngle * $nPI / 180) + ($ny - $y) * Cos($nAngle * $nPI / 180)
    
    ; Parameters for GDIPlus_GraphicsDrawStringEx()
    $hBrush  = _GDIPlus_BrushCreateSolid   ($iARGB)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate   ($nFontName)
    $hFont   = _GDIPlus_FontCreate         ($hFamily, $nFontSize, 1, 3)
    $tLayout = _GDIPlus_RectFCreate        ($nXt, $nYt, $nWidth, $nHeight)
    _GDIPlus_GraphicsDrawStringEx          ($hGraphic, $nText, $hFont, $tLayout, $hFormat, $hBrush)
    
    ; Parameters for _WinAPI_UpdateLayeredWindow
    $tSize   = DllStructCreate  ($tagSIZE)
    $pSize   = DllStructGetPtr  ($tSize)
    DllStructSetData            ($tSize, "X", $GuiWidth)  
    DllStructSetData            ($tSize, "Y", $GuiHeight) 
    $tSource = DllStructCreate  ($tagPOINT)
    $pSource = DllStructGetPtr  ($tSource)
    $tBlend  = DllStructCreate  ($tagBLENDFUNCTION)
    $pBlend  = DllStructGetPtr  ($tBlend)
    DllStructSetData            ($tBlend, "Alpha", $iOpacity)
    DllStructSetData            ($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow ($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    
    ; Clean up resources
    _GDIPlus_MatrixDispose       ($hMatrix)
    _GDIPlus_FontDispose         ($hFont)
    _GDIPlus_FontFamilyDispose   ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose        ($hBrush)
    _GDIPlus_GraphicsDispose     ($hGraphic)
    _WinAPI_ReleaseDC            (0, $hWnd)
    _WinAPI_DeleteObject         ($hBitmap)
    _WinAPI_DeleteDC             ($hDC)
    _GDIPlus_Shutdown            ()
    return 1
EndFunc   ;==>CreateFloatTextAngle


; =================================================================
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($hWnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
EndFunc   ;==>_WinMove
Link to comment
Share on other sites

Hi,

yeah looks nice. You can add a label and then drag the GUI too I suppose.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

yeah looks nice. You can add a label and then drag the GUI too I suppose.

Mega

That's kind of correct.

To drag the GUI, something visible has to be on the GUI to click on to drag.

In this case text. With small lettering, the process is clink drag, clink drag, clink drag, clink drag, got it!, dropped it, clink drag, clink drag.....

If an image was placed on one of these GDIPlus layered GUI's with a transparent background, it's only the visible parts that are clickable to drag the GUI.

Thanks for your statement. I clarified in my mind what was happening.

Link to comment
Share on other sites

qwert, if you are fine with Xenobiologist example and still need draggability of the text, try extracting the three part addin I used. That should make the text draggable, which is a gui window

Yes, thanks for that function. It works great.
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...