VB6 - 如何使表格排在第二位?
VB6 - How to make the form second top most?
我使用了下面的 VB6 代码,
Private 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
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Sub Form_Activate()
Dim R As Long
R = SetWindowPos(frmSlide.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
表单设置了这些属性,
MaxButton = False
MinButton = False
ShowInTaskbar = False
StartUpPosition = CenterScreen
WindowState = Maximized
这是为了让表格进入后台。它没有进入后台。这里的想法是让表单只返回一个 window。例如:如果记事本程序 window 已打开。本程序只需要在记事本后台,不需要其他程序windows。这可能吗?
是的,你可以做到。您需要做的是找到您的外部程序的 window 句柄,然后告诉 windows 您的表单应该被视为父级
SetWindowLong(hwndChild, GWL_HWNDPARENT, hwndOwner)
PS:感谢
另请参阅下面的 SO 线程
Win32 window Owner vs window Parent?
我根据 Tarun Lalwani's 做了一些研究,这对我有用,
在表格中添加一个 Timer
并使用此代码,
Option Explicit
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
Public Function FindWindowHandle(Caption As String) As Long
FindWindowHandle = FindWindow1(vbNullString, Caption)
End Function
Private Sub Form_Load()
On Error Resume Next
strTitle = "Untitled - Notepad"
With Timer1
.Interval = 2000
.Enabled = True
End With
End Sub
Private Sub Timer1_Timer()
If FindWindowHandle(strTitle) <> 0 Then
Timer1.Enabled = False
parenthwnd = 0
parenthwnd = FindWindow1(vbNullString, strTitle)
Dim R As Long
R = SetWindowLong(parenthwnd, GWL_HWNDPARENT, Me.hWnd)
End If
End Sub
打开记事本后,它将成为此表单的父级。
警告:我已将表单属性设置为这些,
MaxButton = False
MinButton = False
ShowInTaskbar = False
StartUpPosition = CenterScreen
WindowState = Maximized
如果设置相同的属性,请确保添加按钮或任何其他方法来关闭表单。否则表格会在最上面,可能很难关闭。
我使用了下面的 VB6 代码,
Private 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
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Sub Form_Activate()
Dim R As Long
R = SetWindowPos(frmSlide.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
表单设置了这些属性,
MaxButton = False
MinButton = False
ShowInTaskbar = False
StartUpPosition = CenterScreen
WindowState = Maximized
这是为了让表格进入后台。它没有进入后台。这里的想法是让表单只返回一个 window。例如:如果记事本程序 window 已打开。本程序只需要在记事本后台,不需要其他程序windows。这可能吗?
是的,你可以做到。您需要做的是找到您的外部程序的 window 句柄,然后告诉 windows 您的表单应该被视为父级
SetWindowLong(hwndChild, GWL_HWNDPARENT, hwndOwner)
PS:感谢
另请参阅下面的 SO 线程
Win32 window Owner vs window Parent?
我根据 Tarun Lalwani's
在表格中添加一个 Timer
并使用此代码,
Option Explicit
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
Public Function FindWindowHandle(Caption As String) As Long
FindWindowHandle = FindWindow1(vbNullString, Caption)
End Function
Private Sub Form_Load()
On Error Resume Next
strTitle = "Untitled - Notepad"
With Timer1
.Interval = 2000
.Enabled = True
End With
End Sub
Private Sub Timer1_Timer()
If FindWindowHandle(strTitle) <> 0 Then
Timer1.Enabled = False
parenthwnd = 0
parenthwnd = FindWindow1(vbNullString, strTitle)
Dim R As Long
R = SetWindowLong(parenthwnd, GWL_HWNDPARENT, Me.hWnd)
End If
End Sub
打开记事本后,它将成为此表单的父级。
警告:我已将表单属性设置为这些,
MaxButton = False
MinButton = False
ShowInTaskbar = False
StartUpPosition = CenterScreen
WindowState = Maximized
如果设置相同的属性,请确保添加按钮或任何其他方法来关闭表单。否则表格会在最上面,可能很难关闭。