PeekMessage in .Net

J

Jeff

What is the .Net Framework equivalent of the Windows API function
PeekMessage? Or any other method that will do the same thing. I simply
need to check to see if there are messages waiting to be processed.

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

Jeff,

There is no equivalent in the .NET framework. However, you can call the
API through the P/Invoke layer, using the following declarations:

[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
public IntPtr hwnd;
[MarshalAs(UnmanagedType.U4)]
public int message;
public IntPtr wParam;
public IntPtr lParam;
[MarshalAs(UnmanagedType.U4)]
public int time;
public Point pt;
}

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool PeekMessage(
ref MSG lpMsg,
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] wMsgFilterMin,
[MarshalAs(UnmanagedType.U4)] wMsgFilterMax,
[MarshalAs(UnmanagedType.U4)] wRemoveMsg);

Hope this helps.
 
J

Jeffrey Tan[MSFT]

Hi Jeff,

I think IMessageFilter interface should meet your need. Do you still have
any concern?

Please feel free to let me know, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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