Synaps3 Posted July 9, 2022 Posted July 9, 2022 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.
Subz Posted July 9, 2022 Posted July 9, 2022 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.
Solution Nine Posted July 9, 2022 Solution Posted July 9, 2022 (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 July 9, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Synaps3 Posted July 10, 2022 Author Posted July 10, 2022 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. expandcollapse popup#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
Nine Posted July 10, 2022 Posted July 10, 2022 One small glitch in your code. Since there is no GUI involved in, you should replace last 3 lines by : While Sleep(100) WEnd “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Synaps3 Posted July 11, 2022 Author Posted July 11, 2022 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?
Nine Posted July 11, 2022 Posted July 11, 2022 (edited) If I am not mistaken, GUIGetMsg without GUI is just about Sleep(13). It is just an ugly usage of it, that is all. And I dislike ugly things Edited July 11, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
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