原理很简单,用FINDWINDOW函数寻找 任务管理器,如果监测到其运行,则显示一个最大化的窗口,并且将其窗口设置为始终在最前端。
建议大家先把窗口的属性设置为无边框和最大化。 我试过,还真不能用任务管理器关闭这个程序了。
特此感谢帮助我门这些小菜的人!!!
Option Explicit
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
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 cmdAllTop()
Dim rectTemp As RECT
GetWindowRect Form1.hwnd, rectTemp
SetWindowPos Form1.hwnd, HWND_TOPMOST, _
rectTemp.Left, rectTemp.Top, rectTemp.Right - rectTemp.Left, rectTemp.Bottom - rectTemp.Top, 0
End Sub
'Ñ°ÕÒ´°¿ÚÁбíÖеÚÒ»¸ö·ûºÏÖ¸¶¨Ìõ¼þµÄ¶¥¼¶´°¿ÚµÄAPIµ÷ÓÃ
'ÔÚ´°¿ÚÖн¨Á¢Ò»timer¿Ø¼þºÍLabel1¿Ø¼þ,È»ºóÔÚ´úÂë´°¿ÚÊäÈëÈçÏ´úÂë:
Private Sub Form_Load()
Form1.Visible = False
Timer1.Interval = 500
End Sub
Private Sub Label1_Click()
End
End Sub
'timer¿Ø¼þºÍLabel1¿Ø¼þµÄ´úÂëÈçÏÂ:
Private Sub Timer1_Timer()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "Windows ÈÎÎñ¹ÜÀíÆ÷") 'ץȡ"ÄãÐèÒªµÄ³ÌÐòÃû"µÄ´°¿ÚÃû³Æ.
If (hwnd = 0) Then
Label1.Caption = "³ÌÐòδ¼ÓÔØ"
ElseIf (hwnd <> 0) Then
Label1.Caption = "³ÌÐòÒѼÓÔØ"
Call cmdAllTop
Form1.Visible = True
End If
End Sub