问题
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