我想开发一个应用程序,它不允许用户在打开时打开或跳转到另一个应用程序.它应该在Visual Basic.例如,如果我的应用程序是打开(运行)并且用户试图打开任何其他Windows应用程序,如"媒体播放器",则它不应该打开.应用程序甚至不应允许"任务管理器"运行.应用程序应该在运行时完全阻止Windows环境.
Sid*_*out 15
一个非常好的问题.:)
有可能在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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
b)以最大化模式显示您的应用程序
最大化您的表单,以便桌面仅显示您在Kiosk应用程序中显示的表单.根据需要,您还可以禁用最小化按钮或标题栏.在这种情况下,请记住添加一个按钮,以便用户可以单击该按钮以退出表单.
3)禁用"开始"菜单
此代码取决于您使用的Windows版本.在Google上搜索,你会发现很多例子.
同样,你必须要处理一些小的小东西,但这篇文章将给你一个良好的开端.如果你在一个地方寻找一个完整的解决方案,那么我怀疑你会得到它;)
HTH
| 归档时间: |
|
| 查看次数: |
864 次 |
| 最近记录: |