Name:
For example: WiseGui("unnamed") will create/show the following UI with WinTitle set as WiseGui\unnamed ahk_class AutoHotkeyGUI
Note: The UI can be dismissed with Mouse left click
Options:
When Options are completely omitted, the function will
- Create a new GUI if name doesn't exist.
- or Destroy any existing one.
For eg., the following would splash a WiseGui for 3 seconds
Code: Select all
WiseGui("unnamed") Sleep(3000) WiseGui("unnamed")
When WiseGUI() is called with Options and the Named UI already exists, then the UI will be updated with newer options.
All options would work when creating a GUI.. For updation, only selected options will be processed.
Any unrecognized Key:value pair will be silently ignored
Recognized Keys for Gui creation
Four themes are built-in, namely Warning Info Success Error. Or, you may simply use the first letter W I S E
The following code would splash all 4 in-built themes, one-by-one. at right-bottom corner of primary monitor. (use Move option for different window placement)
Code: Select all
WiseGui("Test", "Theme: Warning")
Sleep(2000)
WiseGui("Test") ; Kill
WiseGui("Test", "Theme: Info")
Sleep(2000)
WiseGui("Test") ; Kill
WiseGui("Test", "Theme: Success")
Sleep(2000)
WiseGui("Test") ; Kill
WiseGui("Test", "Theme: Error")
Sleep(2000)
WiseGui("Test") ; Kill
You may pass your own theme with 4 comma separated values and in this exact order: TextColor, WindowColor, BorderColor, [HICON]
For eg., WiseGui("Test", "Theme: 0xF0F0F0, 0x778899, 0x556677") will produce
The left border is thick as WiseGui() will use a 32x32px transparent icon as place holder when HICON is omitted.
Pass 0 as HICON value to suppress this behaviour.
WiseGui("Test", "Theme: 0xF0F0F0, 0x778899, 0x556677, 0") will produce
-Theme:
If colors are omitted, WiseGui() will use System colors. WiseGui("Test", "Theme:,,") will produce
Again, to suppress thick left border: WiseGui("Test", "Theme:,,,0") will produce
MainText
SubText
A WiseGui has two text controls, MainText and SubText.
When MainText is omitted, Warning Info Success Error will be used for built-in themes and A_ScriptName for a custom theme.
Code: Select all
WiseGui( "Test"
, "MainText: Lorem ipsum"
, "SubText: Sed ut perspiciatis unde`nomnis iste natus error sit voluptatem"
)
Example 2: Text alignment -1=Left, 0=Center, 1=Right
Code: Select all
WiseGui( "Test"
, "MainText: Lorem ipsum"
, "MainAlign: 0"
, "SubText: Sed ut perspiciatis unde`nomnis iste natus error sit voluptatem"
, "SubAlign: 0"
)
Example 3: Applying Font
Code: Select all
WiseGui( "Test"
, "FontMain: s14 Bold Italic Underline, Comic Sans MS"
, "MainText: ' Lorem ipsum '"
, "MainAlign: 0"
, "FontSub: s12 Norm, Consolas"
, "SubText: Sed ut perspiciatis unde`nomnis iste natus error sit voluptatem"
, "SubAlign: 0"
)
Example 4: Applying fixed TextWidth for MainText and SubText
Code: Select all
WiseGui( "Test"
, "FontMain: s14 Bold Italic Underline, Comic Sans MS"
, "MainText: ' Lorem ipsum '"
, "MainAlign: 0"
, "FontSub: s12 Norm, Consolas"
, "SubText: Sed ut perspiciatis unde`nomnis iste natus error sit voluptatem"
, "SubAlign: 0"
, "TextWidth: 480"
)
If only a single line is needed, for eg. a ToolTip like splash, MainText height can be set to 0 with Main: 0
Note: Refer Margins option for precise spacing around SubText
Code: Select all
WiseGui( "Test"
, "Main: 0"
, "Theme: ,,,0"
, "FontSub: s10 Norm, Consolas"
, "SubText: Sed ut perspiciatis unde omnis iste natus error sit voluptatem"
, "Shadow: 1"
, "Transparency: 192" ; valid range: 64 to 255
)
Move
Requires 3 values in this order: xAxis, yAxis, Monitor
xAxis: A positive value (0 based index) will move the UI from left to right. A negative value will move the window from right to left.
yAxis: A positive value (0 based index) will move the UI from top to bottom. A negative value will move the window from bottom to top.
The default placement values are -10, -10 and will move the window to the right-bottom corner (or South-East corner, when expressed as a direction).
Note: Gui().Show("h200 w400 w500 w600") will show a 600x200 window, because only the final say i.e, w600 is accepted.
WiseGui() options are parsed in a similar manner.
The following will show the UI in center screen.
Comment out move lines, one-by-one, from bottom to see how the window placement is done.
Code: Select all
WiseGui( "Test"
, "Theme: Error"
, "MainText: Lorem ipsum"
, "SubText: Sed ut perspiciatis unde`nomnis iste natus error sit voluptatem"
, "Move: 0, 0" ; NorthWest
, "Move: , 0" ; North
, "Move: -1, 0" ; NorthEast
, "Move: -1, " ; East
, "Move: -1, -1" ; SouthEast
, "Move: , -1" ; South
, "Move: 0, -1" ; SouthWest
, "Move: 0, " ; West
, "Move: , " ; Center
)
Specifying monitor: Pass monitor number as 3rd value.
For eg: The following
Code: Select all
WiseGui( "Test"
, "Theme: Error"
, "MainText: Lorem ipsum"
, "SubText: Sed ut perspiciatis unde`nomnis iste natus error sit voluptatem"
, "Move: -1,, 1" ; East of Secondary monitor
)
moves UI as follows in my multi-monitor setup.
Margins
You may specify values in this exact order: xMargin, yMargin, ySpacing, IconMargin
Important Note: These are not pixels values. These values will be multiplied by 4 to convert them to pixel values.
Annoying, I know. Numbers other than multiples of 4 would not DPI scale nicely.
xMargin : The spacing on the left/right sides of MainText / SubText.
yMargin : The spacing above MainText and below SubText.
ySpacing : The vertical spacing between MainText and SubText.
IconMargin : The space surrounding icon.
Try experimenting with Margins' values in following example.
Code: Select all
WiseGui( "Test"
, "Margins: 4,1,0,3"
, "Theme:,,," . LoadPicture(A_AhkPath, "Icon1", &ImageType)
, "FontMain: S18, Comic Sans MS"
, "MainText: AutoHotkey"
, "FontSub: S14, Consolas"
, "SubText:" . A_AhkVersion
, "SubAlign: +1"
)
Show
Hide
You may use this feature to animate when WiseGui is Shown/dismissed.
These keys require 2 parameters, type and duration as a single value: for eg these pair will fade-in fade-out: Show: Fade@500ms Hide: Fade@500ms
Valid duration: 25ms to 2500ms
Valid types:
- Fade
- Zoom
- SlideEast
- SlideNorthEast
- SlideNorth
- SlideNorthWest
- SlideWest
- SlideSouthWest
- SlideSouth
- SlideSouthEast
- RollEast
- RollNorthEast
- RollNorth
- RollNorthWest
- RollWest
- RollSouthWest
- RollSouth
- RollSouthEast
Code: Select all
WiseGui( "Test"
, "MainText: UTC"
, "SubText:" . FormatTime(A_NowUTC, "hh:mm tt")
, "Show: SlideWest@400ms"
, "Show: SlideNorth@400ms" ; delete this line to slide west
, "Hide: SlideSouth@400ms"
, "Move: -1,-1"
, "Timer: 2000"
)
If the second occurrence of Show is deleted from above call:
Close
A WiseGui, for eg. WiseGui("MyWiseGui", "SubText: Hello World") would stay on screen forever until dismissed with a Mouse-Left-click.
It can be auto-closed if a timer is specified: WiseGui("MyWiseGui", "SubText: Hello World", "Timer: 3000").. and/or a mouse click, whichever occurs first.
The UI may also be closed from elsewhere on the script, by calling WiseGui("MyWiseGui").
I have the following Hotkey defined in my always-running-script to dismiss any/all WiseGui with Esc.
Code: Select all
HotIfWinExist("WiseGui\ ahk_class AutoHotkeyGUI")
; Hotkey( "Esc", (*) => WinClose() )
Hotkey( "Esc", (*) => WinClose(WinExist()) ) ; WinExist() rqd from atleast Beta10
HotIfWinExist()
It isn't wise to allow dismissal of a WiseGui, that is showing some/any progress or is in a wait state. On such a case, use Close: 0 to make the window un-closeable.
Once the task is complete, you have to mark the UI closeable with an explicit Close: 1, or else it would require an ExitApp to kill the UI.
Here follows an example:
Code: Select all
WiseGui( "folderSize"
, "Close: 0"
, "MainText: Computing folder size"
, "FontSub: s10 Norm, Consolas"
, "TextWidth: 240"
, "Shadow: 1"
)
FolderSize := 0
Loop Files A_WinDir . "\*.*"
{
WiseGui( "folderSize", "SubText:" . A_LoopFileFullPath )
Foldersize += A_LoopFileSize
Sleep(50)
}
WiseGui( "folderSize"
, "Close: 1"
, "MainText: Folder size in bytes"
, "SubText:" . FolderSize
, "Theme: Success"
, "Timer: 3000"
)
Use Close: Trigger if you need to know if UI was dismissed with a mouse click. Note: This isn't a callback.. Just an alert.
Code: Select all
WiseGui( "MyWiseGui"
, "Close: Trigger"
, "Timer: 5000"
, WiseGuiWasClicked ; or WiseGuiWasClicked.Bind("Auto", "Hot", "Key")
)
WiseGuiWasClicked(P*) ; Requires variadic params to deal with BoundFunc
{
Switch( P[1] ) ; Check first parameter if being called as Func
{ ; Check final parameter if being called as BoundFunc
Case 0 : ; No mouse click
Case 1 : SoundBeep() ; Left clicked
Case -1 : SoundBeep(), SoundBeep() ; Right clicked
}
}
Windows Media Player
I have implemented key wmp:<filename> on a test basis.
It uses PlaySound() and has been tested to work in Win 7+.
Use it minimally. Example call: "wmp:" . A_WinDir . "\Media\notify.wav"
Code: Select all
#Requires AutoHotkey v2.0-
#Warn
#SingleInstance
#Include "WiseGui.ah2"
F2::WinExist("WiseGui\SplashClock ahk_class AutoHotkeyGUI") ? WinClose() : SplashClock()
SplashClock()
{
WiseGui("SplashClock"
, "FontMain: s24 Norm, Consolas"
, "FontSub: s48 Norm Bold, Consolas"
, "MainText:" . FormatTime(A_Now, "ddd, dd-MMM-yyyy (") . FormatTime(A_Now, "YDay0") . ")"
, "SubText:" . FormatTime(A_Now, "hh:mm:ss tt")
, "MainAlign: 0"
, "SubAlign: 0"
, "Margins: 4,4,2,0"
, "Move:" ; Center screen
, "TextWidth: 420"
, "Theme: 0x856442, 0xFFFFF0, 0xEBB800, 0" ; Same as Warning theme, but no Icon
, "Show: Fade@400ms"
, "Hide: Fade@400ms"
)
SetTimer( SplashClock, 900 )
SplashClock()
{
If ( WinExist("WiseGui\SplashClock ahk_class AutoHotkeyGUI") )
WiseGui("SplashClock", "SubText:" . FormatTime(A_Now, "hh:mm:ss tt"))
Else SetTimer( , 0 )
}
}