Get Window instance from Window Handle

后端 未结 2 877
傲寒
傲寒 2021-02-19 09:06

I am able get a Window handle from running applications using the following code.

foreach (ProcessModule module in process.Modules)
{
  if (module.ModuleName.Con         


        
2条回答
  •  情书的邮戳
    2021-02-19 09:56

    Try the following:

    IntPtr handle = process.MainWindowHandle;
    
    HwndSource hwndSource = HwndSource.FromHwnd(handle);
    
    Window = hwndSource.RootVisual as Window;
    

    Update:

    But this will work only inside the same AppDomain, because otherwise it would mean that you could share an object across different AppDomains and even processes, which is obviously impossible.

提交回复
热议问题