I am trying to access a specific window using its handle (this value System.IntPtr):
var process = Process.GetProcessesByName("devenv")[0];
MessageBox.Show(this, process.MainWindowHandle.ToString());
var wnd = NativeWindow.FromHandle(process.MainWindowHandle);
if (wnd == null)
MessageBox.Show("Failed");
else
MessageBox.Show(wnd.ToString(), "Yeeeeees!!");
I also tried to access another main window of the application for demonstrating .net winforms, which I made for this purpose (i.e. I launched a demo application and tried to access its main window with this application), and also failed, although demo and this application are .NET applications. However, this success:
var process2 = Process.GetCurrentProcess();
MessageBox.Show(this, process2.MainWindowHandle.ToString());
var wnd2 = NativeWindow.FromHandle(process2.MainWindowHandle);
if (wnd2 == null)
MessageBox.Show("Failed");
else
MessageBox.Show(wnd2.ToString(), "Yes");
I think this works because it is called from a single application. So, how can I access another object of the program window by its handle? I thought it could work using C\C++using a header file <windows.h>and then using P \ invoke.
, (.. )?
===================
user586399