很多流行软件都有这样一个选项: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 on top。