AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SPL - Splashscreen Library

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Banane



Joined: 25 Nov 2009
Posts: 31

PostPosted: Thu Mar 11, 2010 3:07 pm    Post subject: SPL - Splashscreen Library Reply with quote

SPL - Splashscreen Library

Description:
With this library your able to use splashscreens with just one function call.
Unlike the already built-in functions your able to use all gui options, transparency and change the shape.

You can create up to 9 splashscreens at the same time.

Functions:
SPL_Open
SPL_Close
SPL_Count

Library:
Code:
;----------------------------------------------------------------------------------------------------------------------------
;Function:    SPL_Open
;Parameters:  File      = The Path to your graphic
;             Option    = Various options, delimited by "/"
;                         /title   = Window title
;                         /trans   = Window transparency
;                         /region  = Window shape
;                         /options = Gui Options
;             Label     = The label to launch on click
;             Autoclose = Close the splash after X ms
;             Handle    = Gui Number (handle gets generated by default in the range 90-99)
;Description: Creates a new splash, returns 0 if file doesn't exist or out of range, otherwise the handle is returned
;----------------------------------------------------------------------------------------------------------------------------
SPL_Open(File,Option="",Label="",Autoclose=0,Handle=0) {
  ;If it's inside the range and file exists
  If (SPL_Count() = 9 || FileExist(File) = "")
    Return 0

  ;Constants
  Splashscreen_Options := "title,trans,region,options"

  ;Make handle
  If (Handle = 0)
    Handle := 89 + SPL_Count(1)

  ;Get Optional options
  If (InStr(Option,"/") <> 0)
    ;Parse the options block
    Loop, Parse, Option, /
      If (InStr(A_LoopField,"=") <> 0) {
        ;Get the Option Name
        Name := SubStr(A_LoopField,1,InStr(A_LoopField,"=") - 1)
        ;Save if it's valid
        If (InStr(Splashscreen_Options,Name) <> 0)
          %Name% := SubStr(A_LoopField,InStr(A_LoopField,"=") + 1,StrLen(A_LoopField))
      }

  ;Detect if label exists and use it
  If (IsLabel(Label) <> 0)
    Control := "g" . Label

  ;Build gui
  Gui, %Handle%:Margin, 0, 0
  Gui, %Handle%:+LastFound +LabelSplashscreen
  If (Options <> "")
    Gui, %Handle%:%Options%
  If (Trans <> "")
    WinSet, Trans, % Trans

    ;Add the graphic
    Gui, %Handle%:Add, Picture, %Control%, % File

  ;Show the gui
  Gui, %Handle%:Show, AutoSize %Guishow%, % (Title <> "") ? Title : "Splashscreen" . SPL_Count()
  ID := WinExist()

  ;Check if region should be used
  If (Region <> "") {
    ID := WinExist()
    WinGetPos,,, W, H, ahk_id %ID%
    WinSet, Region, % Region . " w" . W . " h" . H
  }

  ;Sleep if autoclose is on
  If (Autoclose <> 0) {
    Sleep, % Autoclose
    SPL_Close(Handle)
  }

  ;Output the gui number
  Return Handle . "|" . ID
}
;----------------------------------------------------------------------------------------------------------------------------
;Function:    SPL_Close
;Parameters:  The handle returned by SPL_Open
;Description: Closes the splashscreen and sets the new splash count, returns 0 if window doesn't exist, 1 otherwise
;----------------------------------------------------------------------------------------------------------------------------
SPL_Close(Handle) {
  ;Check if it exists
  If (WinExist("ahk_id " . SubStr(Handle,InStr(Handle,"|") + 1,StrLen(Handle))) = 0)
    Return 0
  ;Decrease count and get gui number
  SPL_Count(2),Handle := SubStr(Handle,1,InStr(Handle,"|") - 1)
  ;Destroy window
  Gui, %Handle%:Destroy
  Return 1
}
;----------------------------------------------------------------------------------------------------------------------------
;Function:    SPL_Count
;Parameters:  Set = 1 - Increase, 2 - Decrease
;Description: Returns the splash count and sets the new length
;----------------------------------------------------------------------------------------------------------------------------
SPL_Count(Set=0) {
 static Splashscreen_Count := 0

  Splashscreen_Count := (Set = 1) ? Splashscreen_Count + 1 : (Set = 2) ? Splashscreen_Count - 1 : Splashscreen_Count
  Return Splashscreen_Count
}


Example:
Code:
SPL_Open("Some Graphic.jpg","/title=Test1 /options=+ToolWindow","",2000)
Handle := SPL_Open("Some other Graphic.jpg","/title=Test2 /trans=200 /region=0-0 0-0 R9-9 /options=+ToolWindow -Caption")
Sleep, 2000
SPL_Close(Handle)


Changelog:
11.3.2010 - Initial Release
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group