8

I need to show form as top level system-wide, e.g. over /all/ other windows on screen. I do realize this is usually /bad UI practice/, but I have very specific scenario in mind.

We intend to use normal Windows PCs for POS cash registrators. There is an option on the screen to open cash drawer. It would be rather bad for someone just to press something on a screen and get access to money when clerk isn't looking. So we equiped PCs with RFID readers and each clerk has his/her own RFID card which will be used for authentication.

I need however an mechanism to lock the computer (or make it unusable) when clerk goes away. Logging off seems too much of a nuisance.

Any ideas welcome.

LP, Dejan

Dejan Stanič
  • 787
  • 7
  • 14
  • So basically you want to reimplement the locking part of Windows? Well, good luck with getting the security good enough. – Lasse V. Karlsen Jul 23 '09 at 10:12
  • No, I have no intention of doing that. Ideally, I'd like to /utilize/ the locking part of the Windows. If you have any idea how to do it from C#, I'd be happy to know. – Dejan Stanič Jul 23 '09 at 10:23
  • 2
    Ther clerk can lock the windows using Win + L key. When he comes back he can just unlock it by entering his password. Won't that work? – chikak Jul 23 '09 at 12:12
  • Yes, indeed. Unfortunately, in my case, I want to use USB RFID reader to log them on. – Dejan Stanič Jul 23 '09 at 15:05

3 Answers3

8

Well, after a day of trial and error I came to sort of solution.

It involves the following steps:

1. When "Lock" button is pressed new (empty) /desktop/ is created. Program is run in this desktop with full screen form and login procedure. There is nothing else to switch to or run on this desktop.

2. Task manager is disabled via registry. Of course, somebody uninvited can still access the Ctrl-Alt-Delete menu, but there is nothing of particular harm he can do there.

3. Alt-F4 and such are disabled.

4. When authentication is made, program switches back to original desktop and everything proceeds as normal.

There is some P/Invoking required, of course. If someone wants to do something similar, perhaps s/he will find my bare bones example helpful - link text

LP, Dejan

Dejan Stanič
  • 787
  • 7
  • 14
1

I think you'll need to look into calling down to the Win32 API to achieve this.

You'll need to look into:

ShowWindow and SetWindowPos

and invoke them with code similar to the following (note this is pseudo-code):

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

static void ShowTopmost(Form frm)
{
     ShowWindow(frm.Handle, SW_SHOWMAXIMIZED);
     SetWindowPos(frm.Handle.ToInt32(), HWND_TOPMOST,
        0, 0, [width of desktop], [height of desktop],
        SWP_SHOWWINDOW);
}
CraigTP
  • 44,143
  • 8
  • 72
  • 99
-2

Form has a TopMost property.

set Form.TopMost = true

Lloyd Powell
  • 18,270
  • 17
  • 87
  • 123
chikak
  • 1,702
  • 1
  • 18
  • 21