The file path to be opened is provided, how to get a handle to the new window?

不问归期 提交于 2019-12-11 15:04:55

问题


I want to implement a shell context menu "Open to Left/Right" that user can open a file with the new window being re-positioned to occupy the left/right half of the screen. Basically I just call Process.Start(fileName), and get the process's MainWindowHandle, and pass the handle to SetWindowPos to set the window's position.

But some applications (like Word) are running as singleton instance, so Process.Start("new.docx") just pass the file name to the running instance, and returns null, so I can't get the window handle to do the repositioning.

Is there a workaround for this?

Any approach (preferred written in C#) is welcome.

PS. I know I can just use EnumWindows to list all the top-level windows and let user to select which one he likes to reposition. But that is another use scenario. I want to implement the function in shell context menu.

来源:https://stackoverflow.com/questions/14556479/the-file-path-to-be-opened-is-provided-how-to-get-a-handle-to-the-new-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!