2012-04-22 87 views
10

我想开发一个应用程序,它不允许用户在打开时打开或跳转到另一个应用程序。它应该在​​3210。例如,如果我的应用程序是打开(正在运行)并且用户试图打开任何其他Windows应用程序(如“媒体播放器”),则不应该打开它。该应用程序甚至不应该允许“任务管理器”运行。应用程序在运行时应该完全阻止Windows环境。开发一个不会失去焦点的应用程序?

+2

好吧,祝你好运 – 2012-04-22 19:18:25

+2

如果要创建就像那些在许多电子卖场发现一个Kiosk应用程序,你必须依靠组策略在Windows 7多在自己的应用程序的限制。 Google,“在Windows 7中禁用任务管理器” – 2012-04-22 19:23:51

+0

这个过去被称为“系统模式窗口”。我说“习惯了”,因为从Win32开始,微软没有提供任何内置的方法来实现它,甚至试图做到这一点,他们极力阻止它。 (尽管他们有时试图为自己的产品做这件事)。 – RBarryYoung 2012-04-22 19:24:50

回答

14

一个很好的问题。 :)

是可以实现它在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)确保你的程序是始终在最前面

一)隐藏任务栏

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版本。在Google上搜索,你会发现很多例子。

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

HTH

+0

逻辑思维+1。 – 2012-04-22 22:43:40

+0

+1可怕的东西 – 2012-04-23 07:28:15

+0

谢谢普拉迪普/ JFC :) – 2012-04-23 08:33:06

0

看看在Desktop APIi创建自己的“沙箱”,但非常小心,因为它很容易将自己锁定在主桌面之外。

另请参阅this question了解更多信息。