Click to See Complete Forum and Search --> : Set My Form Active Only!
alanscl
May 22nd, 2001, 02:35 AM
Hello,
Does anyone know how to disable switching of windows thru' mouse or keyboard? This means that suppose I had a Form which I setfocus to, I do not want the user to click/active to other windows.
Thanks!
Alan
Cimperiali
May 22nd, 2001, 03:08 AM
Inside your application, you may want to show your form in modal mode
ie:
show form1, vbmodal
But it will require api coding to try to keep a form always on top, and to try to disable alt-tab and to capture mouse inside the form if you would like user not to set active the form of another application. And winnT will not let you disable task manager...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
Clearcode
May 22nd, 2001, 03:29 AM
To prevent the user switching from your application to another, you need to use the API and to trap for the WM_ACTIVATEAPP message.
Fortunately there is a dll that can take most of the effort out of this. Download the EventVB.dll from http://www.merrioncomputing.com/Download/index.htm and add a reference to it to your application. Then in your application's main form:
'\\ Declarations
Dim withevents ApiLink as EventVB.ApiFunctions
Dim withevents wnd as EventVB.ApiWindow
private Sub Form_Load()
set ApiLink = new EventVB.ApiFunctions
set wnd = new EventVB.Apiwindow
wnd.hWnd = me.hwnd
ApiLink.SubclasssedWindows.Add wnd
End Sub
private Sub Form_Terminate()
set wnd = nothing
set ApiLink = nothing
End Sub
This will give you a heap of new form events, of which you need to use:
private Sub wnd_ActiveApplicationChanged(byval ActivatingThisApp as Boolean, byval hThread as Long, Cancel as Boolean)
If Not ActivatingThisApp then
Cancel = true
End If
End Sub
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Cimperiali
May 22nd, 2001, 03:40 AM
It sounds good.
I have downloaded your product, but still have not find the time to test it. And, worse, I am already out of votes...
:-)
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
alanscl
May 22nd, 2001, 04:09 AM
HI! I had duplicated the same code but I am still able to switch to other existing windows. Pls advise!
Thanks!
Alan
Lutz
May 22nd, 2001, 08:29 AM
It is not yet clear, what you really want. Do you want to forbid any other application to be run, when yours is active? Any other application to deal with, when yours is running? If it is so, then windows is the wrong operating system for this, as it is a multithreaded one. Many programmers made big efforts just to avoid, that one solely application may be run at a time. Do you like to return to old DOS times?
So why shall your app be the only active one? Perhaps you want to avoid drag'n drop or cut'n paste, but this can be handled by other means (e.g. just clear the clipbord, whenever your app regets the focus). Or you want to avoid other programs to be started while yours is active?
Anyway, by accident I found some sort of solution for forbidding to switch to another app. You only have to enter a "SetFocus"-command for e.g. a TextBox into the Form_Paint-Event of that form, that you want to be always active. So whenever your form will be overpainted by another application, the Paint-Event fires and the SetFocus puts the focus back to your form.
But take care: surely there are users, that wont like this behaviour!
alanscl
May 22nd, 2001, 08:34 PM
I tried your method. It does not work too. Maybe I should elaborate more...
Ok.. Currently I am writing a user login for an application. When the user activate my login form, he is not suppose to:
1) click to another window. Suppose there are only 2 windows, login form & winword respectively, the user should not be able to click to the winword window active so that he can do his job in the winword and ignore the login form. He/She is suppose to be able to switch to the winword window after he exit from the login form.
2) The login form is suppose to stay on top no matter where the user click on the desktop.
Thanks. Hope this will enhance your understanding of my problem. Would appreciate if reply with coding.
Thanks for the help!
Alan
Lutz
May 28th, 2001, 07:49 AM
Perhaps the example I found here:
http://www.mvps.org/vb/code/ForceFore.zip
may help you...
alanscl
May 28th, 2001, 10:00 PM
Thanks Lutz!!! This example is really useful to my assignment....
Alan
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.