VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 让窗口一直在上面(1)
发表评论(0)作者:, 平台:, 阅读:10570, 日期:2000-03-12
让窗口一直在上面

很多流行软件都有这样一个选项:Always on Top。它可以让窗口在最上面,别的窗

口不能覆盖它。我们在 VB 中,可以使用下面的方法来实现:

Private Const SWP_NOSIZE = &H1

Private Const SWP_NOMOVE = &H2

Private Const SWP_NOZORDER = &H4

Private Const SWP_NOREDRAW = &H8

Private Const SWP_NOACTIVATE = &H10

Private Const SWP_FRAMECHANGED = &H20

Private Const SWP_SHOWWINDOW = &H40

Private Const SWP_NOCOPYBITS = &H80

Private Const SWP_NOOWNERZORDER = &H200

Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED

Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER Private Const HWND_TOP = 0

Private Const HWND_BOTTOM = 1

Private Const HWND_TOPMOST = -1

Private Const HWND_NOTOPMOST = -2

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 mbOnTop As Boolean

Private Property Let OnTop(Setting As Boolean)

if Setting Then

SetWindowPos hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE

Else

SetWindowPos hwnd, -2, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE

End If

mbOnTop = Setting

End Property

Private Property Get OnTop() As Boolean

'Return the private variable set in Property Let

OnTop = mbOnTop

End Property

调用 OnTop=True 即可让窗口 Always OnTop。