PostMessage() vs. SendMessage()
-
Hi , C# fellows, I have one dll and one windows form, this dll send messages to windows form. the windows form has a message filter; my problem is : when I use PostMessage() in dll, the message Filter can trap it; however, if I use sendMessage() , then doesnt work. Can anyone explain Why??? :wtf:
-
Hi , C# fellows, I have one dll and one windows form, this dll send messages to windows form. the windows form has a message filter; my problem is : when I use PostMessage() in dll, the message Filter can trap it; however, if I use sendMessage() , then doesnt work. Can anyone explain Why??? :wtf:
Can you post the code for the message filter? PostMessage and SendMessage messages go to different queues, maybe the message filter is coded incorrectly? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Can you post the code for the message filter? PostMessage and SendMessage messages go to different queues, maybe the message filter is coded incorrectly? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
OK,here is the source code:: // in the main function , do the following
MyMessageFilter msgFilter = new MyMessageFilter(); System.Windows.Forms.Application.AddMessageFilter(msgFilter);
// filter implementation public class MyMessageFilter : System.Windows.Forms.IMessageFilter { public bool PreFilterMessage(ref System.Windows.Forms.Message m) { //custom message is 0x0800,... if (m.Msg == 0x8000) { System.Windows.Forms.MessageBox.Show("Data ming" + m.Msg); } return false; } } // and in dll , two way of send message ... case 0x8000: PostMessage(...);break; case 0x0801: SendMessage(...);break; the problem is only the message by PostMessage can be trapped in the filter. is that strange???? -
OK,here is the source code:: // in the main function , do the following
MyMessageFilter msgFilter = new MyMessageFilter(); System.Windows.Forms.Application.AddMessageFilter(msgFilter);
// filter implementation public class MyMessageFilter : System.Windows.Forms.IMessageFilter { public bool PreFilterMessage(ref System.Windows.Forms.Message m) { //custom message is 0x0800,... if (m.Msg == 0x8000) { System.Windows.Forms.MessageBox.Show("Data ming" + m.Msg); } return false; } } // and in dll , two way of send message ... case 0x8000: PostMessage(...);break; case 0x0801: SendMessage(...);break; the problem is only the message by PostMessage can be trapped in the filter. is that strange????Does the DLL function that executes PostMessage/SendMessage run on the UI thread that is running the message pump for the HWND to which you send/post messages? For eg, if your DLL function gets executed when the user clicks a button (on the HWND that you are sending/posting messages), then SendMessage will directly call the WndProc and won't go through the message pump. Which also means that the message filter won't work. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Does the DLL function that executes PostMessage/SendMessage run on the UI thread that is running the message pump for the HWND to which you send/post messages? For eg, if your DLL function gets executed when the user clicks a button (on the HWND that you are sending/posting messages), then SendMessage will directly call the WndProc and won't go through the message pump. Which also means that the message filter won't work. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
the Dll is in another thread, its really confusing...