Example #1
0
        public void WindowFormRun()
        {
            System.Windows.Interop.MSG msg = new System.Windows.Interop.MSG();

            while (RunWinForm)
            {
                if (PeekMessage(ref msg, new HandleRef(this, IntPtr.Zero), (WindowMessage)0, (WindowMessage)0, 1))
                {
                    if (msg.message == (int)WindowMessage.WM_QUIT)
                    {
                        break;
                    }
                    if (GameWindowHwnd != IntPtr.Zero && msg.hwnd == GameWindowHwnd)
                    {
                        System.Windows.Forms.Application.DoEvents();
                    }
                    TranslateMessage(ref msg);
                    DispatchMessage(ref msg);
                }
                else
                {
                    unsafe
                    {
                        fixed(byte *p = &KeyBoardStats[0])
                        {
                            GetKeyboardState(p);
                        }
                    }

                    System.Windows.Forms.Application.RaiseIdle(null);// new EventArgs());
                }
            }
        }
Example #2
0
        /// <summary>
        /// Convert a WinForms MSG to a WPF MSG.
        /// </summary>
        public static System.Windows.Interop.MSG ConvertToInteropMsg(System.Windows.Forms.Message m)
        {
            System.Windows.Interop.MSG msg = new System.Windows.Interop.MSG();

            msg.hwnd    = m.HWnd;
            msg.lParam  = m.LParam;
            msg.message = m.Msg;
            msg.wParam  = m.WParam;

            return(msg);
        }
        /// <summary>
        ///     Converts from a System.Windows.Interop.MSG to a System.Windows.Forms.Message
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        internal static SWF.Message ToSystemWindowsFormsMessage(System.Windows.Interop.MSG msg)
        {
            SWF.Message msg2 = new SWF.Message();

            msg2.HWnd   = msg.hwnd;
            msg2.LParam = msg.lParam;
            msg2.Msg    = msg.message;
            msg2.WParam = msg.wParam;

            return(msg2);
        }
 public static System.Windows.Interop.MSG MSGFromOleMSG(ref Microsoft.VisualStudio.OLE.Interop.MSG oleMsg)
 {
     System.Windows.Interop.MSG msg = new System.Windows.Interop.MSG();
     msg.hwnd    = oleMsg.hwnd;
     msg.message = (int)oleMsg.message;
     msg.wParam  = oleMsg.wParam;
     msg.lParam  = oleMsg.lParam;
     msg.time    = (int)oleMsg.time;
     msg.pt_x    = oleMsg.pt.x;
     msg.pt_y    = oleMsg.pt.y;
     return(msg);
 }
        /// <summary>
        ///     Converts from a System.Windows.Forms.Message to a System.Windows.Interop.MSG
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        internal static System.Windows.Interop.MSG ToSystemWindowsInteropMSG(SWF.Message msg)
        {
            SW.Interop.MSG msg2 = new SW.Interop.MSG();

            msg2.hwnd    = msg.HWnd;
            msg2.lParam  = msg.LParam;
            msg2.message = msg.Msg;
            msg2.pt_x    = 0;
            msg2.pt_y    = 0;
            msg2.time    = MS.Win32.SafeNativeMethods.GetMessageTime();
            msg2.wParam  = msg.WParam;
            return(msg2);
        }
Example #6
0
        private void OnThreadFilterMessage(ref System.Windows.Interop.MSG msg, ref bool handled)
        {
            if (handled)
            {
                return;
            }

            //var desktopWindowXamlSourceNative = _xamlSource.GetInterop<IDesktopWindowXamlSourceNative2>();
            //if (desktopWindowXamlSourceNative != null)
            //{
            //    handled = desktopWindowXamlSourceNative.PreTranslateMessage(msg);
            //}
        }
Example #7
0
 // 判断是否按下热键
 private void ThreadPreprocessMessageMethod(ref System.Windows.Interop.MSG m, ref bool handled)
 {
     if (!handled)
     {
         if (m.message == 0x0312)// 如果m.message的值为0x0312那么表示用户按下了热键
         {
             if (m.wParam.ToInt32() == REC_HOT_KEY_ID)
             {
                 Record();
             }
             else if (m.wParam.ToInt32() == EXE_HOT_KEY_ID)
             {
                 Execute();
             }
             handled = true;
         }
     }
 }
Example #8
0
        public void WindowsRun(Dispatcher dispatcher)
        {
            System.Windows.Interop.MSG msg            = new System.Windows.Interop.MSG();
            SynchronizationContext     oldSyncContext = null;
            SynchronizationContext     newSyncContext = null;

            oldSyncContext = SynchronizationContext.Current;
            newSyncContext = new DispatcherSynchronizationContext(dispatcher);
            SynchronizationContext.SetSynchronizationContext(newSyncContext);
            while (true)
            {
                if (PeekMessage(ref msg, new HandleRef(this, IntPtr.Zero), (WindowMessage)0, (WindowMessage)0, 1))
                {
                    if (msg.message == (int)WindowMessage.WM_QUIT)
                    {
                        break;
                    }
                    bool handled = System.Windows.Interop.ComponentDispatcher.RaiseThreadMessage(ref msg);
                    if (GameWindowHwnd != IntPtr.Zero && msg.hwnd == GameWindowHwnd)
                    {
                        System.Windows.Forms.Application.DoEvents();
                    }
                    if (handled == false)
                    {
                        TranslateMessage(ref msg);
                        DispatchMessage(ref msg);
                    }
                }
                else
                {
                    unsafe
                    {
                        fixed(byte *p = &KeyBoardStats[0])
                        {
                            GetKeyboardState(p);
                        }
                    }
                    System.Windows.Interop.ComponentDispatcher.RaiseIdle();
                }
            }

            SynchronizationContext.SetSynchronizationContext(oldSyncContext);
        }
        public static bool HandleComponentMessage(Microsoft.VisualStudio.OLE.Interop.MSG msg)
        {
            // Swallow all keyboard input
            if ((msg.message >= VSIntegrationUtilities.NativeMethods.WM_KEYFIRST &&
                 msg.message <= VSIntegrationUtilities.NativeMethods.WM_KEYLAST) ||
                (msg.message >= VSIntegrationUtilities.NativeMethods.WM_IME_FIRST &&
                 msg.message <= VSIntegrationUtilities.NativeMethods.WM_IME_LAST))
            {
                /*
                 * // Special case when the Alt key is down
                 * if (Keyboard.IsKeyDown(Key.LeftAlt) ||
                 *  Keyboard.IsKeyDown(Key.RightAlt))
                 * {
                 * // Give the main window focus. This will allow it to handle
                 * // the ALT + <key> commands and bring up the menu.
                 * //
                 * // This works because we lose focus and revoke IOleComponent tracking status
                 * Utilities.NativeMethods.SetFocus(Shell.MainWindow.Handle);
                 * return false;
                 * }
                 * }
                 */

                // Otherwise it's our message. Don't let the shell translate it
                // into some goofy command.

                // Give WPF a chance to translate.
                System.Windows.Interop.MSG windowsMsg = NativeMethods.MSGFromOleMSG(ref msg);
                if (!System.Windows.Interop.ComponentDispatcher.RaiseThreadMessage(ref windowsMsg))
                {
                    VSIntegrationUtilities.NativeMethods.TranslateMessage(ref msg);
                    VSIntegrationUtilities.NativeMethods.DispatchMessage(ref msg);
                }
                return(true);
            }

            return(false);
        }
 public static extern IntPtr DispatchMessage([In] ref System.Windows.Interop.MSG msg);
 public static extern bool TranslateMessage([In, Out] ref System.Windows.Interop.MSG msg);
 protected override bool TranslateAcceleratorCore(ref System.Windows.Interop.MSG msg, System.Windows.Input.ModifierKeys modifiers)
 {
     return(default(bool));
 }
Example #13
0
 public static extern bool PeekMessage([In, Out] ref System.Windows.Interop.MSG msg, HandleRef hwnd, WindowMessage msgMin, WindowMessage msgMax, int remove);