我如何“恢复” 使用自动化的 MS Word 文档窗口

发布于 2024-07-24 06:02:51 字数 342 浏览 6 评论 0原文

我希望能够使用自动化“恢复”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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

但可醉心 2024-07-31 06:02:51

尝试 ::ShowWindow(handle, SW_RESTORE)

Try ::ShowWindow(handle, SW_RESTORE)

↘人皮目录ツ 2024-07-31 06:02:51

到目前为止我想出的最好的方法如下。

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文