Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. PostMessage() vs. SendMessage()

PostMessage() vs. SendMessage()

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jinzhecheng
    wrote on last edited by
    #1

    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:

    S 1 Reply Last reply
    0
    • J jinzhecheng

      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:

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • S S Senthil Kumar

        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

        J Offline
        J Offline
        jinzhecheng
        wrote on last edited by
        #3

        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????

        S 1 Reply Last reply
        0
        • J jinzhecheng

          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????

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          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

          J 1 Reply Last reply
          0
          • S S Senthil Kumar

            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

            J Offline
            J Offline
            jinzhecheng
            wrote on last edited by
            #5

            the Dll is in another thread, its really confusing...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups