VB 如何将新窗口最前显示

来源:百度知道 编辑:UC知道 时间:2024/06/25 19:01:23
VB中,一个按钮弹出的新窗口如何最前端显示?

Private Declare Function SetWindowPos Lib "user32.dll" (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 Boolean
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const HWND_TOPMOST = -1
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Dim btopmost As Boolean

Private Sub Form_Load()
If btopmost = False Then
SetWindowPos Me.hwnd, HWND_TOPMOST, Me.Left, Me.Top, Me.Width, Me.Height, FLAGS
btopmost = True
End If
End Sub

你试试这个。
=================
Private Sub Command1_Click()
Shell "c:\windows\notepad.exe", vbNormalFocus
End Sub

首先添加API SetWindowPos 然后在按钮的点击事件调用这个东西就好了调用用 Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, &H1 + &H2)