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

📄 mdifrmmain.frm

📁 调用外部程序作为自已的子程序,其中调用了API函数
💻 FRM
字号:
VERSION 5.00
Begin VB.MDIForm MDIForm1 
   BackColor       =   &H8000000C&
   Caption         =   "调用外部程序作为自已的子程序"
   ClientHeight    =   6735
   ClientLeft      =   165
   ClientTop       =   855
   ClientWidth     =   10005
   LinkTopic       =   "MDIForm1"
   StartUpPosition =   3  '窗口缺省
   Begin VB.Menu M_File 
      Caption         =   "文件"
      Begin VB.Menu M_File_exit 
         Caption         =   "退出"
      End
   End
   Begin VB.Menu M_OtherAPP 
      Caption         =   "外部程序"
      Begin VB.Menu M_OtherAPP_notepad 
         Caption         =   "记事本"
      End
      Begin VB.Menu M_OtherAPP_calc 
         Caption         =   "计算器"
      End
      Begin VB.Menu M_OtherAPP_cmd 
         Caption         =   "命令提示符"
      End
   End
End
Attribute VB_Name = "MDIForm1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

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

Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Const SW_HIDE = 0

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOP = 0
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80



Private Sub M_File_exit_Click()
    Unload Me
    'End
End Sub

Private Sub ShellChildApp()
    g_hChildWnd = 0
    EnumChildWindows Me.hwnd, AddressOf EnumChildProc, ByVal 0&
    g_lrtnVal = GetDesktopWindow()
    g_lrtnVal = LockWindowUpdate(g_lrtnVal)
    If g_hChildWnd <> 0 Then
        ShowWindow g_hChildWnd, SW_HIDE
        ShowWindow g_hChildWnd, SW_SHOWNORMAL
    Else
        g_lrtnVal = ShellExecute(Me.hwnd, "open", g_strAppPath & g_strAppName, vbNullString, g_strAppPath, SW_HIDE)
        Do
            DoEvents
            g_hChildWnd = FindWindow(vbNullString, g_strTitle)
        Loop While (g_hChildWnd = 0)
        g_lrtnVal = ShowWindow(g_hChildWnd, SW_HIDE)
        Call SetParent(g_hChildWnd, Me.hwnd)
        SetWindowPos g_hChildWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE
        ShowWindow g_hChildWnd, SW_SHOWNORMAL
    End If
    Call Putfocus(g_hChildWnd)
    Call LockWindowUpdate(0)
End Sub

Private Sub M_OtherAPP_calc_Click()
    g_strAppPath = ""
    g_strAppName = "calc.exe"
    g_strTitle = "计算器"
    ShellChildApp
End Sub

Private Sub M_OtherAPP_cmd_Click()
    g_strAppPath = "c:\windows\system32\"
    g_strAppName = "cmd.exe"
    g_strTitle = "C:\WINDOWS\system32\cmd.exe"
    ShellChildApp
End Sub

Private Sub M_OtherAPP_notepad_Click()
    g_strAppPath = ""
    g_strAppName = "notepad.exe"
    g_strTitle = "无标题 - Notepad"
    ShellChildApp
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
    EnumChildWindows Me.hwnd, AddressOf CloseChildProc, ByVal 0&
    'Cancel = True
End Sub

⌨️ 快捷键说明

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