Get specific window handle using Office interop에 도움이되는 것을 발견했습니다. 하지만 그 모든 대답은 새로 생성하는 창에 대한 핸들을 얻는 데 기반합니다. 나는 기존의 윈도우를 얻기 위해 다소 수정했고 유틸리티 메소드에 그것을 채웠다.
doc
은 현재 문서입니다.
using System.Windows.Interop;
using System.Diagnostics;
public void SetOwner(System.Windows.Window pd)
{
var wordProcs = Process.GetProcessesByName("winword").ToList();
// in read-only mode, this would be e.g. "1.docx [Read-Only] - Microsoft Word"
var procs = wordProcs.Where(x =>
x.MainWindowTitle.StartsWith(Path.GetFileName(doc.FullName))
&&
x.MainWindowTitle.EndsWith("- Microsoft Word"));
if (procs.Count() >= 1)
{
// would prefer Word 2013's Window.HWND property for this
var handle = procs.First().MainWindowHandle;
WindowInteropHelper wih = new WindowInteropHelper(pd);
wih.Owner = handle;
}
}
불행하게도 프로세스의 수는 1보다 결코 크기 때문에, (다른 폴더에있는) 같은 문서 이름을 가진 여러 개의 창을 설명 할 수있을 것 같지 않습니다하지만 그 허용 한계라고 생각 .