gpt4 book ai didi

vb.net - 开发一个不会失去焦点的应用程序?

转载 作者:行者123 更新时间:2023-12-04 03:22:40 25 4
gpt4 key购买 nike

我想开发一个应用程序,它不允许用户在打开时打开或跳转到另一个应用程序。它应该在 Visual Basic .例如,如果我的应用程序已打开(正在运行)并且用户尝试打开任何其他 Windows 应用程序,例如“媒体播放器”,那么它不应该打开。该应用程序甚至不应允许“任务管理器”运行。应用程序在运行时应完全阻止 Windows 环境。

最佳答案

一个非常好的问题。 :)

是否有可能在VB中实现它?

答案是 !

这简单吗?

当然不!

但是,这里有一些关于如何解决问题的提示。

1) 禁用任务管理器

Sub DisableTaskManager()
Shell "REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableTaskMgr /t REG_DWORD /d 1 /f", vbNormalFocus
End Sub

Sub EnableTaskManager()
Shell "REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableTaskMgr /t REG_DWORD /d 0 /f", vbNormalFocus
End Sub

2) 确保您的程序始终处于领先地位

a) 隐藏任务栏
Option Explicit

'~~> http://allapi.mentalis.org/apilist/FindWindow.shtml
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

'~~> http://allapi.mentalis.org/apilist/SetWindowPos.shtml
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 Const SWP_HIDEWINDOW = &H80
Private Const SWP_SHOWWINDOW = &H40

'~~> Show/Hide Taskbar
Sub Sample()
'~~> To show the taskbar
ShowTskBar True

'~~> To hide the taskbar
ShowTskBar False
End Sub

Sub ShowTskBar(ShouldI As Boolean)
Dim Sid As Long

Sid = FindWindow("Shell_traywnd", "")

If ShouldI = True Then
If Sid > 0 Then _
Sid = SetWindowPos(Sid, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
Else
If Sid > 0 Then _
Sid = SetWindowPos(Sid, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
End If
End Sub

b) 显示您的应用程序 始终位于顶部
'~~> http://www.allapi.net/apilist/SetWindowPos.shtml
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 HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40

Private Sub Form_Activate()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

b) 以最大化模式显示您的应用程序

最大化您的表单,以便桌面仅显示您在 Kiosk 应用程序中显示的表单。根据需要,您还可以禁用最小化按钮或标题栏。 在这种情况下,请记住添加一个按钮,以便用户可以单击该按钮退出表单 .

3) 禁用开始菜单

此代码取决于您使用的 Windows 版本。在谷歌上搜索一下,你会发现很多例子。

同样,你必须照顾一些小事,但这篇文章会给你一个好的开始。如果您正在一个地方寻找完整的解决方案,那么我怀疑您是否会得到它;)

高温高压

关于vb.net - 开发一个不会失去焦点的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10271212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com