我如何“恢复” 使用自动化的 MS Word 文档窗口
我希望能够使用自动化“恢复”MS Word 的文档窗口。
我已经有了应用程序对象,并且尝试调用 App.Activate。 激活会将窗口带到窗口堆栈的顶部,但如果 Word 最小化则不会。 我可以将 WindowState 设置为最大化、最小化和正常,但我真正需要做的是将窗口恢复到用户最小化它之前的状态(这相当于用户单击任务栏中的应用程序按钮) 。
使用 Word 自动化可以实现这一点吗?
我实际上使用 C++ 来实现自动化,因此如果需要,我可以调用 Win32 API 函数。
如果没有直接的方法来恢复窗口,那么问题就变成了“如何获取 ActiveWindow 的窗口句柄?”
I would like to be able to 'restore' MS Word's document window using Automation.
I already have the application object and I have tried calling App.Activate. Activate will bring the window to the top of the Window stack but not if Word is minimized. I can set the WindowState to Maximized, Minimized and Normal but what I really need to do is restore the window to the state it was in before the user minimized it (this would be equivalent to the user clicking on the application's button in the taskbar).
Is this possible using Word automation?
I am actually using C++ to to the automation so I am able to call Win32 API functions if required.
If there is not direct way to restore the window then the question becomes, 'how can I get the window handle of the ActiveWindow?'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
::ShowWindow(handle, SW_RESTORE)
Try
::ShowWindow(handle, SW_RESTORE)
到目前为止我想出的最好的方法如下。
使用 Application.ActiveWindow 获取活动窗口
该窗口对象有一个名为 Caption 的属性。 标题出现在文档窗口的标题中。
然后,我使用 Win32 函数 EnumWindows() 来搜索 Win32 窗口。 我使用 Win32 函数 GetWindowText() 获取 EnumWindows() 返回的每个窗口的窗口文本。 我尝试在窗口文本中查找标题,作为额外检查,我确保窗口文本还包含字符串“Microsoft Word”。
一旦找到窗口,我就拥有了它的 Win32 窗口句柄,然后我可以将其传递给 Win32 函数 ShowWindow(hWnd, SW_RESTORE)。
您还必须调用Application.Activate。
这个解决方案并不完美,例如,我不太喜欢假设窗口标题始终包含文本“Microsoft Word”,但我也不想选择错误的窗口。
The best way I have come up with so far is as follows.
Get the active window using Application.ActiveWindow
This window object has a property named Caption. The caption appears in the document window's title.
I then use the Win32 function EnumWindows() to search for the Win32 window. I get the window text for each window returned by EnumWindows() using the Win32 function GetWindowText(). I attempt to find the caption in the window text and as an extra check I make sure the window text also contains the string 'Microsoft Word'.
Once I find the window, I then have it's Win32 window handle which I can then pass to the Win32 function ShowWindow(hWnd, SW_RESTORE).
You also have to call Application.Activate.
This solution is not perfect, for example I don't really like to assume that the window title will always contain the text 'Microsoft Word' but I also don't want to pick the wrong window.