⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 vb 窗体实例 都是自己的例子
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "控制其他程序成为自己的子窗体"
   ClientHeight    =   3135
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4875
   LinkTopic       =   "Form1"
   ScaleHeight     =   3135
   ScaleWidth      =   4875
   StartUpPosition =   1  '所有者中心
   Begin VB.CommandButton Command3 
      Caption         =   "退出"
      Height          =   600
      Left            =   2940
      TabIndex        =   5
      Top             =   2385
      Width           =   1800
   End
   Begin VB.CommandButton Command2 
      Caption         =   "释放程序"
      Height          =   600
      Left            =   2955
      TabIndex        =   4
      Top             =   1695
      Width           =   1800
   End
   Begin VB.DirListBox Dir1 
      Height          =   1350
      Left            =   90
      TabIndex        =   3
      Top             =   465
      Width           =   2685
   End
   Begin VB.FileListBox File1 
      Height          =   1170
      Left            =   90
      Pattern         =   "*.exe"
      TabIndex        =   2
      Top             =   1830
      Width           =   2685
   End
   Begin VB.DriveListBox Drive1 
      Height          =   300
      Left            =   90
      TabIndex        =   1
      Top             =   90
      Width           =   2685
   End
   Begin VB.CommandButton Command1 
      Caption         =   "调用程序"
      Height          =   600
      Left            =   2955
      TabIndex        =   0
      Top             =   1005
      Width           =   1800
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Const GW_HWNDNEXT = 2

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, _
    lpdwProcessId As Long) As Long
    
Private Declare Function GetParent Lib "user32" (ByVal Hwnd As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, _
    ByVal lpWindowName As Long) As Long
    
Private Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
    ByVal hWndNewParent As Long) As Long

Private OldParent&
Private Hwnd1&

Private Sub Form_Load()
  Drive1.Drive = App.Path
  Dir1.Path = App.Path
End Sub

Private Sub Dir1_Change()
  File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
  Dir1.Path = Drive1.Drive
End Sub
Private Sub Command1_Click()                            '调用程序为本程序子窗口
  Dim myexe As Long
  Dim newhwnd As Long
  Dim newexe As Long
  Dim myvalue As Long

  myexe = Shell(File1.Path & "\" & File1.FileName, vbNormalFocus)    '调用程序
  If myexe = 0 Then
     MsgBox ""
     Exit Sub
  End If
  newhwnd = FindWindow(ByVal 0&, ByVal 0&)               '获取windows句柄
  Do While newhwnd <> 0
     If GetParent(newhwnd) = 0 Then
        myvalue = GetWindowThreadProcessId(newhwnd, newexe)  '获取窗口的进程
        If newexe = myexe Then
           Hwnd1& = newhwnd
           Exit Do
        End If
     End If
        newhwnd = GetWindow(newhwnd, GW_HWNDNEXT)      '获取窗口值
    Loop
    OldParent& = SetParent(Hwnd1&, Me.Hwnd)              '指定本程序为打开程序的父窗口
End Sub

Private Sub Command2_Click()       '释放程序
  SetParent Hwnd1&, OldParent&
End Sub

Private Sub Command3_Click()
  End
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -