【问题标题】:How to close embedded window that was embedded using window handle?如何关闭使用窗口句柄嵌入的嵌入窗口?
【发布时间】:2018-10-30 15:55:10
【问题描述】:

所以我有一个我正在使用的方法,我可以将 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

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

【问题讨论】:

标签: vb.net hwnd


【解决方案1】:

要关闭打开的窗口,您需要使用 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

【讨论】:

    猜你喜欢
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2012-12-02
    • 2011-03-18
    • 2012-04-22
    • 2014-03-21
    相关资源
    最近更新 更多