Send messages to other window

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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#?
 
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);
 
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.
 
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.
 
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.
 
Back
Top