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() SetWindowPos Me.hwnd, -1, 0, 0, Screen.Width, Screen.Height, 0 end sub
.frm Private Sub Form_Load() Call PutWindowOnTop(Me) end sub .basPrivate 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 Const HWND_TOPMOST = -1 Const SWP_NOMOVE = &H2 Const SWP_NOSIZE = &H1 Public Sub PutWindowOnTop(pFrm As Form) '永远在最顶层 Dim lngWindowPosition As Long '函数成功则返回值为非零,失败则返回0 '可以调用GetLastError函数获得更多的错误信息 lngWindowPosition = SetWindowPos(pFrm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE) End Sub
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
Const SWP_NOSIZE = &H1 Const SWP_NOMOVE = &H2 Const SWP_NOACTIVATE = &H10 Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_SHOWWINDOW = &H40 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 SubPrivate 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 SubPrivate Sub Command3_Click() Form2.Show End SubPrivate Sub Form_Load() '使 窗 口 Always On Top用 SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZEEnd Sub
Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, Screen.Width, Screen.Height, 0
end sub
.frm Private Sub Form_Load()
Call PutWindowOnTop(Me)
end sub
.basPrivate 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
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Public Sub PutWindowOnTop(pFrm As Form) '永远在最顶层
Dim lngWindowPosition As Long
'函数成功则返回值为非零,失败则返回0
'可以调用GetLastError函数获得更多的错误信息
lngWindowPosition = SetWindowPos(pFrm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
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
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_SHOWWINDOW = &H40
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 SubPrivate 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 SubPrivate Sub Command3_Click()
Form2.Show
End SubPrivate Sub Form_Load()
'使 窗 口 Always On Top用
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZEEnd Sub
谢谢两位了!以后小弟有问题还请各位多帮忙啊!