如何使VB窗口总在最前?

而且不会被DIRECTX全屏的程序覆盖请写清详细代码谢谢
2025-01-04 09:21:26
推荐回答(5个)
回答1:

如果要不会被DIRECTX全屏的程序覆盖,那么加上一个timer事件,每隔一秒就把窗口显示在前面,哈哈我测试过了有效,以前学过一个学期的VB。
代码如下

Option Explicit
Const Hwndx = -1
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 Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Dim XX As Long
XX = SetWindowPos(Me.Hwnd, Hwndx, 0, 0, 0, 0, 3)
End Sub

记住别忘加timer按钮

或者这样
建立模块
Option Explicit
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)

Private Sub Form_Load()
Dim rtn
'让窗口在顶层
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
'取消窗口在顶层
'rtn = SetWindowPos(F_V.hwnd, -2, 0, 0, 0, 0, 3)

End Sub

回答2:

1、用setparent把DIRECTX全屏的程序作为自己程序中某个控件容器的子窗口。
2、把自己要置于最前面的控件设置为该控件容器最前面
3、OK。

回答3:

Option Explicit
Const Hwndx = -1
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 Sub Form_Load()
Dim XX As Long
XX = SetWindowPos(Me.Hwnd, Hwndx, 0, 0, 0, 0, 3)
End Sub

回答4:

不被DIRECTX全屏的程序覆盖似乎很困难,不过可以把使窗体在最上的代码放在时间事件中,很多时候是有效的,具体的让窗体在最上的代码很多,我就不贴了

回答5:

上面的好像不行???
运行时把鼠标放在窗口的位置时,只会有一个颜色很反常的窗口,并且被放大了.