Sign in to follow this  
Followers 0

Adding Text to Windows Desktop

11 posts in this topic

#1 ·  Posted

I'm trying to figure out how to display some text on the desktop simmilar to how some trial OS's will put the OS, Build Number, and Trial info.

I found this ResHacker option but i'm looking for something a bit cleaner so I can update the text when needed.

Anybody have an idea?

Thanks,

Mike


Share this post


Link to post
Share on other sites



#3 ·  Posted

yeah, i thought about that also but I really don't want to have a script running all the time just to display some text.


Share this post


Link to post
Share on other sites

#4 ·  Posted

yeah, i thought about that also but I really don't want to have a script running all the time just to display some text.

You can use bginfo http://technet.microsoft.com/en-us/sysinte...s/bb897557.aspx and just customize the output to show your desired text only.

Note that you can't redistribute bginfo, but you could probably even hack together your own version using some of the graphics/GDI functions that have been posted.

Share this post


Link to post
Share on other sites

#5 ·  Posted

yeah, i thought about that also but I really don't want to have a script running all the time just to display some text.

Maybe find the file used for the desktop, create a copy and add text to it then switch the desktop to use that file.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#6 ·  Posted

If you want to go with GDI functions, here is something you can play with.

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

HotKeySet("{ESC}", "Quit")

CreateFloatText("Tweaking with Vishal" & @CRLF & "Build 6001", @DesktopWidth / 1.4, @DesktopHeight / 1.1, "Arial", 12, 0xFFFFFFFF, 2)
;or
;CreateFloatText("Where to go to from here.", 100, 10, "Arial" , 25, 0xFFFF00ff)

While 1
    Sleep(20)
WEnd

Func CreateFloatText($nText, $Left = -1, $Top = -1, $nFontName = "Arial", _
        $nFontSize = 12, $iARGB = 0xFFFFFFFF, $iAlign = 1)

    Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    Local $iOpacity = 255
    Local $ULW_ALPHA = 2
    Local $hGui, $hGraphic, $GuiWidth, $GuiHeight
    Local $hBrush, $hFormat, $hFamily, $hFont, $tLayout

    $txtlen = StringLen($nText)
    $GuiWidth = Int($nFontSize * $txtlen * 37 / 40) ;Tweak here to de/increase text box width size
    $GuiHeight = Int(($nFontSize * 37 / 30) * (17 / 9) * ((StringInStr($nText, @CRLF) > 0) + 1))
    ;ConsoleWrite("$GuiWidth = " & $GuiWidth & "  $GuiHeight = "& $GuiHeight & @CRLF)
    $hGui = GUICreate("Text", $GuiWidth, $GuiHeight, $Left, $Top, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetState()

    _GDIPlus_Startup()
    $hWnd = _WinAPI_GetDC($hGui)
    $hDC = _WinAPI_CreateCompatibleDC($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiWidth, $GuiHeight)
    _WinAPI_SelectObject($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)

    ; 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(0, 0, $GuiWidth, $GuiHeight)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    $rectWidth = DllStructGetData($aInfo[0], "Width")
    $rectHeight = DllStructGetData($aInfo[0], "Height")
    ;ConsoleWrite("$rectWidth = " & $rectWidth & "  $rectHeight = "& $rectHeight & @CRLF)
    WinMove("Text", "", $Left, $Top, Int($rectWidth), Int($rectHeight))
    _GDIPlus_StringFormatSetAlign($hFormat, $iAlign)
    _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_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   ;==>CreateFloatText

Func _GDIPlus_StringFormatSetAlign($hStringFormat, $iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat, "short", $iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] = 0 Then Return SetError(0, 0, 1)
    Return SetError(1, 0, 0)
EndFunc   ;==>_GDIPlus_StringFormatSetAlign

Func Quit()
    Exit
EndFunc   ;==>Quit

Interesting thing about this example is it appears to place part of the text where the invisible title bar is. This is the reason, I believe, that the top line of the text is dragable. And, on my system, when I click on the top left stem of the capital V of the text, the invisible GUI minimizes.

Share this post


Link to post
Share on other sites

#8 ·  Posted

You can use bginfo http://technet.microsoft.com/en-us/sysinte...s/bb897557.aspx and just customize the output to show your desired text only.

Note that you can't redistribute bginfo, but you could probably even hack together your own version using some of the graphics/GDI functions that have been posted.

That is PERFECT! Thanks ResNullius...

Now I have to figure out how to add text to an image file... and I can make this myself.

Mike


Share this post


Link to post
Share on other sites

#9 ·  Posted

You can use bginfo http://technet.microsoft.com/en-us/sysinte...s/bb897557.aspx and just customize the output to show your desired text only.

Note that you can't redistribute bginfo, but you could probably even hack together your own version using some of the graphics/GDI functions that have been posted.

Actually, that is pretty cool!

8)


Ad_Smallest_zpsjjqeqtel.jpg

Share this post


Link to post
Share on other sites

#10 ·  Posted

Now I have to figure out how to add text to an image file... and I can make this myself.

Mike

That's easy with GDI+ :mellow:

#include <GDIPlus.au3>

_GDIPlus_Startup()

$image=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\sample.jpg")
$imagegraphics=_GDIPlus_ImageGetGraphicsContext($image)
$w=_GDIPlus_ImageGetWidth($image)
$h=_GDIPlus_ImageGetHeight($image)

$whitebrush=_GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$fontfamily=_GDIPlus_FontFamilyCreate("Arial")
$font=_GDIPlus_FontCreate($fontfamily,18)
$stringformat=_GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($stringformat,2)
$rect=_GDIPlus_RectFCreate(0,$h-25,$w,$h)

_GDIPlus_GraphicsDrawStringEx($imagegraphics,"Sample Text",$font,$rect,$stringformat,$whitebrush)


_GDIPlus_ImageSaveToFile($image,@ScriptDir&"\newimage.jpg")
_GDIPlus_ImageDispose($image)
_GDIPlus_GraphicsDispose($imagegraphics)
_GDIPlus_BrushDispose($whitebrush)
_GDIPlus_FontFamilyDispose($fontfamily)
_GDIPlus_FontDispose($font)
_GDIPlus_StringFormatDispose($stringformat)
_GDIPlus_Shutdown()




Func _GDIPlus_StringFormatSetAlign($hStringFormat, $iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat, "short", $iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] = 0 Then Return SetError(0, 0, 1)
    Return SetError(1, 0, 0)
EndFunc  ;==>_GDIPlus_StringFormatSetAlign

:(


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

That's easy with GDI+ :mellow:

I knew one of the GDI+ guys would have an answer.

So now MikeOsdx, all you need to do is read the appropriate registry entry to find the current wallpaper, use that as the source picture in monoceres's script and then update the wallpaper to the new picture.

Edited by ResNullius

Share this post


Link to post
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
Sign in to follow this  
Followers 0