SetParent API を使用して、アプリケーションの GroupBox コントロール内に Word ドキュメントを配置する VB.NET アプリケーションがあります。
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 自体は正しく機能しており、Word 文書自体のテキストにも影響はありません)。
これがどのように起こるか誰にも分かりますか?これをプログラムで防止したり、後で修正したりできますか?