如何关闭使用 window 句柄嵌入的嵌入 window?

How to close embedded window that was embedded using window handle?

所以我有一种方法可以将 powerpoint 集成到面板中。我使用 FindWindow 和 SetParent 函数来实现这个:

Dim proc as integer

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer

Public Sub embed_Window()
    Do Until proc <> 0
        proc = FindWindow(vbNullString, window_name)
    Loop

    SetParent(proc, Panel1.Handle)

End Sub

这部分可以很好地将另一个 window 嵌入到我的面板控件中。我的问题是,如何关闭面板中现​​在的 window?我不能再使用 FindWindow 方法,因为它不再是任务栏中的 window。

为了关闭打开的 window 你需要使用 PostMessage:

Private Declare Auto Function PostMessage Lib "user32" (ByVal hwnd As Integer, ByVal message As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean

Public Const WM_CLOSE = &H10

Public Sub CloseWindow()
 PostMessage(proc, WM_CLOSE, 0, 0)
End Sub