久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

打開程序并顯示在窗體上vb代碼

 EYYLTV 2023-03-14 發(fā)布于廣東

?正確例題

打開程序并且顯示在窗體上

VB 讓外部程序在VB程序的窗體里面運(yùn)行

Option Explicit

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

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

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

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

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

Private Const GW_HWNDNEXT = 2

Private m_Hwnd As Long

Private Sub Form_Load()

    Dim dblPid As Long

    Call LockWindowUpdate(GetDesktopWindow)

    dblPid = Shell("c:\windows\notepad.exe", vbNormalFocus)

    m_Hwnd = InstanceToWnd(dblPid) '根據(jù)進(jìn)程PID找窗口句柄

    SetParent m_Hwnd, Me.hwnd

    Putfocus m_Hwnd                 '記事本設(shè)置焦點(diǎn)

    Call LockWindowUpdate(0)

End Sub

Function InstanceToWnd(ByVal target_pid As Long) As Long

    Dim i As Long, lHwnd As Long, lPid As Long, lThreadId As Long

    lHwnd = FindWindow(ByVal 0&, ByVal 0&)   '查找第一個(gè)窗口

    Do While lHwnd <> 0

        i = i + 1

        If i Mod 20 = 0 Then DoEvents

        '判斷窗口是否沒父窗口

        If GetParent(lHwnd) = 0 Then

            '獲取該窗口的線程ID

            lThreadId = GetWindowThreadProcessId(lHwnd, lPid)

            If lPid = target_pid Then '找到PID所在窗口句柄

                InstanceToWnd = lHwnd

                Exit Do

            End If

        End If

        '繼續(xù)查找下一個(gè)兄弟窗口

        lHwnd = GetWindow(lHwnd, GW_HWNDNEXT)

        Debug.Print Hex$(lHwnd)

    Loop

End Function

Private Sub Form_Unload(Cancel As Integer)

    Call DestroyWindow(m_Hwnd)

    'TerminateProcess GetCurrentProcess, 0    '野蠻了些

    Set Form1 = Nothing

End Sub

正確例題

打開程序并且顯示在窗體上

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

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

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

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

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

Private Const GW_HWNDNEXT = 2

Private m_Hwnd As Long

Function InstanceToWnd(ByVal target_pid As Long) As Long

    Dim i As Long, lHwnd As Long, lPid As Long, lThreadId As Long

    lHwnd = FindWindow(ByVal 0&, ByVal 0&)   '查找第一個(gè)窗口

    Do While lHwnd <> 0

        i = i + 1

        If i Mod 20 = 0 Then DoEvents

        '判斷窗口是否沒父窗口

        If GetParent(lHwnd) = 0 Then

            '獲取該窗口的線程ID

            lThreadId = GetWindowThreadProcessId(lHwnd, lPid)

            If lPid = target_pid Then '找到PID所在窗口句柄

                InstanceToWnd = lHwnd

                Exit Do

            End If

        End If

        '繼續(xù)查找下一個(gè)兄弟窗口

        lHwnd = GetWindow(lHwnd, GW_HWNDNEXT)

        Debug.Print Hex$(lHwnd)

    Loop

End Function

Private Sub Form_Load()

    Dim dblPid As Long

    Call LockWindowUpdate(GetDesktopWindow)

    dblPid = Shell("C:\Users\28261\Desktop\密碼登錄程序.exe", vbNormalFocus)

    m_Hwnd = InstanceToWnd(dblPid) '根據(jù)進(jìn)程PID找窗口句柄

    SetParent m_Hwnd, Me.hwnd

    Putfocus m_Hwnd                 '記事本設(shè)置焦點(diǎn)

    Call LockWindowUpdate(0)

End Sub

Private Sub Form_Unload(Cancel As Integer)

    Call DestroyWindow(m_Hwnd)

    'TerminateProcess GetCurrentProcess, 0    '野蠻了些

    Set Form1 = Nothing

End Sub

正確例題

打開exe文件并顯示出來

Private Sub Command4_Click()

Shell "notepad.exe", vbNormalFocus

End Sub

打開exe文件并顯示出來

Private Sub Command3_Click()

Shell "密碼登錄程序.exe", vbNormalFocus

End Sub

打開exe文件并顯示出來

Private Sub Command5_Click()

CommonDialog1.ShowOpen

Shell CommonDialog1.FileName, vbNormalFocus

End Sub

打開文本文件并顯示出來

Private Sub Command6_Click()

CommonDialog1.ShowOpen

Open CommonDialog1.FileName For Binary As #1

MsgBox Input(LOF(1), #1)

Close #1

End Sub

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多