Gilbert,
Here's an example.
public class Program
{
public static void Main()
{
// Get RunMessageLoop going in another thread.
}
private void RunMessageLoop()
{
Application.AddMessageFilter(new MyMessageFilter());
Application.Run();
}
private class MyMessageFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == /* whatever */)
{
// Intercept and handle accordingly.
return true;
}
// Allow the message loop to dispatch the message.
return false;
}
}
}
Brian
gilbert@gmail wrote:
Thank you very much for your tips. After searching from the web, I
still have no idea how to use the message loop created by the
Application.Run(). Like, how to put the custom message handler? How to
post custom messages to the loop? I think it is the thing I am looking
for, just I still have no idea how to use it!
Any help would be greatly appreciated!
Thanks!
Gilbert
Brian Gideon wrote:
Gilbert,
You can call Application.Run to install a windows message loop on the
current thread. The PostThreadMessage or Control.BeginInvoke (if you
have a control hosted on the thread) can be used to dispatch messages
to the queue.
If you don't want the message queue to receive windows messages then
you'll have to write your own.
Brian