【问题标题】:SetParent API under Windows-8 changes font size of application menu and ribbonWindows-8 下的 SetParent API 更改应用程序菜单和功能区的字体大小
【发布时间】:2015-06-18 10:39:11
【问题描述】:

我有一个 VB.NET 应用程序,它使用 SetParent API 将 Worddocument 放入我的应用程序的 GroupBox 控件中。

Public Class myForm
    Dim mwrdApp As Microsoft.Office.Interop.Word.Application
    Dim mwrdDoc As Microsoft.Office.Interop.Word.Document
    Dim mwrdHwnd As Integer
    Dim sTemp As String

    Public Structure RECT 'for GetWindowRect API
        Dim Left As Integer
        Dim Top As Integer
        Dim Right As Integer
        Dim Bottom As Integer
    End Structure

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Declare Function GetWindowRect Lib "user32" (ByVal Hwnd As Integer, ByRef lpRect As RECT) As Integer
    Declare Function MoveWindow Lib "user32" (ByVal Hwnd As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer) As Integer
    Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer

    Private Sub myForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        mwrdApp = New Microsoft.Office.Interop.Word.Application
        mwrdDoc = mwrdApp.Documents.Add

        sTemp = mwrdDoc.ActiveWindow.Caption    'save document-caption
        mwrdDoc.ActiveWindow.Caption = "besuretofindthisinstance"   'set detectable caption
        mwrdHwnd = FindWindow("OpusApp", mwrdDoc.ActiveWindow.Caption & " - " & mwrdApp.Caption)    'find Word window handle
        mwrdDoc.ActiveWindow.Caption = sTemp    'restore original caption
        mwrdApp.Visible = True
        mwrdApp.ScreenUpdating = True
        mwrdDoc.ActiveWindow.Visible = True

        MsgBox("Worddocument-window before SetParent")
        SetParent(mwrdHwnd, myGroupBox.Handle.ToInt32) 'put Word in myGroupBox
        Dim myGroupBoxRect As RECT
        GetWindowRect(myGroupBox.Handle.ToInt32, myGroupBoxRect) 'Get size of myGroupBox
        MoveWindow(mwrdHwnd, 0, 0, myGroupBox.Right - myGroupBox.Left, myGroupBox.Bottom - myGroupBox.Top, True) 'Size the Word window to fit inside myGroupBox:
    End Sub
End Class

在桌面上打开 Word 后,代码停止并显示消息框,然后 Wordwindow (Word 2013) 看起来完全正常。

然后 SetParent-API 将 Wordwindow 从桌面移动到 myForm 上的 myGroupBox。到目前为止,这在任何操作系统上都运行良好,但是我最近将我的应用程序切换到 Windows-8(在 MS Surface Pro 3 上),现在在 SetParent 之后,带框的 Wordwindows 显示增加的菜单和功能区。 现在 Word 菜单和功能区控件中的所有标题和选项卡突然变大了;字体大小要大得多(顺便说一句:Word 本身运行正常,Worddocument 本身中的任何文本也不受影响)。

有人知道这是怎么发生的吗?之后可以通过编程方式防止或纠正这种情况吗?

【问题讨论】:

  • 现在已经6年了,你解决了这个问题吗?你会分享诀窍吗?谢谢!

标签: vb.net windows-8 ms-word ribbon setparent


【解决方案1】:

官方不支持您尝试实现的目标。您可以将您的应用程序嵌入到 Word 中(但不能反过来)开发带有任务窗格的加载项。考虑使用任何第三方组件在 Windows 窗体上显示 Word 文档。

还可以看看以下类似的线程:

【讨论】:

  • 感谢 Eugene 的 cmets。多年来,我一直在我的应用程序中嵌入 Word,并成功地将 Word 2010 升级到 WINdows-7,我需要继续这种方式。我现在看到这个问题出现在 Windows-8 系统上,希望有人能找到解决方案。问候,亨克
猜你喜欢
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-11
  • 2017-11-30
  • 2016-11-09
  • 1970-01-01
相关资源
最近更新 更多