-1
我有一個vb.net應用程序,它將被最小化爲任務欄或通知區域。當用戶按下某個鍵時(即使用戶正在使用任何其他應用程序),是否有任何方法可以最大限度地/專注於該應用程序。將焦點轉移到按鍵上的vb.net應用程序
試過窗口快捷鍵,但是當它已經open.Please幫助
我有一個vb.net應用程序,它將被最小化爲任務欄或通知區域。當用戶按下某個鍵時(即使用戶正在使用任何其他應用程序),是否有任何方法可以最大限度地/專注於該應用程序。將焦點轉移到按鍵上的vb.net應用程序
試過窗口快捷鍵,但是當它已經open.Please幫助
您需要全局熱鍵不集中的應用程序。首先,將這些功能添加到您的應用程序。
Private Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Integer) As Integer
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True)> _
Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function ShowWindow(hWnd As IntPtr, nCmdShow As Integer) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(hWnd As IntPtr) As Integer
End Function
接下來,添加一個Timer
並在其Timer.Tick
事件,使用此功能是這樣的:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If GetKeyPress(Keys.LControlKey) And GetKeyPress(Keys.A) Then
Dim Handle As IntPtr = Process.GetProcessById(2916).MainWindowHandle
ShowWindow(Handle, 9)
SetForegroundWindow(Handle)
End If
End Sub
設置Timer
間隔150,以避免重複按鍵,並確保啓用定時器Form Load
事件。
HI Farhan,謝謝。代碼第一次工作。當我按下組合鍵時,從任務欄中激活應用程序。但一旦再次減少,它不起作用。 –
查看更新的答案。 –