VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "Command3"
Height = 495
Left = 3285
TabIndex = 2
Top = 2220
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 1755
TabIndex = 1
Top = 1500
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1740
TabIndex = 0
Top = 765
Width = 1215
End
End
Attribute VB_Name = "Form1"
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 Sub Command1_Click()
'使 窗 口 Always On Top用
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub Command2_Click()
'使 窗 口 取 消 Always On Top功 能 , 用
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub Command3_Click()
Form2.Show
End Sub
Private Sub Form_Load()
'使 窗 口 Always On Top用
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
'Form2.frm
VERSION 5.00
Begin VB.Form Form2
Caption = "Form2"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form2"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text1
Height = 675
Left = 1125
TabIndex = 0
Text = "Text1"
Top = 990
Width = 2100
End
End
Attribute VB_Name = "Form2"
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
---- hWnd变元是窗口的句柄;x,y是窗口的左上角的坐标;cx、cy是窗口宽度和高度;hWndInsertAfter变元是窗口清单中hWnd窗口前面的窗口句柄,有四个可选值:
Option Explicit
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 SWP_SHOWWINDOWS = &H40
Private Sub Form_Load()
Dim retValue As Long
retValue = SetWindowPos(Me.hwnd,
HWND_TOPMOST, Me.CurrentX, _
Me.CurrentY, 300, 300, SWP_SHOWWINDOWS)
End Sub
---- 备注:编写函数声明时,整个函数声明须在一行中写完,不可提行。一般是自动从系统中得到函数声明,方法是从VB的外接程序管理中启动“API 浏览”程序,在“API 浏览”程序中找到所需的函数声明,然后复制到VB代码中。