我正在创建一个我想在后台运行的小型检查器应用程序,它只有一个简单的计时器来检查某个进程是否正在运行,但是我想从 Alt-Tab 切换器中隐藏它并且任务列表是可能的也。我遇到了一些来自 Microsoft 的代码,但它来自 2003 年,并且不再适用于最新版本的 VB.Net,我收到以下错误:
OwnerhWnd = GetWindow(Me.hWnd, GW_OWNER)
我已经在网上查看了它并遵循了一些人所说的但无济于事。许多人建议使用 Me.Handle 的其他人,但我也无法让它工作,只是不断收到同样的错误:
A first chance exception of type 'System.DllNotFoundException' occurred in Checkr.exe
这是提供的代码:
Public Class Form1
Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer,
ByVal nCmdShow As Integer) As Integer
Declare Function GetWindow Lib "User" (ByVal hWnd As Integer,
ByVal wCmd As Integer) As Integer
Const SW_HIDE = 0
Const GW_OWNER = 4
Sub Form_Load ()
Dim OwnerhWnd As Integer
Dim ret As Integer
' Make sure the form is invisible:
form1.Visible = False
' Set interval for timer for 5 seconds, and make sure it is enabled:
timer1.Interval = 5000
timer1.Enabled = True
' Grab the background or owner window:
OwnerhWnd = GetWindow(Me.hWnd, GW_OWNER)
' Hide from task list:
ret = ShowWindow(OwnerhWnd, SW_HIDE)
End Sub
Sub Timer1_Timer ()
Dim ret As Integer
' Display a message box:
ret = MsgBox("Visible by Alt+Tab. Cancel to Quit", 1, "Invisible Form")
' If cancel clicked, end the program:
If ret = 2 Then
timer1.Enabled = False
Unload Me
End
End If
End Sub
如果有帮助,可以在此处找到原始的 Microsoft 文章。