main
cs 39 lines 1.35 KB
Raw
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
3 namespace 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 }