0

我创建了一个在后台运行到另一个程序的 VB6 程序。这意味着程序窗口将只在这个其他程序的后面。我正在使用此代码,

Private Declare Function FindWindow1 Lib "User32" Alias "FindWindowA" (ByVal lpclassname As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_HWNDPARENT = -8

Private parenthwnd As Long
Private strTitle As String

Private Sub Form_Load()
        strTitle = "My Program" 'Title of the program window
        parenthwnd = FindWindow1(vbNullString, strTitle)
        Dim R As Long
        R = SetWindowLong(parenthwnd, GWL_HWNDPARENT, Me.hWnd)
End Sub

另一个程序将运行这个 VB6 程序,它将自身设置为另一个程序窗口的背景。有用。但是有两个问题。

  1. 当 VB6 程序执行代码R = SetWindowLong(parenthwnd, GWL_HWNDPARENT, Me.hWnd)时,其他程序和 VB6 程序一起进入后台。VB6程序运行时如何激活其他程序?
  2. 当另一个程序关闭时,它有终止VB6程序的代码。但这不会关闭 VB6 程序。我认为这可能是由于运行代码R = SetWindowLong(parenthwnd, GWL_HWNDPARENT, Me.hWnd)。如何解决这个问题?
4

1 回答 1

1

如果我正确理解您的问题(我不确定我是否正确),这是我用来将表单发送到后台或将表单发​​送到顶部的代码。也许这就是你要找的。

' Declares and constants for BringToFront and SendToBack

    Public Declare Function 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) As Long

    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const HWND_BOTTOM = 1
    Public Const HWND_TOP = 0

    Public Sub BringToFront(frm As Form)

       Dim flags As Long

       flags = SWP_NOSIZE Or SWP_NOMOVE
       SetWindowPos frm.hWnd, HWND_TOP, 0, 0, 0, 0, flags

    End Sub

    Public Sub SendToBack(frm As Form)

       Dim flags As Long

       flags = SWP_NOSIZE Or SWP_NOMOVE
       SetWindowPos frm.hWnd, HWND_BOTTOM, 0, 0, 0, 0, flags

    End Sub
于 2018-05-20T02:07:00.410 回答