aboutsummaryrefslogtreecommitdiff
path: root/src/test/burn/TestBA/MessagePump.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/burn/TestBA/MessagePump.cs')
-rw-r--r--src/test/burn/TestBA/MessagePump.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/burn/TestBA/MessagePump.cs b/src/test/burn/TestBA/MessagePump.cs
new file mode 100644
index 00000000..21a00349
--- /dev/null
+++ b/src/test/burn/TestBA/MessagePump.cs
@@ -0,0 +1,39 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Test.BA
4{
5 using System;
6 using System.Runtime.InteropServices;
7 using System.Windows.Forms;
8
9 public class MessagePump
10 {
11 const uint PM_REMOVE = 1;
12
13 [DllImport("user32.dll", ExactSpelling = true)]
14 [return: MarshalAs(UnmanagedType.Bool)]
15 public static extern bool PeekMessageW(ref Message pMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
16
17 [DllImport("user32.dll", ExactSpelling = true)]
18 [return: MarshalAs(UnmanagedType.Bool)]
19 public static extern bool TranslateMessage(ref Message pMsg);
20
21 [DllImport("user32.dll", ExactSpelling = true)]
22 public static extern IntPtr DispatchMessageW(ref Message pMsg);
23
24 public static void ProcessMessages(int maxMessages)
25 {
26 for (int i = 0; i < maxMessages; i++)
27 {
28 Message message = new Message();
29 if (!PeekMessageW(ref message, IntPtr.Zero, 0, 0, PM_REMOVE))
30 {
31 break;
32 }
33
34 TranslateMessage(ref message);
35 DispatchMessageW(ref message);
36 }
37 }
38 }
39}