[C#] How can I clear Messages Queue ?

S

Sergey Bogdanov

Your link has everything to clear message queue, just assemble all
pieces together. Something like this:

using System.Runtime.InteropServices;

....

struct MSG
{
IntPtr hwnd;
uint message;
IntPtr wParam;
IntPtr lParam;
int time;
int ptX;
int ptY;
}

[DllImport("coredll")]
extern static bool PeekMessage(out Message Msg, uint hWnd, uint
wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);

const uint PM_REMOVE = 1;

void ClearMessages()
{
MSG msg;
while (PeekMessage(out msg, 0, 0, 0, PM_REMOVE));
}

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
G

Guest

Ok, thank you.
I have an other question. PM_REMOVE = 1, is it necessary ?
because I have a message in my form - mymessage = 1.
Is it a problem (I think yes) ?
How can I do ?

Thanks.

Sergey Bogdanov said:
Your link has everything to clear message queue, just assemble all
pieces together. Something like this:

using System.Runtime.InteropServices;

....

struct MSG
{
IntPtr hwnd;
uint message;
IntPtr wParam;
IntPtr lParam;
int time;
int ptX;
int ptY;
}

[DllImport("coredll")]
extern static bool PeekMessage(out Message Msg, uint hWnd, uint
wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);

const uint PM_REMOVE = 1;

void ClearMessages()
{
MSG msg;
while (PeekMessage(out msg, 0, 0, 0, PM_REMOVE));
}

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi,

I'd like to clear only the messages queue. Not with DoEvents.
I found this :
http://groups-beta.google.com/group...ae6b0b5?q=PeekMessage&rnum=1#84c1ea607ae6b0b5
But I don't know how I can use it.

Somebody could help me ?
Do you have a function which clear up the message queue or a link ?

Thanks.

Best Regards
 
S

Sergey Bogdanov

If you don't like PM_REMOVE, replace it with actual value - 1. About
what PM_REMOVE means see MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefpeekmessage.asp


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Ok, thank you.
I have an other question. PM_REMOVE = 1, is it necessary ?
because I have a message in my form - mymessage = 1.
Is it a problem (I think yes) ?
How can I do ?

Thanks.

:

Your link has everything to clear message queue, just assemble all
pieces together. Something like this:

using System.Runtime.InteropServices;

....

struct MSG
{
IntPtr hwnd;
uint message;
IntPtr wParam;
IntPtr lParam;
int time;
int ptX;
int ptY;
}

[DllImport("coredll")]
extern static bool PeekMessage(out Message Msg, uint hWnd, uint
wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);

const uint PM_REMOVE = 1;

void ClearMessages()
{
MSG msg;
while (PeekMessage(out msg, 0, 0, 0, PM_REMOVE));
}

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi,

I'd like to clear only the messages queue. Not with DoEvents.
I found this :
http://groups-beta.google.com/group...ae6b0b5?q=PeekMessage&rnum=1#84c1ea607ae6b0b5
But I don't know how I can use it.

Somebody could help me ?
Do you have a function which clear up the message queue or a link ?

Thanks.

Best Regards
 

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