Hi Jacob,
PostMessage is handy for sending messages to other controls or windows
outside your program. Native windows programs uses message queues
(.net-programs hides this message queue with the event system). If you
get the address to any window you can manipulate it by posting messages to
it, hence PostMessage. PostMessage will 'post' a message to the window
and returns without waiting for a reply, while SendMessage does the same,
but waits for a reply before returning.
The sample code below will close all Notepad windows on your desktop by
posting a WM_Close message to each window
class Program
{
static void Main(string[] args)
{
Process[] processes =
System.Diagnostics.Process.GetProcessesByName("Notepad");
foreach(Process p in processes)
{
IntPtr hWnd = p.MainWindowHandle; // handle to the notepad
window
UInt32 msg = 0x0010; // WM_Close, a message for closing a
window
IntPtr wParam = IntPtr.Zero; // no extra parameters needed
IntPtr lParam = IntPtr.Zero;
PostMessage(hWnd, msg, wParam, lParam);
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError =
false)]
static extern void PostMessage(IntPtr hWnd, uint Msg, IntPtr
wParam, IntPtr lParam);
}
Hi anyone and everyone,
Could anybody tell me clearly wats the use of PostMessage and sort
explain to me in simple english...Its just that i searched lot of
places and i am still not getting it right...
Regards,
Jacob