示例#1
0
        /// <summary>
        /// Updates the status and returns true if this was successful.
        /// </summary>
        private bool UpdateStatus()
        {
            TrayMeClass trayMe = new TrayMeClass();

            try
            {
                if (trayMe.IsHooked())
                {
                    if (!isWindowTrayed)
                    {
                        buttonTrayMe.Text = "Un-&Tray Me";
                        isWindowTrayed    = true;
                    }
                }
                else
                {
                    if (isWindowTrayed)
                    {
                        buttonTrayMe.Text = "&Tray Me!";
                        isWindowTrayed    = false;
                    }
                }

                if (!buttonTrayMe.Enabled)
                {
                    buttonTrayMe.Enabled = true;
                }

                return(true);
            }
            catch (DllNotFoundException)
            {
                if (buttonTrayMe.Enabled)
                {
                    buttonTrayMe.Enabled = false;
                    buttonTrayMe.Text    = "Missing Dll";
                }
            }
            catch (EntryPointNotFoundException)
            {
                if (buttonTrayMe.Enabled)
                {
                    buttonTrayMe.Enabled = false;
                    buttonTrayMe.Text    = "Bad Dll";
                }
            }

            return(false);
        }
示例#2
0
        /// <summary>
        /// Determines whether a window is currently attached.
        /// </summary>
        /// <returns>true, if there is no window attached or the attached window is now detached; otherwise, false.</returns>
        public bool DoDetach()
        {
            // Check for trayed window
            TrayMeClass trayMe = new TrayMeClass();

            if (trayMe.IsHooked())
            {
                if (trayMe.HookTrayWindow(IntPtr.Zero, IntPtr.Zero) == true)
                {
                    MessageBox.Show(this, "Could not unhook currently trayed window.", "TrayMe Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                UpdateStatus();
            }

            return(true);
        }