Paul G. Tobey said:
You have to call it from the UI thread. I don't recognize what a TestUI
thread is...as far as I can see from your code, TestUI is a Control.
Paul T.
message I call it from 'TestUI.cs' thread. I create and display TestUI from
'Form1.cs' I do ;
testUI = new TestUI();
this.Controls.Add(testUI);
testUI.Show();
How can I check that I am calling purge from within TestUI thread and
not
some other thread?
:
And you're calling this purge process from the UI thread of this
application?
Paul T.
in
message Hi,
Mouse Pressed are not being purged, inaddition, the call to
PeekMessage()
is
returning 120 after it loops through while a few times. See code
below
( I
made changes based on previous input from this group);
///
/// TestUI.cs this class uses PeekMessage() PInvoke;
///
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Security;
using CSFittingFormula;
using System.Text;
namespace MyNamespace {
class TestUI : Control {
private void PurgeMouseEvents() {
NativeApi.MessageQueueFunctions.MSG msg=new
NativeApi.MessageQueueFunctions.MSG();
while (NativeApi.MessageQueueFunctions.PeekMessage(out msg,
IntPtr.Zero,
NativeApi.MessageQueueFunctions.WM_MOUSEFIRST,
NativeApi.MessageQueueFunctions.WM_MOUSELAST,
NativeApi.MessageQueueFunctions.PM_REMOVE |
NativeApi.MessageQueueFunctions.PM_NOYIELD)) { }
int error = Marshal.GetLastWin32Error();
}
}
}
///
/// NativeApi.cs - this class does pinvoke and is compiled into a
.NET
CF
DLL
///
using System;
using System.Runtime.InteropServices;
namespace NativeApi {
public sealed class MessageQueueFunctions {
public const uint WM_MOUSEFIRST = 0x0200;
public const uint WM_MOUSELAST = 0x020D;
// PeekMessage() Options
public const uint PM_NOREMOVE = 0x0000;
public const uint PM_REMOVE = 0x0001;
public const uint PM_NOYIELD = 0x0002;
[StructLayout(LayoutKind.Sequential)]
public struct MSG {
public IntPtr hwnd;
public uint message;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public int pt_x;
public int pt_y;
}
[DllImport("coredll.dll", EntryPoint = "PeekMessageW",
SetLastError
=
true)]
public static extern bool PeekMessage(out MSG lpMsg, IntPtr hWnd,
uint
wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
[DllImport("coredll.dll", EntryPoint = "GetMessageW",
SetLastError =
true)]
public static extern bool GetMessage(out MSG lpMsg, IntPtr hWnd,
uint
wMsgFilterMin, uint wMsgFilterMax);
}
}