我有一个VB.NET应用程序,它使用SetParent API将WordDocument放入我的应用程序的GroupBox控件中。Windows-8下的SetParent API更改应用程序菜单和功能区的字体大小
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(2013字)正在完全正常。
然后,SetParent-API将Wordwindow从桌面移动到myForm上的myGroupBox。到目前为止,这一直适用于任何操作系统,但是最近我将应用程序切换到Windows-8(在MS Surface Pro 3上),现在在SetParent之后,框架化的Wordwindows显示增加的菜单和功能区。 现在Word菜单和色带控件中的所有标题和标签都突然增加了尺寸;字体大小要大得多(BTW:Word本身运行正常,并且Worddocument中的任何文本本身都不受影响)。
有没有人知道这会发生什么?这可以通过编程方式防止或以后更正吗?
尤金感谢您的意见。多年来,我一直在使用Word 2010将Word嵌入到我的应用程序中,并且我需要继续这种方式。我现在看到在Windows-8系统上出现这个问题,希望有人能找到解决方案。 问候,Henk –