我使用了以下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
这是为了让表单转到后台。它没有回到后台。这里的想法是让表单只返回一个窗口。例如:如果记事本程序窗口打开。这个程序只需要在记事本的后台,而不是其他程序窗口。这可能吗?
答案 0 :(得分:1)
我根据Tarun Lalwani的information进行了一些研究,这对我有用,
在表单中添加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
如果设置相同的属性,请确保添加按钮或任何其他方法来关闭表单。否则表格将位于顶部,可能很难将其关闭。
答案 1 :(得分:0)
是的,你可以这样做。您需要做的是找到外部程序的窗口句柄,然后告诉窗口您的表单应该被视为父项
SetWindowLong(hwndChild, GWL_HWNDPARENT, hwndOwner)
PS:致https://stackoverflow.com/a/834509/2830850
的积分另请参阅以下SO线程