Flush Events

  • Thread starter Mobile Application Developer (MAD)
  • Start date
M

matt

Thanks Paul, I had always thought of wParam as a WORD and lParam as a
DWORD until I looked them up... looks like I didn't look up far
enough :) e.g. the definition of int and long!

Matt
 
P

Paul G. Tobey [eMVP]

And you're calling this purge process from the UI thread of this
application?

Paul T.
 
M

Mobile Application Developer (MAD)

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?

Paul G. Tobey said:
And you're calling this purge process from the UI thread of this
application?

Paul T.

Mobile Application Developer (MAD) said:
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);
}
}
 
P

Paul G. Tobey [eMVP]

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.

Mobile Application Developer (MAD) said:
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?

Paul G. Tobey said:
And you're calling this purge process from the UI thread of this
application?

Paul T.

Mobile Application Developer (MAD) said:
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);
}
}
 
M

Mobile Application Developer (MAD)

Ok, I'll do it from Form1.

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.

Mobile Application Developer (MAD) said:
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?

Paul G. Tobey said:
And you're calling this purge process from the UI thread of this
application?

Paul T.

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);
}
}
 
P

Paul G. Tobey [eMVP]

You may already be doing it from the UI thread. The location, in terms of
classes, has NOTHING to do with the execution context, which is what a
thread is. It seems like you should learn a bit about threading,
particularly in the context of the .NET CF.

Paul T.

Mobile Application Developer (MAD) said:
Ok, I'll do it from Form1.

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.

Mobile Application Developer (MAD) said:
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);
}
}
 
M

Mobile Application Developer (MAD)

Yeah, I admit I am a bit weak on threading on .net cf.

Paul G. Tobey said:
You may already be doing it from the UI thread. The location, in terms of
classes, has NOTHING to do with the execution context, which is what a
thread is. It seems like you should learn a bit about threading,
particularly in the context of the .NET CF.

Paul T.

Mobile Application Developer (MAD) said:
Ok, I'll do it from Form1.

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top