Click to See Complete Forum and Search --> : Locking User in Application


Judgey
April 4th, 2001, 05:04 AM
I'm developing an Examination Program and need to lock the user in the program, I have disabled the CTRL-ALT-Del no problem. but say for example my App window is 800x600 and the screen resolution in 1024x768. Users can still activate Icons on the desktop and also the Taskbar.

Does anybody know of a way of confining a user solely to my application ?

many thanks in advance . .

Cimperiali
April 4th, 2001, 05:13 AM
Do not know direct answer, but you can modify your app screen size in load event getting the size of screen (it should be expressed in pixel, not in twips, so you will have to make some conversions). Now I cannot test, but try with screen.height and screen.width, or look for a window Api (sorry, do not remember which one). You should also look for an api which will take your form always on top...I know it is not much, but I hope it helped you

Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.

Judgey
April 4th, 2001, 05:16 AM
Cheers Cesare

I have already got the Form Always on top but I Didn't want to size my form to the Screen size as the Applications I have really needs to be a fixed size, thanx anyway though . .

Clearcode
April 4th, 2001, 05:27 AM
There is a way, but it involves subclassing.

1st you need to download the EventVB subclassing control from http://www.merrioncomputing.com/Download/EventVB.dll and then add a reference to it in your visual basic project.

Then in your main form's declarations:

private withevents ApiLink as EventVB.APIFunctions
private withevents frmThis as ApiWindow

private Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (byval hwnd as Long) as Long
private Declare Function SetFocus Lib "user32" Alias "SetFocus" (byval hwnd as Long) as Long





And start up the subclasser in your form's Load event:

private Sub Form_Load()

'\\ Link the api dispenser
set ApiLink = new EventVB.APIFunctions
'\\ Link the form
set frmThis = new ApiWindow
frmThis.hwnd = me.hwnd

'\\ Start the subclassing
ApiLink.SubclassedWindows.Add frmThis

End Sub




You must unsubclass the window in the unload event:

public Sub Form_Terminate()

ApiLink.SubclassedWindows.Remove frmThis.hWnd
set frmThis = nothing
set ApiLink = nothing


End Sub




Now whenever your application loses the focus it will recieve a ActiveApplicationChanged message.
You need to regain control in this message.

private Sub frmThis_ActiveApplicationChanged(byval ActivatingThisApp as Boolean, byval hThread as Long, Cancel as Boolean)

If Not ActivatingThisApp then
Call SetForegroundWindow(me.hwnd)
End If

End Sub




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

TH1
April 4th, 2001, 05:28 AM
You could use the clipcursor API to restrict the mouse pointer to your form

private Declare Function ClipCursor Lib "user32" (lpRect as Any) as Long
private Declare Function GetWindowRect Lib "user32" (byval hwnd as Long, lpRect as RECT) as Long
private Declare Function GetDesktopWindow Lib "user32" () as Long
private Type RECT
left as Long
top as Long
right as Long
bottom as Long
End Type
private Sub Clip()
Dim myrect as RECT
Call GetWindowRect(Form1.hwnd, myrect)
Call ClipCursor(myrect)
End Sub
private Sub Release()
Dim myhwnd as Long
Dim myrect as RECT
myhwnd = GetDesktopWindow()
Call GetWindowRect(myhwnd, myrect)
Call ClipCursor(myrect)
End Sub
private Sub Form_Load()
Clip
End Sub

private Sub Form_Unload(Cancel as Integer)
Release
End Sub

John G Duffy
April 4th, 2001, 07:12 AM
You could try using the following two APIs to control where the mouse is. These API gain control and track where the mouse is. The following program needs a commandBox on a standard form.
In conjunction with this simple program, there are ways to position the cursor so that if the user moves it outside your application you can move it back. I however do not have a sample of how to do this piece, but here is the Mouse Capture piece. Scrounge on Planet-Source-Code.com/vb,or your favorite Code haunt, for the mouse move part.

option Explicit

private Declare Function SetCapture Lib "user32" (byval hwnd as Long) as Long
private Declare Function ReleaseCapture Lib "user32" () as Long


'Code:
'Put this code in MouseMove event. In this example, I put a
'CommandButton on a
'form with the name Command1

private Sub Command1_MouseMove(Button as Integer, Shift as Integer, X _
as Single, Y as Single)
static CtrMov as Boolean
static Counter as Long
Counter = Counter + 1
With Command1 'Change this 'Command1' to your control name
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) then
ReleaseCapture
CtrMov = false
Command1.BackColor = &HFF&
Command1.Caption = " Not Over " & Counter
Command1.Refresh
'Put here your code to LostMouseFocus
'for example:
me.print "LostMouseFocus"

else
SetCapture .hwnd
If CtrMov = false then ' do this only once per "over"
CtrMov = true
Command1.BackColor = &HFFFFFF
Command1.Caption = " Over " & Counter
Command1.Refresh
'Put here your code to GetMouseFocus
'for example:
me.print "GetMouseFocus"

End If
End If
End With
End Sub






John G