PeekMessage in .Net

  • Thread starter Thread starter Jeff
  • Start date Start date
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!
 
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.
 
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.
 
Back
Top