namespace RobvanderWoude { [System.Runtime.InteropServices.Guid( "96D1A611-39B2-4039-AEDA-C9DC88FFB031" )] public interface SystemTrayMessage_Interface { [System.Runtime.InteropServices.DispId( 1 )] void CheckUpdate( ); [System.Runtime.InteropServices.DispId( 2 )] string Credits( ); [System.Runtime.InteropServices.DispId( 3 )] string Help( int html = 0 ); [System.Runtime.InteropServices.DispId( 4 )] string ListProperties( ); [System.Runtime.InteropServices.DispId( 5 )] string ListToolTipIcons( ); [System.Runtime.InteropServices.DispId( 6 )] string SampleCode( ); [System.Runtime.InteropServices.DispId( 7 )] void Show( ); } [System.Runtime.InteropServices.Guid( "F80187E9-E178-4B7B-87EB-EEE1386FF0E1" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )] public interface SystemTrayMessage_Events { } [System.Runtime.InteropServices.Guid( "C7484303-39FC-4C47-8736-02E3E341BDD5" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( SystemTrayMessage_Events ) )] public class SystemTrayMessage : SystemTrayMessage_Interface { #region Default Values const string defaulticonfile = "shell32.dll"; const int defaulticonindex = 277; const int defaulttimeout = 10; const System.Windows.Forms.ToolTipIcon defaulttooltipicon = System.Windows.Forms.ToolTipIcon.Info; static readonly string defaulttitle = string.Format( "{0}, Version {1}", Global.Common.ProgramInfo.FileName, Global.Common.ProgramInfo.FileVersion ); static readonly string[] searchpath = System.Environment.GetEnvironmentVariable( "PATH" ).Split( new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries ); #endregion Default Values static System.Windows.Forms.NotifyIcon notifyicon; static System.Drawing.Icon systrayicon; #region Methods public void CheckUpdate( ) { Global.Common.ProgramInfo.CheckUpdate( ); } public string Credits( ) { return Global.Common.Credits( ); } public string Help( int html = 0 ) { int col1width = 0; int col2width = 0; int col3width = 0; int col4width = 0; int col5width = 0; string help = string.Empty; string linetemplate = string.Empty; string separatorline = string.Empty; if ( html == 1 ) { help += "

Help for SystemTrayMessage class

\n\n"; help += "

Present an icon in the notification area (system tray) with an optional tooltip balloon, and return whether the icon or tooltip were clicked

\n\n"; help += "

COM ProgID: RobvanderWoude.SystemTrayMessage

\n\n"; } else { help += "Help for SystemTrayMessage class\n"; help += new string( '\u2500', help.Length ) + "\n\n"; help += "Present an icon in the notification area (system tray) with an optional tooltip balloon, and return whether the icon or tooltip were clicked\n\n\n"; help += "COM ProgID: RobvanderWoude.SystemTrayMessage\n\n\n"; } #region Properties if ( html == 1 ) { separatorline = string.Empty; linetemplate = "\n\t{0}\n\t{1}\n\t{2}\n\t{3}\n\t{4}\n\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\n"; } else { col1width = 16; col2width = 50; col3width = 9; col4width = 9; col5width = 44; separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u253C" + new string( '\u2500', 2 + col4width ) + "\u253C" + new string( '\u2500', 2 + col5width ) + "\u2524\n"; linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502 {3,-" + col4width.ToString( ) + "} \u2502 {4,-" + col5width.ToString( ) + "} \u2502\n"; help += "\u250C" + new string( '\u2500', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2510\n"; help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n"; help += string.Format( "\u2502 {0,-" + ( 12 + col1width + col2width + col3width + col4width + col5width ).ToString( ) + "} \u2502\n", "Properties (Note that all properties are string or integer, no booleans, objects or arrays)" ); help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n"; help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2564" + new string( '\u2550', 2 + col4width ) + "\u2564" + new string( '\u2550', 2 + col5width ) + "\u2561\n"; help += string.Format( linetemplate, "Property Name", "Description", "Mandatory", "Read-Only", "Default (Allowed) Values" ); help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u256A" + new string( '\u2550', 2 + col4width ) + "\u256A" + new string( '\u2550', 2 + col5width ) + "\u2561\n"; } help += HelpTableRow( linetemplate, "balloonclicked", "Will be 1 (true) if wait is 1 (true) and the tooltip balloon was clicked before timeout elapsed (0=false; 1=true)", "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "errors", Global.Common.Help.errors, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "escapemessage", "Interpret \\n as newline and \\t as tab in message (0=false; 1=true)", "no", "no", "1", html ); help += separatorline; help += HelpTableRow( linetemplate, "iconfile", "Either an icon file (*.ico) or an icon library (*.dll or *.exe) containing the icon to be used in notification area", "no", "no", string.Format( "icon #{0} in {1}", defaulticonindex, defaulticonfile ), html ); help += separatorline; help += HelpTableRow( linetemplate, "iconindex", "Index of icon in icon library iconfile", "no", "no", string.Format( "{0} if iconfile is {1}", defaulticonindex, defaulticonfile ), html ); help += separatorline; help += HelpTableRow( linetemplate, "message", "Tooltip message (if empty, no tooltip is shown)", "no", "no", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "timeout", Global.Common.Help.timeout, "no", "no", defaulttimeout.ToString( ), html ); help += separatorline; help += HelpTableRow( linetemplate, "title", Global.Common.Help.title, "no", "no", defaulttitle, html ); help += separatorline; help += HelpTableRow( linetemplate, "tooltipicon", "Icon shown in the tooltip balloon (use ListToolTipIcons( ) for a list of available icons)", "no", "no", string.Format( "{0} ({1})", defaulttooltipicon.ToString( ), ListToolTipIcons( ).Replace( ";", ", " ) + ")" ), html ); help += separatorline; help += HelpTableRow( linetemplate, "Version", Global.Common.Help.version, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "wait", "Wait for timeout to elapse (0=false; 1=true)\n(if 1, script will wait until either tooltip balloon is clicked or timeout elapses, if 0 script will continue without waiting, but \"balloonclicked\" status will not be available)", "", "", "1", html ); if ( html == 1 ) { help += "
Properties (Note that all properties are string or integer, no booleans, objects or arrays)
Property NameDescriptionMandatoryRead-OnlyDefault (Allowed) Values
\n\n\n"; } else { help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2534" + new string( '\u2500', 2 + col4width ) + "\u2534" + new string( '\u2500', 2 + col5width ) + "\u2518\n\n\n"; } #endregion Properties #region Methods if ( html == 1 ) { separatorline = string.Empty; linetemplate = "\n\t{0}\n\t{1}\n\t{2}\n\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\n"; } else { col1width = 16; col2width = 74; col3width = 44; separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u2524\n"; linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502\n"; help += "\u250C" + new string( '\u2500', 8 + col1width + col2width + col3width ) + "\u2510\n"; help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n"; help += string.Format( "\u2502 {0,-" + ( 6 + col1width + col2width + col3width ).ToString( ) + "} \u2502\n", "Methods" ); help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n"; help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2561\n"; help += string.Format( linetemplate, "Method Name", "Description", "Requirements" ); help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u2561\n"; } help += HelpTableRow( linetemplate, "CheckUpdate", Global.Common.Help._checkupdate, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "Credits", Global.Common.Help._credits, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "Help", Global.Common.Help._help, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "ListProperties", Global.Common.Help._listproperties, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "ListToolTipIcons", "Return a semicolon-separated list of available icons", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "SampleCode", Global.Common.Help._samplecode, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "Show", "Presents an icon in the notification area (system tray) with an optional tooltip balloon; if the program is set to continue without waiting, then that's all; if the program is set to wait for the timeout to elapse, clicking the tooltip balloon sets \"balloonclicked\" property and aborts the program.", "", html ); if ( html == 1 ) { help += "
Methods
Method NameDescriptionRequirements
\n\n\n"; } else { help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2518\n\n\n"; } #endregion Methods #region Example if ( html == 1 ) { help += "

VBScript usage example:

\n\n
";
			}
			else
			{
				help += "VBScript usage example:\n";
				help += new string( '\u2500', 23 ) + "\n\n";
			}

			help += SampleCode( );

			if ( html == 1 )
			{
				help += "
"; } help += "\n\n"; #endregion Example help = help.Replace( "\n", System.Environment.NewLine ); return help; } private string HelpTableRow( string template, string col1text, string col2text, string col3text, int html ) { if ( html == 1 ) { return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text ); } else { return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, "", "" ); } } private string HelpTableRow( string template, string col1text, string col2text, string col3text, string col4text, string col5text, int html ) { if ( html == 1 ) { return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text, col4text, col5text ); } else { return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, col4text, col5text ); } } public string ListProperties( ) { return Global.Common.Lists.Properties( this ); } public string ListToolTipIcons( ) { return Global.Common.Lists.ToolTipIcons( ); } public string SampleCode( ) { string code = string.Empty; code += "Set objSystemTrayMessage = CreateObject( \"RobvanderWoude.SystemTrayMessage\" )\n\n"; code += "With objSystemTrayMessage\n"; code += "\t.message = \"It is time for your daily backup.\" & vbCrLf & \"Please save and close all documents,\" & vbCrLf & \"and click this message when ready.\"\n"; code += "\t.title = \"Backup Time\"\n"; code += "\t.timeout = 1800\n"; code += "\t.wait = 1\n"; code += "\tWScript.Echo .ListProperties( )\n"; code += "\tWScript.Echo\n"; code += "\t.Show\n"; code += "\tIf .balloonclicked Then\n"; code += "\t\tWScript.Echo \"You clicked the tooltip balloon before the timeout elapsed\"\n"; code += "\tEnd If\n"; code += "End With\n\n"; code += "Set objSystemTrayMessage = Nothing"; return code; } public void Show( ) { if ( iconext == ".dll" ) { systrayicon = Global.IconExtractor.Extract( iconfile, iconindex, true ); } else { systrayicon = new System.Drawing.Icon( iconfile ); } notifyicon = new System.Windows.Forms.NotifyIcon( ); notifyicon.Icon = systrayicon; notifyicon.Visible = true; if ( !string.IsNullOrWhiteSpace( message ) ) { if ( _escapemessage ) { message = System.Text.RegularExpressions.Regex.Replace( message, @"(? { _balloonclicked = true; }; notifyicon.BalloonTipClosed += ( object sender, System.EventArgs e ) => { _balloonclicked = true; }; } notifyicon.ShowBalloonTip( _timeout, title, message, _tooltipicon ); } if ( _wait ) { _balloonclicked = false; while ( _timeout > 0 && !_balloonclicked ) { System.Threading.Thread.Sleep( 100 ); System.Windows.Forms.Application.DoEvents( ); _timeout -= 100; } notifyicon.Visible = false; notifyicon.Dispose( ); } } #endregion Methods #region Properties private static bool _balloonclicked = false; [System.Runtime.InteropServices.ComVisible( true )] public int balloonclicked { get { return ( _balloonclicked ? 1 : 0 ); } } private static System.Collections.Generic.List _debuginfo = new System.Collections.Generic.List( ); [System.Runtime.InteropServices.ComVisible( true )] public string debuginfo { get { return string.Join( "\n", _debuginfo.ToArray( ) ); } } private static System.Collections.Generic.List _errors = new System.Collections.Generic.List( ); [System.Runtime.InteropServices.ComVisible( true )] public string errors { get { return string.Join( "\n", _errors.ToArray( ) ); } } private static bool _escapemessage = true; [System.Runtime.InteropServices.ComVisible( true )] public int escapemessage { get { return ( _escapemessage ? 1 : 0 ); } set { _escapemessage = ( value == 1 ); } } private static string _iconfile = defaulticonfile; [System.Runtime.InteropServices.ComVisible( true )] public string iconfile { get { return _iconfile; } set { if ( System.IO.File.Exists( value ) ) { _iconfile = System.IO.Path.GetFullPath( value ); } else if ( iconext == ".dll" || iconext == ".exe" ) { foreach ( string folder in searchpath ) { if ( System.IO.File.Exists( System.IO.Path.Combine( folder, value ) ) ) { _iconfile = System.IO.Path.Combine( folder, value ); break; } } if ( !System.IO.File.Exists( _iconfile ) ) { _debuginfo.Add( timestamp + "Invalid path to icon file or library, using default icon file \"" + defaulticonfile + "\" and index " + defaulticonindex + " instead" ); _errors.Add( Global.Common.TimeStamp( ) + "Invalid path to icon file or library, using default icon file \"" + defaulticonfile + "\" and index " + defaulticonindex + " instead" ); _iconfile = defaulticonfile; _iconindex = defaulticonindex; } } if ( iconfile.EndsWith( "shell32.dll", System.StringComparison.InvariantCultureIgnoreCase ) ) { iconindex = iconindex.LimitToRange( 1, 305 ); } } } [System.Runtime.InteropServices.ComVisible( false )] private static string iconext { get { return System.IO.Path.GetExtension( _iconfile ).ToLower( ); } } private static int _iconindex = defaulticonindex; [System.Runtime.InteropServices.ComVisible( true )] public int iconindex { get { return _iconindex; } set { if ( _iconfile.EndsWith( "shell32.dll", System.StringComparison.InvariantCultureIgnoreCase ) ) { _iconindex = value.LimitToRange( 1, 305 ); } else { _iconindex = value; } } } private static string _message = string.Empty; [System.Runtime.InteropServices.ComVisible( true )] public string message { get { return _message; } set { _message = value.Trim( ); } } private static int _timeout = defaulttimeout * 1000; [System.Runtime.InteropServices.ComVisible( true )] public int timeout { get { return _timeout / 1000; } set { if ( value < 1 ) { _debuginfo.Add( timestamp + "Cannot set timeout to a value less than 1 second, using the minimum of 1 second" ); _timeout = 1000; } else { _timeout = value * 1000; } } } public static string timestamp => Global.Common.TimeStamp( ); private static string _title = defaulttitle; [System.Runtime.InteropServices.ComVisible( true )] public string title { get { return _title; } set { if ( string.IsNullOrWhiteSpace( value ) ) { _title = defaulttitle; } else { _title = value.Trim( ); } } } private static System.Windows.Forms.ToolTipIcon _tooltipicon = defaulttooltipicon; [System.Runtime.InteropServices.ComVisible( true )] public string tooltipicon { get { return _tooltipicon.ToString( ); } set { if ( !System.Enum.TryParse( value, true, out _tooltipicon ) ) { _tooltipicon = defaulttooltipicon; } } } [System.Runtime.InteropServices.ComVisible( true )] public string Version { get { return Global.Common.ProgramInfo.FileVersion; } } private static bool _wait = true; [System.Runtime.InteropServices.ComVisible( true )] public int wait { get { return ( _wait ? 1 : 0 ); } set { _wait = ( value == 1 ); } } #endregion Properties } }