blob: 21a00349ff8c7596be5dcb3e2de43634965ecf1d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// 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.
namespace WixToolset.Test.BA
{
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class MessagePump
{
const uint PM_REMOVE = 1;
[DllImport("user32.dll", ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PeekMessageW(ref Message pMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
[DllImport("user32.dll", ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool TranslateMessage(ref Message pMsg);
[DllImport("user32.dll", ExactSpelling = true)]
public static extern IntPtr DispatchMessageW(ref Message pMsg);
public static void ProcessMessages(int maxMessages)
{
for (int i = 0; i < maxMessages; i++)
{
Message message = new Message();
if (!PeekMessageW(ref message, IntPtr.Zero, 0, 0, PM_REMOVE))
{
break;
}
TranslateMessage(ref message);
DispatchMessageW(ref message);
}
}
}
}
|