Groups | Blog | Home
all groups > dotnet windows forms > october 2006 >

dotnet windows forms : Whats the use of postmessage??


Chacko
10/31/2006 2:58:11 AM
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
Morten Wennevik
10/31/2006 12:36:28 PM
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 =3D =

System.Diagnostics.Process.GetProcessesByName("Notepad");
foreach(Process p in processes)
{
IntPtr hWnd =3D p.MainWindowHandle; // handle to the no=
tepad =

window
UInt32 msg =3D 0x0010; // WM_Close, a message for closi=
ng a =

window
IntPtr wParam =3D IntPtr.Zero; // no extra parameters n=
eeded
IntPtr lParam =3D IntPtr.Zero;

PostMessage(hWnd, msg, wParam, lParam);
}
}

[DllImport("user32.dll", CharSet =3D CharSet.Auto, SetLastError=
=3D =

false)]
static extern void PostMessage(IntPtr hWnd, uint Msg, IntPtr =

wParam, IntPtr lParam);
}


On Tue, 31 Oct 2006 11:58:11 +0100, Chacko <jacobneroth@gmail.com> wrote=
:

[quoted text, click to view]



-- =

Happy Coding!
Chacko
11/1/2006 9:53:56 PM
Thanx morton for explaining PostMessage to me...
Now morton i have a problem with the first parameter of PostMessage...
As in i want to be able to post my messages to disabled windows or
invisible windows...
How do i do that???
I came across some special value thing but then i didn;t understand
it...
Jacob



[quoted text, click to view]
Morten Wennevik
11/2/2006 12:00:00 AM
To get the window handle to a hidden window you need to use FindWindowEx=
=

in the Win32 API using pinvoke.

http://www.pinvoke.net/search.aspx?search=3DFindWindowEx&namespace=3D[Al=
l]

The handle to the parent window is 'null' for a main window.



On Thu, 02 Nov 2006 06:53:56 +0100, Chacko <jacobneroth@gmail.com> wrote=
:

[quoted text, click to view]
es =

[quoted text, click to view]
=

[quoted text, click to view]
s =

[quoted text, click to view]



-- =

Happy Coding!
Chacko
11/2/2006 6:30:09 AM
Morton i guess i gave u the wrong picture...
Here is the explaination in brief abt the problem
When i write
this.ShowInTaskbar=false;
i am not able to get an another window(instance of the program) or an
thread to be created...
but when the ShowInTaskBar= true
then it works perfectly...
Could u help me out here
Thankx

another
[quoted text, click to view]
AddThis Social Bookmark Button