/// <summary>
        /// Gets the Snarl system version number. This represents the system build number
        /// and can be used to uniquely identify the version of Snarl running.
        /// </summary>
        /// <returns>Snarl system version number. Zero on failure.</returns>
        public static Int32 GetVersionEx()
        {
            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd = (Int16)SNARL_COMMAND.SNARL_GET_VERSION_EX;

            return(Send(message, IntPtr.Zero));
        }
        /// <summary>
        /// Hides the specified snarl message.
        /// </summary>
        /// <param name="handle">The handle returned from <see cref="ShowMessage"/> or <see cref="ShowMessageEx"/>.</param>
        /// <returns><c>true</c> if the message was hidden, otherwise <c>false</c>.</returns>
        public static bool HideMessage(Int32 handle)
        {
            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd = (Int16)SNARL_COMMAND.SNARL_HIDE;
            message.Id  = handle;

            return(Convert.ToBoolean(Send(message, IntPtr.Zero)));
        }
        /// <summary>
        /// Sets the timeout of the specified notification to <c>timeout</c> seconds.
        /// </summary>
        /// <param name="handle">The message handle.</param>
        /// <param name="timeout">The timeout in seconds.</param>
        /// <returns><see cref="M_RESULT"/> value indicating the result of the Snarl request.</returns>
        public static M_RESULT SetTimeout(Int32 handle, Int32 timeout)
        {
            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd      = (Int16)SNARL_COMMAND.SNARL_SET_TIMEOUT;
            message.Id       = handle;
            message.LngData2 = timeout;

            return(ConvertToMResult(Send(message, IntPtr.Zero)));
        }
        /// <summary>
        /// Registers an alert type for the specified application. The application must have been previously registered with <see cref="RegisterConfig"/>.
        /// </summary>
        /// <param name="appName">The name of the application.</param>
        /// <param name="alert">The name of the alert.</param>
        /// <returns><see cref="M_RESULT"/> value indicating the result of the Snarl request.</returns>
        public static M_RESULT RegisterAlert(string appName, string alert)
        {
            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd   = (Int16)SNARL_COMMAND.SNARL_REGISTER_ALERT;
            message.Title = StringToUtf8(appName);
            message.Text  = StringToUtf8(alert);

            return(ConvertToMResult(Send(message, IntPtr.Zero)));
        }
        /// <summary>
        /// Updates the contents of an existing Snarl message.
        /// </summary>
        /// <param name="handle">The handle of the existing Snarl message.</param>
        /// <param name="title">The new title.</param>
        /// <param name="text">The new text.</param>
        /// <param name="iconPath">The new icon path.</param>
        /// <returns><c>M_OK</c> on success. <see cref="M_RESULT"/> value indicating the result of the Snarl request.</returns>
        public static M_RESULT UpdateMessage(Int32 handle, string title, string text, string iconPath)
        {
            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd   = (Int16)SNARL_COMMAND.SNARL_UPDATE;
            message.Id    = handle;
            message.Title = StringToUtf8(title);
            message.Text  = StringToUtf8(text);
            message.Icon  = StringToUtf8(iconPath);

            return(ConvertToMResult(Send(message, IntPtr.Zero)));
        }
        /// <summary>
        /// Displays a Snarl message.
        /// </summary>
        /// <param name="title">The title of the message.</param>
        /// <param name="text">The text of the message.</param>
        /// <param name="timeout">The timeout in seconds. Zero means the message is displayed indefinitely.</param>
        /// <param name="iconPath">The location of a PNG image which will be displayed alongside the message text.</param>
        /// <param name="client">The client handle to send messages back to.</param>
        /// <param name="reply">The windows message to send to the client if the Snarl message is clicked.</param>
        /// <returns><c>Message id</c> on success. <c>M_RESULT</c> on failure.</returns>
        public static Int32 ShowMessage(string title, string text, Int32 timeout, string iconPath, IntPtr client, WindowsMessage reply)
        {
            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd      = (Int16)SNARL_COMMAND.SNARL_SHOW;
            message.Title    = StringToUtf8(title);
            message.Text     = StringToUtf8(text);
            message.Icon     = StringToUtf8(iconPath);
            message.LngData2 = client.ToInt32();
            message.Id       = (Int32)reply;
            message.Timeout  = timeout;

            return(Send(message, client));
        }
        /// <summary>
        /// Determines whether the specified message is still visible.
        /// </summary>
        /// <param name="handle">The handle returned from <see cref="ShowMessage"/> or <see cref="ShowMessageEx"/>.</param>
        /// <returns><c>true</c> if the specified message is still visible; otherwise, <c>false</c>.</returns>
        public static bool IsMessageVisible(Int32 handle)
        {
            if (handle == 0)
            {
                return(false);
            }

            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd = (Int16)SNARL_COMMAND.SNARL_IS_VISIBLE;
            message.Id  = handle;

            return(Convert.ToBoolean(Send(message, IntPtr.Zero)));
        }
        /// <summary>
        /// Removes the application previously registered using <c>client</c>. Typically done as part of the application's shutdown procedure.
        /// </summary>
        /// <param name="client">The client handle used to register the application using <see cref="RegisterConfig"/>.</param>
        /// <returns><c>M_OK</c> if the revocation was successfule.</returns>
        public static M_RESULT RevokeConfig(IntPtr client)
        {
            if (client == IntPtr.Zero)
            {
                return(M_RESULT.M_INVALID_ARGS);
            }

            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd      = (Int16)SNARL_COMMAND.SNARL_REVOKE_CONFIG_WINDOW;
            message.LngData2 = client.ToInt32();
            client           = IntPtr.Zero;

            return(ConvertToMResult(Send(message, client)));
        }
        /// <summary>
        /// Registers and application configuration interface with Snarl.
        /// (Is the same as snRegisterConfig2 from the official API)
        /// </summary>
        /// <param name="client">The client windows handle.</param>
        /// <param name="appName">Name to be displayed in Snarl's "Registered Applications" list. This should match the title of your application.</param>
        /// <param name="reply">Message to send to application configuration interface window is the application name is double clicked in Snarl.</param>
        /// <param name="iconPath">A path to an icon that will be displayed alongside the application name in Snarl.</param>
        /// <returns><see cref="M_RESULT"/> value indicating the result of the Snarl request.</returns>
        public static M_RESULT RegisterConfig(IntPtr client, string appName, WindowsMessage reply, string iconPath)
        {
            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd      = (Int16)SNARL_COMMAND.SNARL_REGISTER_CONFIG_WINDOW_2;
            message.LngData2 = client.ToInt32();
            message.Id       = (Int32)reply;
            message.Title    = StringToUtf8(appName);
            if (!string.IsNullOrEmpty(iconPath))
            {
                message.Icon = StringToUtf8(iconPath);
            }

            return(ConvertToMResult(Send(message, client)));
        }
Beispiel #10
0
        /// <summary>
        /// Checks if Snarl is currently running and, if it is, retrieves the major and minor version numbers.
        /// Depricated, use GetVersionEx() instead.
        /// </summary>
        /// <param name="major">The major version number.</param>
        /// <param name="minor">The minor version number.</param>
        /// <returns><c>true</c> if Snarl is running, otherwise <c>false</c>.</returns>
        public static bool GetVersion(out UInt16 major, out UInt16 minor)
        {
            major = 0;
            minor = 0;

            SNARLSTRUCT message = new SNARLSTRUCT();

            message.Cmd = (Int16)SNARL_COMMAND.SNARL_GET_VERSION;

            Int32 version = Send(message, IntPtr.Zero);

            if (version > 0)
            {
                major = (UInt16)((version >> 16) & 0xFF);
                minor = (UInt16)(version & 0xFF);
                return(true);
            }
            else
            {
                return(false);
            }
        }