外挂窗体、内嵌窗体

    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
    Private Const GWL_STYLE = (-16)
    Private Const WS_SYSMENU = &H80000
    Private Const WS_CAPTION = &HC00000
    Private Const WS_SIZEBOX = &H40000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const SWP_NOZORDER = &H4
    Private Const SWP_FRAMECHANGED = &H20
    Private Const SWP_NOREPOSITION = &H200
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer

    Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
    Private Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Integer
    Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (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

    Dim skyHwnd As Integer = FindWindow("tSkMainForm.UnicodeClass", vbNullString)
    Dim lStyle As Integer

    Private Structure RECT
        Dim Left As Integer
        Dim Top As Integer
        Dim Right As Integer
        Dim Bottom As Integer
    End Structure

    Dim ret As New RECT

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        lStyle = lStyle Or WS_SYSMENU
        lStyle = lStyle Or WS_CAPTION
        lStyle = lStyle Or WS_SIZEBOX
        lStyle = lStyle Or WS_MAXIMIZEBOX
        lStyle = lStyle Or WS_MINIMIZEBOX

        SetWindowLong(skyHwnd, GWL_STYLE, lStyle)
        SetParent(skyHwnd, GetDesktopWindow)

        MoveWindow(skyHwnd, ret.Left, ret.Top, ret.Right - ret.Left, ret.Bottom - ret.Top, 1)
        ShowWindow(skyHwnd, SW_SHOW)
    End Sub

    Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    Private Const SW_RESTORE = 9
    Private Const SW_SHOW = 5
    Private Const SW_SHOWNOACTIVATE = 4

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GetWindowRect(skyHwnd, ret)

        lStyle = lStyle And Not WS_SYSMENU
        lStyle = lStyle And Not WS_CAPTION
        lStyle = lStyle And Not WS_SIZEBOX
        lStyle = lStyle And Not WS_MAXIMIZEBOX
        lStyle = lStyle And Not WS_MINIMIZEBOX

        SetWindowLong(skyHwnd, GWL_STYLE, lStyle)

        SetParent(skyHwnd, Me.Handle.ToInt32)
        MoveWindow(skyHwnd, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, 1)
        ShowWindow(skyHwnd, SW_SHOW)
    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState <> FormWindowState.Minimized Then
            MoveWindow(skyHwnd, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, 1)
        End If
    End Sub  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值