Jump to content

SplashTextOn with close (X) button


Go to solution Solved by Nine,

Recommended Posts

I'd like to be able to use the SplashTextOn feature, but allow the user to close the window with an X button instead of having to make them wait an arbitrary amount of time. I am surprised I can't find any results for this.

I managed to make a whole GUI version to get around this, but it's kludgy AF. I'm just trying to display bitcoin price in a text window, that's it, nothing else. The bitcoin part works, not asking for help with that.

Here's how easy the code 'could' be:

SplashTextOn("Bitcoin Price", $result, -1, 150, -1, -1, -1, -1, 48, 700)

Here's how I have it now:

$Form1 = GUICreate( "Bitcoin Price", 480, 100, -1, -1, BitOR($WS_EX_TOPMOST, $WS_SYSMENU))
GUISetBkColor (0x000000)
$Label1 = GUICtrlCreateLabel($result, 0, -10, 480, 180, $SS_LEFT)
GUICtrlSetColor($Label1, 0xFFFFFF)
GUICtrlSetFont(-1, 64, 800)
GUISetState(@SW_SHOW)
WinSetOnTop ($Form1, "", 1)
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd
GUIDelete($Form1)

There's several problems. It won't auto size the label properly with the new font size, so I have to set a fixed width. Same with the window. BUT I don't even really care about that; I just want an X button on the text window.

I don't want long fancy code. Small and compact. This is going into a large script that does many things and I don't want to bloat it up with a ton of GUI stuff; it doesn't use that for anything else.

Link to post
Share on other sites

Have a look at Melba23 UDFs, Toast.au3 and StringSize.au3 UDFs, both are excellent for this type of thing

How to make Toast - New version 2 Aug 18 - AutoIt Example Scripts - AutoIt Forums (autoitscript.com)

StringSize - M23 - New version 16 Aug 11 - AutoIt Example Scripts - AutoIt Forums (autoitscript.com)

Alternatively just use the Gui but within a function where you can use it as a custom SplashText function.

Link to post
Share on other sites
  • Solution
Posted (edited)

Here a way to modify the style of a splash :

#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

SplashTextOn("Bitcoin Price", "1000.00", -1, 150, -1, -1, -1, -1, 48, 700)
Local $hWnd = WinGetHandle("Bitcoin Price")
_WinAPI_EnableWindow($hWnd, True)
Local $nStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $nStyle + $WS_SYSMENU)
_WinAPI_SetWindowPos($hWnd, Null, 0, 0, 0, 0, $SWP_NOSIZE + $SWP_NOMOVE + $SWP_FRAMECHANGED)

Sleep(10000)

 

Edited by Nine
Link to post
Share on other sites
20 hours ago, Nine said:

Here a way to modify the style of a splash :

That's perfect. Here's the final result if you're interested.

#include <Misc.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>

; THIS SCRIPT WILL IMMEDIATELY DISPLAY BITCOIN PRICE WHEN PRESSING CTRL + ALT + B

HotKeySet("^!b", "DispPrice")

Func HttpGet($sURL, $sData = "")
    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("GET", $sURL & "?" & $sData, False)
    If (@error) Then Return SetError(1, 0, 0)
    $oHTTP.Send()
    If (@error) Then Return SetError(2, 0, 0)
    If ($oHTTP.Status <> 200) Then Return SetError(3, 0, 0)

    Return SetError(0, 0, $oHTTP.ResponseText)
EndFunc

Func GetPrice()
    Local $thePrice = HttpGet("") ; REDACTED URL JUST IN CASE. Put your own URL here that returns a JSON.
    Local $begining = StringInStr($thePrice, '"price":') + 8
    Local $ending = StringInStr($thePrice, '},')

    Return Int(StringMid($thePrice, $begining, $ending - $begining))
EndFunc

Func DispPrice()
    SplashTextOn("Bitcoin Price", GetPrice(), -1, 128, -1, -1, -1, -1, 72, 700)
    Local $hWnd = WinGetHandle("Bitcoin Price")
    _WinAPI_EnableWindow($hWnd, True)
    Local $nStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $nStyle + $WS_SYSMENU)
    _WinAPI_SetWindowPos($hWnd, Null, 0, 0, 0, 0, $SWP_NOSIZE + $SWP_NOMOVE + $SWP_FRAMECHANGED)
    While WinExists($hWnd)
        Sleep(3000)
        ControlSetText($hWnd, "", "Static1", GetPrice())
    WEnd
    SplashOff()
    ;Exit
EndFunc

While 1
    GUIGetMsg()
WEnd

 

Link to post
Share on other sites
14 hours ago, Nine said:

One small glitch in your code. Since there is no GUI involved in, you should replace last 3 lines by :

While Sleep(100)
WEnd

:)

Surprisingly, I've found GUIGetMsg() to work perfectly even without a GUI. I always default to using it over sleep because it just idles the CPU at a rate that works best for me (0% CPU usage, yet the code still executes fast). When I use sleep and then later add more to the code, I find myself having to tweak it for the right speed.

I admit, I have no idea why it works anyway. Is there a real problem with using it in this case or is it just aesthetics?

Link to post
Share on other sites
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...