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. How to use user32.dll PostMessage function.

How to use user32.dll PostMessage function.

Scheduled Pinned Locked Moved C#
tutorialquestiondatabasealgorithmsjson
5 Posts 3 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.
  • L Offline
    L Offline
    Larantz
    wrote on last edited by
    #1

    Hi everyone. I'm looking for a good way to let one process know that another process has made changes in a shared database, so that the first process can update its view, if it is currently open. After alot of searching on inet I've come to the conclusion that PostMessage from the Win32 api might be the solution, but I haven't managed to find a guide as how to do it. I think I can manage the PostMessage part, but how do I retrieve it in target process? Any help or links to tutorials would be greatly appreciated. -Larantz-

    R 1 Reply Last reply
    0
    • L Larantz

      Hi everyone. I'm looking for a good way to let one process know that another process has made changes in a shared database, so that the first process can update its view, if it is currently open. After alot of searching on inet I've come to the conclusion that PostMessage from the Win32 api might be the solution, but I haven't managed to find a guide as how to do it. I think I can manage the PostMessage part, but how do I retrieve it in target process? Any help or links to tutorials would be greatly appreciated. -Larantz-

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Override your target process form's WndProc() to handle the message. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      L 2 Replies Last reply
      0
      • R Ravi Bhavnani

        Override your target process form's WndProc() to handle the message. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

        L Offline
        L Offline
        Larantz
        wrote on last edited by
        #3

        [Solved it] Hi Ravi. Thx for reply. I tried overriding the WndProc() and just added a debugger to see if it fires when I run the 2nd process with PostMessage(..). WndProc() process compiles, but when I fire it up, I get an error along the lines of "Error creating windows referance". (I got it in norwegian...) How can I preserve / inherit original WndProc() and just extend it with the code I want to fire? -Larantz- -- modified at 9:10 Friday 2nd June, 2006

        1 Reply Last reply
        0
        • R Ravi Bhavnani

          Override your target process form's WndProc() to handle the message. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          L Offline
          L Offline
          Larantz
          wrote on last edited by
          #4

          Hi again ravi. I was hoping you might explain to me why the messages I send from "senderclass" isn't picked up by the "recieverclass". All I can think of is that the pointer to the process is wrong. But I know that Process.GetprocessByName("processname") finds the right process. Here's the code for the PostMessage routines:

          //Helperclass
          [DllImport("User32.Dll")]
          public static extern long PostMessage(IntPtr hWnd, long wMsg, long wParam, long lParam);

          public const long WM_PAINT = 0x0F;
          public const long WM_DISPLAYCHANGE = 0x7E;

          //Sender class
          System.Diagnostics.Process[] procs = Process.GetProcessesByName("processname_here");
          foreach(System.Diagnostics.Process proc in procs)
          {
          Helpers.PostMessage(proc.Handle, Helpers.WM_PAINT, 0, 0);
          }

          //Reciever class
          protected override void WndProc(ref Message m)
          {
          base.WndProc(ref m);

          if (m.Msg == WM\_PAINT) //This draws for WM\_PAINT messages from the system, but not when I send it from senderclass.
          {
          	MessageBox.Show("Got message");
          }
          

          }

          Thanks in advance, -Larantz-

          E 1 Reply Last reply
          0
          • L Larantz

            Hi again ravi. I was hoping you might explain to me why the messages I send from "senderclass" isn't picked up by the "recieverclass". All I can think of is that the pointer to the process is wrong. But I know that Process.GetprocessByName("processname") finds the right process. Here's the code for the PostMessage routines:

            //Helperclass
            [DllImport("User32.Dll")]
            public static extern long PostMessage(IntPtr hWnd, long wMsg, long wParam, long lParam);

            public const long WM_PAINT = 0x0F;
            public const long WM_DISPLAYCHANGE = 0x7E;

            //Sender class
            System.Diagnostics.Process[] procs = Process.GetProcessesByName("processname_here");
            foreach(System.Diagnostics.Process proc in procs)
            {
            Helpers.PostMessage(proc.Handle, Helpers.WM_PAINT, 0, 0);
            }

            //Reciever class
            protected override void WndProc(ref Message m)
            {
            base.WndProc(ref m);

            if (m.Msg == WM\_PAINT) //This draws for WM\_PAINT messages from the system, but not when I send it from senderclass.
            {
            	MessageBox.Show("Got message");
            }
            

            }

            Thanks in advance, -Larantz-

            E Offline
            E Offline
            e87t53iu
            wrote on last edited by
            #5

            i'm not sure whether somebody is still interested in this question, but the mistake is the using of proc.Handle. This is a process handle, but for sending messages you need a window handle. So take proc.MainWindowHandle.

            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