Solved

implement locking windows with "always on top" dialog.

Posted on 2002-06-22
7
258 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:lidorc
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 7100809
You could use a system-wide hook to filter all keyboard and mouse input - see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_hooks32.asp ("Win32 Hooks")
0
 

Expert Comment

by:weicco
ID: 7102026
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.
0
 
LVL 22

Expert Comment

by:ambience
ID: 7102719
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.

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Expert Comment

by:weicco
ID: 7103312
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.
0
 
LVL 3

Expert Comment

by:CoolBreeze
ID: 7112773
how about everytime you lose focus set back the focus on your app?
0
 

Expert Comment

by:weicco
ID: 7115703
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.
0
 
LVL 1

Author Comment

by:lidorc
ID: 7152362
thanks jkr,
and sorry everybody for the delyed answer.

   lidorc
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall‚Ķ
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now