看这几个帖子
http://www.csdn.net/expert/topic/622/622575.xml?temp=.6636621
http://www.csdn.net/expert/topic/622/622248.xml?temp=.4245874
http://www.csdn.net/expert/topic/622/622052.xml?temp=3.390139E-02
http://www.csdn.net/expert/topic/598/598490.xml?temp=.9544031
http://www.csdn.net/expert/topic/514/514440.xml?temp=.7477381
http://www.csdn.net/expert/topic/447/447664.xml?temp=.9597132
http://www.csdn.net/expert/topic/435/435927.xml?temp=.1775476
http://www.csdn.net/expert/topic/622/622575.xml?temp=.6636621
http://www.csdn.net/expert/topic/622/622248.xml?temp=.4245874
http://www.csdn.net/expert/topic/622/622052.xml?temp=3.390139E-02
http://www.csdn.net/expert/topic/598/598490.xml?temp=.9544031
http://www.csdn.net/expert/topic/514/514440.xml?temp=.7477381
http://www.csdn.net/expert/topic/447/447664.xml?temp=.9597132
http://www.csdn.net/expert/topic/435/435927.xml?temp=.1775476
'---------------------设置Windows处于TOp的API
Public 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_NOMOVE = &H2 '不更动目前视窗位置
Const SWP_NOSIZE = &H1 '不更动目前视窗大小
Const HWND_TOPMOST = -1 '设定为最上层
Const HWND_NOTOPMOST = -2 '取消最上层设定
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
'0.将 APP 视窗设定成永远保持在最上层
Public Sub FrmOnTop(Frm As Form, OnTop As Boolean)
If OnTop = True Then
SetWindowPos Frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
Else
'取消最上层设定
SetWindowPos Frm.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
End If
End Sub使用方法:
'以下放到窗体:
form_load:
FrmOnTop(form1,true)
form_unload:
FrmOnTop(form1,false)
form2.show 1
Public 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 Public retValue As String
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const hwnd_topmost = -1
Public Const SWP_SHOWWINDOW = &H40
retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, 3)