Outlook中的Word Interop强制PrintDialog转到Outlook的后面 [英] Word Interop in Outlook forcing PrintDialog to go to the back of Outlook

查看:93
本文介绍了Outlook中的Word Interop强制PrintDialog转到Outlook的后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入了一段代码,甚至连Win32 API都无法帮助我。 

Hi, I'm stuck in a piece of code where even the Win32 APIs can't help me. 

在代码中我创建了单词interop对象打印电子邮件,我也有一个选项,用户可以选择是否要选择他们想要选择的打印机。我设置对话框时出现问题。当我将对话框设置为wdDialogFile
print时,它强制打印对话框窗口落后于Outlook(因此用户认为Outlook已冻结)。 

In the code I am creating the word interop object to print emails, I also have an option where users can select if they want to choose which printer they wish to choose from. The problem occurs when I set my dialogs. When I set my dialog to wdDialogFile print, it forces the print dialog window to go behind Outlook (hence users thinking Outlook has froze). 

我无法终身我想出了一个简单的方法,使该窗口显示在Outlook前面。有没有一个已知的解决方案?这是罪魁祸首代码: 

I cannot for the life of me figure a simple way to make that window show up in front of Outlook. Is there a known solution to this? This is the culprit code here: 

With appWordobj.Dialogs(wdDialogFilePrint)
    If .Display = -1 Then
        appWordobj.Visible = False
        doc.PrintOut(False)
    Else
        GoTo safe_exit
    End If
'Note this is in .NET but done in a VB6 fashion since I have to maintain this legacy code. 
End With

有没有办法获得处理?但是......在Dialog表单打开之前我无法捕获句柄,因为那是Modal它不会让我在它之后运行任何代码,因为它需要输入...

Is there a way to get the handle? But then...I wouldn't be able to capture the handle until the Dialog form is open, and since that's Modal it won't let me run any code after it since it wants input...

推荐答案

Hello Rahul,

Hello Rahul,

你可以使用
FindWindow
  /
FindWindowEx
 函数检索a的句柄类名和窗口名与指定字符串匹配的窗口。注意,您可以在另一个线程中找到一个窗口并将其带到前台。请参阅&bbsp

SetForegroundWindow
 函数,它将创建指定窗口的线程置于前台并激活窗口。

You can use the FindWindow / FindWindowEx function which retrieves a handle to a window whose class name and window name match the specified strings. Note, you can another thread to find a window and bring it to the foreground. See the SetForegroundWindow function which brings the thread that created the specified window into the foreground and activates the window.

此外,您还可以显示自己的自定义对话框显示在顶部。在.Net世界中,您可以随心所欲地做任何事情。

Also you can show your own custom dialog which will be displayed on top. In the .Net world you can do whatever you want.


这篇关于Outlook中的Word Interop强制PrintDialog转到Outlook的后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆