Пример #1
0
		public static MSG Create(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
		{
			MSG m = new MSG();
			m.hWnd = hWnd;
			m.message = msg;
            // Try to get an enum for the message type
            //m.MsgType = (WinMsgType)msg;
			m.wParam = wParam;
			m.lParam = lParam;
			m.time = 0;
			m.pt = new POINT();

			return m;
		}
Пример #2
0
        public static int mainMessageLoop(IntPtr hAccelTable)
        {
            MSG msg = new MSG();

            // loop until WM_QUIT(0) received
            while (User32.GetMessage(out msg, IntPtr.Zero, 0, 0) != 0)
            {
                // now, handle window messages
                //if(!User32.TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                {
                    User32.TranslateMessage(ref msg);
                    User32.DispatchMessage(ref msg);
                }
            }

            return (int)msg.wParam;                 // return nExitCode of PostQuitMessage()
        }
Пример #3
0
        int RunLoop()
        {
            MSG msg = new MSG();

            // loop until WM_QUIT(0) received
            int retValue;
            while ((retValue = User32.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)
            {
                if (retValue == -1)
                    throw new Exception("GetMessage returned -1");

                // now, handle window messages
                //if(!User32.TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                {
                    User32.TranslateMessage(ref msg);
                    User32.DispatchMessage(ref msg);
                }
            }

            return (int)msg.wParam;                 // return nExitCode of PostQuitMessage()
        }
Пример #4
0
        public virtual void Run(Window mainWindow)
        {
            fMainWindow = mainWindow;

            if (fMainWindow != null)
            {
                fMainWindow.IsApplicationWindow = true;
                fMainWindow.Show();
                //fMainWindow.Update();
            }

            MSG msg = new MSG();

            int retValue =0;
            while ((retValue = User32.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)
            {
                if (retValue == -1)
                    throw new Exception("GetMessage returned a -1 value");

                User32.TranslateMessage(ref msg);
                User32.DispatchMessage(ref msg);
            }
        }
Пример #5
0
        public override void OnNext(MSG aMSG)
        {
            int msg = aMSG.message;
            IntPtr retValue = IntPtr.Zero;

            //Console.WriteLine("MouseDevice.Callback: ID = {0} Msg = {1} - {2}", this.fMouseID, msg, MessageDecoder.MsgToString(msg));
            switch (msg)
            {
                case (int)WinMsg.WM_INPUT:
                    {
                        uint dwSize = 0;

                        // First find out how much space is needed to store the data that will
                        // be retrieved.
                        User32.GetRawInputData(aMSG.lParam, User32.RID_INPUT, IntPtr.Zero, ref dwSize,
                            (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER)));

                        // Now allocate the specified number of bytes
                        IntPtr buffer = Marshal.AllocHGlobal((int)dwSize);

                        // Now get the data for real, and check the size to see
                        // if we got what we thought we should get.
                        if (User32.GetRawInputData(aMSG.lParam, User32.RID_INPUT, buffer, ref dwSize,
                            (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER))) == dwSize)
                        {
                            RAWINPUT raw = (RAWINPUT)Marshal.PtrToStructure(buffer, typeof(RAWINPUT));

                            // At this point, we should have raw mouse data
                            if (null != MouseActivityEvent)
                            {
                                MouseActivityArgs mactivity = MouseActivityArgs.CreateFromRawInput(this, raw.data.mouse);

                                // Send the message to all those who are interested in receiving it.
                                MouseActivityEvent(this, mactivity);
                            }

                            Marshal.FreeHGlobal(buffer);
                        }
                    }
                    break;

                default:
                    retValue = User32.DefWindowProc(aMSG.hWnd, msg, aMSG.wParam, aMSG.lParam);
                    //retValue = User32.DefRawInputProc(RAWHID, nInput, sizeof);
                    break;

            }
        }
Пример #6
0
        /// <summary>
        /// </summary>
        // The message processing chain is like this:
        // First, in Start(), we're pulling messages off of the 
        // message queue using GetMessage().  
        // 2) Translate that message into a proper keyboard 
        //    message using TranslateMessage()
        // 3) Dispatch the message using the WindowProc for 
        //    the window, namely, fWindowProc.
        // 4) fWindowProc being this.Callback(), Callback() then
        //    packages up the message into a Message object, and
        //    Calls this.DispatchMessage()
        // 5) If DispatchMessage() can deal with it alone, it
        //    will deal with it.  If it can't, then it then
        //    calls the default window dispatch function
        // 6) DefWindowProc
        //
        // And that's about it.
        public virtual void Run()
        {
            MSG msg = new MSG();

            int retValue;
            while ((retValue = User32.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)
            {
                // If we get a return value == -1, then there was some type of error
                // So, we just throw an exception
                if (retValue == -1)
                    throw new Exception("GetMessage returned -1");

                /// Messages that come in here are typically keyboard
                /// mouse, and timer events.
                /// For the keyboard ones, there may be Hot-Key combinations
                /// that need to be translated into regular characters.  So,
                /// we first call the TranslateMessage() function to do that.
                User32.TranslateMessage(ref msg);

                /// Now, we want to actually handle the message.  
                /// There are three different cases where we will receive
                /// messages.
                /// 1) Thread messages - These messages have a msg.hWnd == 0
                /// Right now we will do nothing with those.
                /// 2) Messages with a msg.hWnd == Handle
                /// These are messages that are meant for the specific window
                /// that this code is dealing with.  
                /// 3) Messages with a msg.hWnd != 0 && msg.hWnd != Handle
                /// These are messages that are meant for a child window of our managed
                /// windows.  This would be a User32 Window that is a child window
                /// of the one we are handling.  These we allow the system to dispatch
                /// as it normally would.
                /// By covering these three cases, we're all set.

                //if (msg.hWnd == Handle)
                //	OnMessage(this, msg);
                //else if (msg.hWnd != IntPtr.Zero)
                User32.DispatchMessage(ref msg);

            }
        }