簡體   English   中英

將孩子移出面板

[英]Move a child out of panel

我使用下面的代碼啟動 cmd.exe window 並將其移動到我表單上的 panel1 中。 我向其中添加了 button1,我喜歡使用該按鈕將孩子移出 panel1,回到“桌面”。 有人知道該怎么做嗎? 我做了一些谷歌搜索,我可以找到很多關於如何將孩子移動到面板或如何將其從一個面板移動到另一個面板的示例,但不是如何將其移出面板......感謝您的任何幫助提前,親切的問候,埃里克

Imports System.Runtime.InteropServices
Public Class Form1
    Private WithEvents proc As New Process
    Public Const SW_SHOWMAXIMIZED As UInt32 = 3
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Int32) As Int32
    Private Declare Function DwmGetWindowAttribute Lib "dwmapi" (ByVal hwnd As IntPtr, ByVal dwAttribute As Integer, ByRef pvAttribute As RECT, ByVal cbAttribute As Integer) As Integer
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
    Public Structure RECT
        Public left, top, right, bottom As Integer
    End Structure
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        proc.EnableRaisingEvents = True
        proc.StartInfo.FileName = "cmd"
        proc.Start()
    End Sub
    Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        proc.WaitForExit(200)
        If SetParent(proc.MainWindowHandle, Panel1.Handle) <> IntPtr.Zero Then
            SetWindowPos(proc.MainWindowHandle, IntPtr.Zero, 0, 0, Width, Height, 0)
            ShowWindow(proc.MainWindowHandle, SW_SHOWMAXIMIZED)
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Code to move the child out of panel1
    End Sub
End Class

感謝@john 的幫助,我現在已經可以讓它工作了。 親切的問候,埃里克

Imports System.Runtime.InteropServices
Public Class Form1
    Private WithEvents proc As New Process
    Public Const SW_SHOWMAXIMIZED As UInt32 = 3
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function DwmGetWindowAttribute Lib "dwmapi" (ByVal hwnd As IntPtr, ByVal dwAttribute As Integer, ByRef pvAttribute As RECT, ByVal cbAttribute As Integer) As Integer
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
    Public Structure RECT
        Public left, top, right, bottom As Integer
    End Structure
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        proc.EnableRaisingEvents = True
        proc.StartInfo.FileName = "cmd"
        proc.Start()
    End Sub
    Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        proc.WaitForExit(200)
        If SetParent(proc.MainWindowHandle, Panel1.Handle) <> IntPtr.Zero Then
            SetWindowPos(proc.MainWindowHandle, IntPtr.Zero, 0, 0, Width, Height, 0)
            ShowWindow(proc.MainWindowHandle, SW_SHOWMAXIMIZED)
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Code to move the child out of panel1
        SetParent(proc.MainWindowHandle, IntPtr.Zero)
    End Sub
End Class

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM