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