Link to home
Start Free TrialLog in
Avatar of lidorc
lidorc

asked on

implement locking windows with "always on top" dialog.

Hi,
I'm trying to implement a screen that locks the computer like the windows standard lock screen.
I used a dialog that I open as maximized and allways on top. In this dialog, I implement OnActivate() and every time I'm being deactivated I'm doing SetWindowPos(&wndTopMost,...), so even after ALT+Tab i'm on top.
Now to business: My problem is that although I'm on top after ALT+Tab, the keyboard typings are going to the other application. So I see the lock screen but can write in the application that I can't see.
I tried to mess with SetCapture() and SetFocus() too, but it didn't work.
If you have any other idea about locking the computer like windows but wothout windows lock, I'd like to here that..
BTW, I'm working under Win2k, with VC6 and MFC.

  lidorc
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of weicco
weicco

Thats pretty impossible. You can set keyboard hooks but so can other processes too.

Keyboard hook can be set by calling SetWindowsHookEx with parameter WH_KEYBOARD_LL. You need DLL file where you set callback that is called when key is pressed. Then you can decide do you want to send that key press to other applications or not.

But if other application has set hook below you, you can't prevent it getting that key press.

If you really want to lock everything, I think you need to implement custom GINA.DLL.
Did you try SetForeGroundWindow ? does that not help.

[wild thoughts ... ]

Writing a GINA dll is too much work on its own, If nothing helps at all, i would suggest you try DirectInput, sounds stupid but with DirectInput you can have Exclusive access onver input devices, so perhaps while you are locking you can maintains exclusive cooperative level for keyboard and that would also inhibit Alt-Tab (not sure though), but perhaps worth a try.

Or even more wilder idea, write your own intermediate keyboard driver that blocks all keyboard events when asked.

A little more information on problem would be nice, like what is the basic problem, why do you need this kind of software.
how about everytime you lose focus set back the focus on your app?
Call SetFocus when OS sends you message about focus change, dunno.

But you can prevent focus change by hooking mouse with SetWindowsHookEx. When mouse button is pressed, check if it's pressed over your program's window. If not block the mouse event, otherwise send mouse event to forward with CallNextHookEx.
Avatar of lidorc

ASKER

thanks jkr,
and sorry everybody for the delyed answer.

   lidorc