如何以编程方式激活vb6中的表单

时间:2015-11-19 15:53:06

标签: vb6

我正在构建VB6.0应用程序,用户在哪里刷卡,表单会弹出一条感谢信息。休息一切都很好,只有形式被最小化,而不是它应该弹出。
我用google搜索了他们的Form.Activate,但是当我写它时会出错。

  

编译错误:找不到方法或数据成员

我是VB新手所以请原谅是否有任何天真的错误  代码:

  Me.Hide
  Form2.Show
  Form2.Activate

我需要弹出Form2。

由于

1 个答案:

答案 0 :(得分:0)

我能够通过

实现
Private Sub Form_Load()

Dim lR As Long
     lR = SetTopMostWindow(Form2.hwnd, True)

End Sub

并添加了一个模块

Option Explicit
 Public Const SWP_NOMOVE = 2
 Public Const SWP_NOSIZE = 1
 Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
 Public Const HWND_TOPMOST = -1
 Public Const HWND_NOTOPMOST = -2

 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 Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) _
    As Long

    If Topmost = True Then 'Make the window topmost
       SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, _
          0, FLAGS)
    Else
       SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, _
          0, 0, FLAGS)
       SetTopMostWindow = False
    End If
 End Function</pre>

可以参考https://support.microsoft.com/en-us/kb/184297

由于