protected override void WndProc(ref Message m) { try { if (wasException) { base.WndProc(ref m); return; } if (!systemReady) { if (m.Msg == NativeMethods.CM_STARTENGINE) { ActivateEngine(); return; } if ((m.Msg == NativeMethods.WM_CLOSE) || (m.Msg == NativeMethods.WM_QUIT) || (m.Msg == NativeMethods.WM_QUERYENDSESSION)) { UnloadAll(); } base.WndProc(ref m); return; } else //do it only if the system is ready { if (context.Dispatch(ref m)) { return; } int code = m.Msg; switch (code) { case NativeMethods.WM_ACTIVATEAPP: // The WParam value identifies what is occurring. bool appActive = (((int)m.WParam != 0)); { if (GlobalSettings.HideOnClick) { if (!appActive) { if (Manager.Visible && (!Manager.Fading)) { if (!context.HookActive) { ChangeVisibility(); } } } } } break; case NativeMethods.WM_CLOSE: case NativeMethods.WM_QUIT: this.UnloadAll(); break; case NativeMethods.WM_QUERYENDSESSION: this.UnloadAll(); break; case NativeMethods.CM_CHECKUPDATE: ShowNewVersion(); break; case NativeMethods.WM_POWERBROADCAST: if (m.WParam == (IntPtr)NativeMethods.PBT_APMRESUMEAUTOMATIC) { context.HidePulsar(); if (Settings.Default.ShowPulsar) { Pulsar.RestoreAlpha(); Pulsar.Alpha = 60; context.ShowPulsar(); Pulsar.DeactivatePulsar(); } } break; case NativeMethods.CM_RBUTTONDOWN: { if (GlobalSettings.UseMouseActivation) { if (GlobalSettings.UseRightClick) { TraceDebug.Trace("CM_RBUTTONDOWN"); if (!trackRightDown) { trackRightDown = true; if (!context.Manager.Visible) { timerIntercept.Enabled = true; } } } } break; } case NativeMethods.CM_RBUTTONUP: { if (GlobalSettings.UseMouseActivation) { if (GlobalSettings.UseRightClick) { TraceDebug.Trace("CM_RBUTTONUP"); timerIntercept.Enabled = false; if (trackRightDown) { trackRightDown = false; if (!trackRightUp) { trackRightUp = true; MouseHook.PauseIntercept(); VirtualMouse.RightClick(); } else { trackRightUp = false; MouseHook.ResumeIntercept(); } } } } break; } case NativeMethods.CM_MBUTTONUP: case NativeMethods.CM_XBUTTONUP: if (GlobalSettings.UseMouseActivation) { int xButton = (int)m.WParam; MouseHookButton hookButton = MouseHookButton.None; if (m.Msg == NativeMethods.CM_MBUTTONUP) { hookButton = MouseHookButton.Wheel; } else { switch (xButton) { case NativeMethods.XBUTTON1: hookButton = MouseHookButton.XButton1; break; case NativeMethods.XBUTTON2: hookButton = MouseHookButton.XButton2; break; default: hookButton = MouseHookButton.None; break; } } if (GlobalSettings.MouseHook != hookButton) { return; } Keys modifiers = (Keys)m.LParam; if (GlobalSettings.MouseModifiers != modifiers) { return; } ActivateUsingMouse(true); } return; case NativeMethods.CM_DESKTOPCLICK: if (GlobalSettings.UseMouseActivation) { if (Manager != null) { if (context.HookActive) { return; } if (GlobalSettings.DesktopClick) { ActivateUsingMouse(true); } } } return; case NativeMethods.WM_HOTKEY: if (NativeMethods.IsMetroActive()) { return; } if (GlobalSettings.UseKeyboardActivation) { if (Manager != null) { if (context.HookActive) { return; } if (GlobalSettings.CircleSelector) { if (ringKeys != null) { if (((int)m.WParam) == (ringKeys.Id)) { Manager.SwitchRing(); } } } if (hotKeys != null) { if (((int)m.WParam) == (hotKeys.Id)) { if (Manager.Visible) { if (NativeMethods.GetForegroundWindow() != Manager.Handle) { Manager.Visible = false; Manager.Rotate(0); ChangeVisibility(); return; } } ChangeVisibility(); } } } } return; case NativeMethods.CM_SPLASHCLOSE: if (splashScreen != null) { splashScreen.Dispose(); splashScreen = null; } break; default: break; } base.WndProc(ref m); } } catch (Exception ex) { TraceDebug.Trace(ex); if (!wasException) { wasException = true; throw new KrentoEngineException("Krento Engine Error: ", ex); } } }