【问题标题】:Where is ExecWB?ExecWB 在哪里?
【发布时间】:2016-06-17 12:41:46
【问题描述】:

如果我使用 WPF 语法:

<WebBrowser Grid.Row="1" Grid.Column="1" x:Name="htmlView"></WebBrowser>

或者如果我添加一个WindowsFormsHost:

<WindowsFormsHost x:Name="formsHost" Grid.Row="1" Grid.Column="1">
</WindowsFormsHost>

在 CS 文件中:

public partial class MainWindow : Window
{
    System.Windows.Forms.WebBrowser htmlView= new System.Windows.Forms.WebBrowser();

    public MainWindow()
    {
        InitializeComponent();

        formsHost.Child = htmlView;
        htmlView.Navigate("d:\\test.xml");
    }

    private void menuFilePageSetup_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("Do do");
    }
}

无论哪种方式,ExecWB 方法都不会暴露。所以我不能从我的 MFC C++ CHtmlView 派生类移植这段代码:

ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);

我错过了什么吗?目前我无法实现打印预览/页面设置/缩放功能,因为我无法使用ExecWB

我已尝试从 Winforms 浏览器派生我自己的类,但仍未列出。

谢谢。

我不明白为什么在这个问题中:

How do I programmatically change printer settings with the WebBrowser control?

它指的是ShowPrintDialog,但即使它也没有列出。

部分成功!我不知道为什么,但是现在,当我使用托管的 Winforms 版本时,我至少可以看到一些方法:

public partial class MainWindow : Window
{
    System.Windows.Forms.WebBrowser htmlView= new System.Windows.Forms.WebBrowser();

    public MainWindow()
    {
        InitializeComponent();

        formsHost.Child = htmlView;
        htmlView.Navigate("d:\\test.xml");
    }

    private void menuFilePageSetup_Click(object sender, RoutedEventArgs e)
    {
        htmlView.ShowPageSetupDialog();
    }

    private void MenuItem_Click(object sender, RoutedEventArgs e)
    {
        htmlView.ShowPrintPreviewDialog();
    }
}

但是ExecWb 仍然缺少用于管理缩放等操作。我发现了这个:

How do I print from the wpf WebBrowser available in .net 3.5 SP1?

答案之一:

mshtml.IHTMLDocument2 doc = webBrowser.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, null);

但即使我添加了对 mshtml 库的引用,编译器也不会让我从 HtmlDocument 转换为 IHtmlDocument2。最终我得到了这个:

Clearing the selection in a webbrowser control

所以现在我知道如何全选并再次复制到剪贴板(只要我使用 Winforms 版本)。但是,看过这里:

https://msdn.microsoft.com/en-us/library/ms533049(v=vs.85).aspx

似乎不适合光学变焦

ExecWB(OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, &vZoom, NULL);

【问题讨论】:

    标签: wpf webbrowser-control


    【解决方案1】:

    调用ExecWb 的基本答案是这样做:

    1. 使用 WinForms WebBrowser 控件

    2. 然后是htmlView.Document.ExecCommand

    传入如下命令:

    SelectAll
    Copy
    

    用于剪贴板项目。

    有显示打印对话等的本地方法。

    唯一似乎不受支持的是:

    ExecWB(OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, &vZoom, NULL);
    
    猜你喜欢
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多