Sign in to follow this  
Followers 0
seanhart

Auto-sizing, moveable, borderless splash screen

1 post in this topic

I've created an include file for extending the functionality of SplashText. My new function is called "SplashIt".

Features

- Borderless window which is automatically sized to length of text (handles multiple lines)

- Window becomes movable (with a title) when the mouse is moved within the window, and goes back to borderless when mouse moves outside of window

- If text is changed, window stays where it was put

The key to the auto window sizing is using a fixed width font, in this case Lucida Console.

Usage

Show the splash screen: _SplashIt ("some text")

Hide the splash screen: _SplashIt ("")

Things to note

- Uses Adlib to monitor the mouse, so can't be used with other Adlib functions

- Default title of window when moved is "Message Window" but this can be changed using the global variable $_SplashItTitle

- Don't change the $_SplashItTitle variable while window is open (Adlib function will error)

Download include file from:

http://www.autoitscript.com/fileman/users/public/seanhart/splashit.au3

#include-once

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Author:         Sean Hart <autoit@hartmail.ca>
; Function:       Borderless, auto-sizing, movable splash window
; Notes:          Variable $_SplashItTitle holds the title of the spash
;                 window, which is only displayed while it is being moved.
;                 Set that variable in your code to change it from the
;                 default.
;
;                 WARNING - Make sure splash window is closed if changing
;                           $_SplashItTitle variable!
;
;
; Following global variables are needed:
;   $_SplashItMouse =   1 - Mouse is within splash window
;                       0 - Mouse is outside of splash window
;   $_SplashItTitle =   string - Title of splash window
;
; ----------------------------------------------------------------------------

Dim $_SplashItMouse, $_SplashItTitle
$_SplashItMouse = 0
$_SplashItTitle = "Message Window"


; ----------------------------------------------------------------------------
;
; Description:      Creates / changes / hides splash window
; Syntax:           _SplashIt ($sText)
; Parameter(s):     $sText - Text to display (set to "" to close window)
; Requirement(s):   None
; Return Value(s):  None
;
; ----------------------------------------------------------------------------
Func _SplashIt ($sText)
   ; Declare variables
    Dim $width, $height, $split, $x, $maxlen

   ; Turn of splash text if blank and stop adlib
    If $sText = "" Then
        AdlibDisable ()
        SplashOff ()
    Else

       ; Determine height using number of lines of text and width using the longest line
        $maxlen = 0
        $split = StringSplit ($sText, @CR & @LF)
        For $x = 1 to $split[0]
            If StringLen ($split[$x]) > $maxlen Then $maxlen = StringLen ($split[$x])
        Next
        $height = ($split[0] + 2) * 12
        $width = ($maxlen * 8) + 16
        
       ; Add a line feed to text to space it nicely
        $sText = @LF & $sText
        
       ; If the window already exists, change the text (so window doesn't move)
        if WinExists ($_SplashItTitle, "") then
            ControlSetText($_SplashItTitle, "", "Static1", $sText)
        else
            SplashTextOn ($_SplashItTitle, $sText, $width, $height, -1, -1, 17, "Lucida Console", "10")
        endif
        
       ; Use adlib function to monitor mouse
        AdlibEnable ("_MoveSplash", 500)
        
    EndIf
EndFunc


; ----------------------------------------------------------------------------
;
; Description:      Adlib function to change the splash window type when the
;                   mouse cursor enters the coordinates of the window. Allows
;                   the splash window to be moved.
; Syntax:           _MoveSplash ()
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  None
;
; ----------------------------------------------------------------------------
Func _MoveSplash ()
       ; Declare variables
        Dim $winpos, $mousepos, $text, $width, $height, $maxlen, $x

       ; Get coordinates of window and position of mouse
        $winpos = WinGetPos ($_SplashItTitle)
        $mousepos = MouseGetPos ()
        
       ; Get contents of text from window
        $text = ControlGetText ($_SplashItTitle, "", "Static1")
        
       ; Determine height using number of lines of text and width using the longest line
        $maxlen = 0
        $split = StringSplit ($text, @CR & @LF)
        For $x = 1 to $split[0]
            If StringLen ($split[$x]) > $maxlen Then $maxlen = StringLen ($split[$x])
        Next
        $height = ($split[0] + 1) * 12
        $width = ($maxlen * 8) + 16
        
       ; If mouse is has just moved within window coordinates, change window type to 16 to allow it to move
        if ($mousepos[0] > $winpos[0]) and ($mousepos[0] < $winpos[0] + $winpos[2]) and ($mousepos[1] > $winpos[1]) and ($mousepos[1] < $winpos[1] + $winpos[3]) then
            if not $_SplashItMouse then
                $_SplashItMouse = 1
                SplashTextOn ($_SplashItTitle, $text, $width, $height, $winpos[0], $winpos[1], 16, "Lucida Console", "10")
            endif
            
       ; If mouse has just left window coordinates, change window type back to 17 (borderless)
        else
            if $_SplashItMouse then
                $_SplashItMouse = 0
                SplashTextOn ($_SplashItTitle, $text, $width, $height, $winpos[0], $winpos[1], 17, "Lucida Console", "10")
            endif
        endif       
EndFunc
1 person likes this

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