Exemple #1
0
 /// <summary>Sends a message to the game's window</summary>
 /// <param name="message">Message that will be sent</param>
 /// <param name="wParam">Value for the message's wParam</param>
 /// <param name="lParam">Value for the message's lParam</param>
 /// <returns>The value returned by the window procedure for the message</returns>
 private int sendMessage(
     UnsafeNativeMethods.WindowMessages message, int wParam, int lParam
     )
 {
     return(UnsafeNativeMethods.SendMessage(
                this.form.Handle, (uint)message, new IntPtr(wParam), new IntPtr(lParam)
                ).ToInt32());
 }
Exemple #2
0
        public void TestMouseButtonReleasedMessage(
            UnsafeNativeMethods.WindowMessages message, int wParam, MouseButtons button
            )
        {
            Mock <IMouseMessageSubscriber> subscriber = mockMouseSubscriber();

            subscriber.Expects.One.Method(x => x.MouseButtonReleased(0)).With(button);
            sendThreadMessage(message, wParam << 16, 0);

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #3
0
        public void TestMouseButtonReleasedMessage(
            UnsafeNativeMethods.WindowMessages message, int wParam, MouseButtons button
            )
        {
            IMouseMessageSubscriber subscriber = mockMouseSubscriber();

            Expect.Once.On(subscriber).Method("MouseButtonReleased").With(
                NMock2.Is.EqualTo(button)
                );
            sendMessage(message, wParam << 16, 0);

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #4
0
        /// <summary>Sends a message to the game's window</summary>
        /// <param name="message">Message that will be sent</param>
        /// <param name="wParam">Value for the message's wParam</param>
        /// <param name="lParam">Value for the message's lParam</param>
        private void sendThreadMessage(
            UnsafeNativeMethods.WindowMessages message, int wParam, int lParam
            )
        {
            // Post the requested message to the thread's message queue
            // (and not the window's message queue, thus the window procedure will
            // not be invoked at this point)
#pragma warning disable 0618 // Unmanaged thread ID can change for managed threads
            bool posted = UnsafeNativeMethods.PostThreadMessage(
                AppDomain.GetCurrentThreadId(),
                (uint)message,
                new IntPtr(wParam),
                new IntPtr(lParam)
                );
#pragma warning restore 0618

            if (!posted)
            {
                throw new Exception("Failed posting a message to the current thread");
            }

            // Now have our thread run the message pump once to process the new message
            Application.DoEvents();
        }