Hello. I need send some commands to other window.
I did this before with VC++. So it work like this.
I found this window (for example cacl.exe have text â??Calculatorâ??) then get
handle of this window and then send some windows messages on this handle.
My old code looks like this

HWND hwndFound = ::FindWindow(NULL, " Calculator"); // поиÑ?к окна
::PostMessage(hwndFound,WM_COMMAND,IDYES,0);

How I can do something like this in C#?

Re: Send messages to other window by Jeff

Jeff
Tue Apr 24 14:05:17 CDT 2007

On 24/04/2007 in message
<E53D7E02-490F-4E64-BE42-69D6A5D1BDA8@microsoft.com> SushiSean wrote:

>Hello. I need send some commands to other window.
>I did this before with VC++. So it work like this.
>I found this window (for example cacl.exe have text â??Calculatorâ??) then
>get
>handle of this window and then send some windows messages on this handle.
>My old code looks like this
>
>HWND hwndFound = ::FindWindow(NULL, " Calculator"); // поиÑ?к окна
>::PostMessage(hwndFound,WM_COMMAND,IDYES,0);
>
>How I can do something like this in C#?

Do it in exactly the same way - you will need to declare prototypes for
the 2 API calls:

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);


[DllImport("user32.dll")]
public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam,
int lParam);

--
Jeff Gaines

Re: Send messages to other window by SushiSean

SushiSean
Tue Apr 24 17:18:02 CDT 2007

So it means framework doesn't have any function for sending
windows mesages? and only one way use DllImport ?
If yes then looks like C# bad choice for this. this is strange.

"Jeff Gaines" wrote:
> [DllImport("user32.dll")]
> public static extern IntPtr FindWindow(string lpClassName, string
> lpWindowName);
>
>
> [DllImport("user32.dll")]
> public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam,
> int lParam);


Re: Send messages to other window by Jeff

Jeff
Wed Apr 25 04:00:25 CDT 2007

On 24/04/2007 in message
<A92FFCA2-8DF0-4230-BCCC-6893DEFBE3BD@microsoft.com> SushiSean wrote:

>So it means framework doesn't have any function for sending
>windows mesages? and only one way use DllImport ?
>If yes then looks like C# bad choice for this. this is strange.

There's no built in API, I was very disappointed when I first started
using it, you can get round it by defining prototypes though.

--
Jeff Gaines

Re: Send messages to other window by Stoitcho

Stoitcho
Wed Apr 25 08:20:42 CDT 2007

SushiSean,

You need to do it in the same way. To access Win32 API you use PInvoke in
.NET. Windows messages are not supported in .NET directly.


--
Stoitcho Goutsev (100)

"SushiSean" <SushiSean@discussions.microsoft.com> wrote in message
news:E53D7E02-490F-4E64-BE42-69D6A5D1BDA8@microsoft.com...
> Hello. I need send some commands to other window.
> I did this before with VC++. So it work like this.
> I found this window (for example cacl.exe have text "Calculator") then get
> handle of this window and then send some windows messages on this handle.
> My old code looks like this
>
> HWND hwndFound = ::FindWindow(NULL, " Calculator"); // ????? ????
> ::PostMessage(hwndFound,WM_COMMAND,IDYES,0);
>
> How I can do something like this in C#?