Visual.Basic.NET实用编程百例-47.6M.zip
源代码在线查看: frm.frm
VERSION 5.00
Begin VB.Form Frm
Caption = "窗体始终在前面"
ClientHeight = 2850
ClientLeft = 165
ClientTop = 735
ClientWidth = 4395
LinkTopic = "Form1"
Picture = "Frm.frx":0000
ScaleHeight = 2850
ScaleWidth = 4395
StartUpPosition = 3 'Windows Default
Begin VB.Menu RightMenu
Caption = "菜单"
Begin VB.Menu TopMost_Menu
Caption = "位于最前"
End
Begin VB.Menu Comm_Menu
Caption = "普通窗口"
End
End
End
Attribute VB_Name = "Frm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const Flag = SWP_NOMOVE Or SWP_NOSIZE '不移动和改变窗口大小
' 使窗口位于最前
Private Sub Comm_Menu_Click()
SetWindowPos Frm.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flag
End Sub
' 使窗口不位于最前
Private Sub TopMost_Menu_Click()
SetWindowPos Frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flag
End Sub