Пример #1
0
        /// <summary>
        /// A method which can be called from within a overridden <see cref="Form.WndProc"/> method to raise the <see cref="ApplicationActivated"/> and the <see cref="ApplicationDeactivated"/> events.
        /// </summary>
        /// <param name="form">The form from which WndProc method this method was called.</param>
        /// <param name="m">The Windows <see cref="T:System.Windows.Forms.Message" /> to process.</param>
        /// <returns><c>true</c> if the <see cref="T:System.Windows.Forms.Message m"/> was handled by the method, <c>false</c> otherwise.</returns>
        public static bool WndProcApplicationActivateHelper(Form form, ref Message m)
        {
            try
            {
                if (m.Msg == WM_ACTIVATEAPP)
                {
                    if (m.WParam != IntPtr.Zero)
                    {
                        // the application is getting activated..
                        ApplicationActivated?.Invoke(form, new EventArgs());
                    }
                    else
                    {
                        // the application is getting deactivated..
                        ApplicationDeactivated?.Invoke(form, new EventArgs());
                    }

                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                // log the exception..
                ExceptionLogger.LogError(ex);
                return(false);
            }
        }
Пример #2
0
 protected virtual void OnActivateApp(bool active)
 {
     if (active)
     {
         ApplicationActivated?.Invoke(this, EventArgs.Empty);
     }
     else
     {
         ApplicationDeactivated?.Invoke(this, EventArgs.Empty);
     }
 }