|
-
May 12th, 2003, 10:45 PM
#1
Thread Starter
Hyperactive Member
how to not allow a copy/paste/print screen
Hey,
does anyone know how to disable a form so that the user cannot:
* right click the mouse to get theshortcut menu
* disable the use of ctrl-c inside a text box
* not press the print screen button
?
i need to make a form that people can read with their eyes, but cannot simply take the data and place into word etc...
cheers...
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
May 13th, 2003, 03:23 PM
#2
Fanatic Member
If you are talking about ASP, you probably should ask on the proper forum. For Windows Forms, most controls' text fields (main exceptions are textbox and richtextbox) are not selectable and will not have a right-click context menu unless you assign one.
Disabling cut/paste functions inside textbox and richtextbox, well, you are probably going to have to write your own controls that do not expose cut/paste methods. I don't believe there is a good way to suppress an object's builtin functions (someone please correct me if this is not true).
As far as the Print Screen key, that's handled by the operating system. While I suppose you might (might!) be able to intercept the alt-prtscr key combo if your form has focus, you can't do a whole lot if your form is not focused and the user just hits prtscr (unless you want to get into buggering up the user's keyboard, in which case please let me know so I can avoid ever using your software).
-
May 13th, 2003, 04:06 PM
#3
yay gay
actually disabling copy/past is very very easy..just subclass the text control and look up for the WM_COPY and WM_PAST (or whatever u want..here is the code from a book i have:
VB Code:
protected overrides sub wndproc(byref m as System.Windows.Forms.Message)
const WM_COPY = &H301
const WM_CUT = &H300
'filter messages
select case m.Msg
case WM_COPY, WM_CUT
MsgBox("u cant do this")
case else
mybase.wndproc(m)
end select
end sub
hope this helps and sorry for the formatting..just put it over the project and it will put the right cases
\m/  \m/
-
May 13th, 2003, 08:41 PM
#4
Fanatic Member
Is that all there is to using Overrides? From reading a couple of discussions on it I thought it was more complicated. Cool.
-
May 13th, 2003, 09:17 PM
#5
Thread Starter
Hyperactive Member
Slow_learner,
I am actually enquiring about Windows forms not ASP. Thanks for the info though.
I have run programs in the past where the PrtScrn key has not worked. Somehow the programmer has managed to disable it. Maybe even if there's a way to know when the user presses this key, it might then be possible to clear the clipboard????
Anyone?
PT_Exorcist,
thanks heaps for that. I will try it and see.
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
May 13th, 2003, 09:26 PM
#6
Addicted Member
Well even if you could intercept the printscreen key, wouldn't the user just be able to remove the focus from the form and press printscreen? Correct me if I'm wrong, but it seems to me that VB can only handle keys when the form has the focus.
Rick
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
May 14th, 2003, 12:13 AM
#7
Thread Starter
Hyperactive Member
PT Exorcist (or anyone),
I have placed the code into my form and it compiles all ok, but it never gets to the "u can't do this" message box.
all i have done is placed this code into the Form Designer Namespace. i don't think i have correctly "subclassed the text control".
can you please elaborate on what i need to do for this a bit more for me?
i really appreciate your help..
Last edited by stingrae; May 14th, 2003 at 12:54 AM.
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
May 14th, 2003, 01:47 AM
#8
Fanatic Member
A discussion of subclassing along with sample code:
http://www.codeproject.com/vb/net/subclassnetway.asp
(you have to register to download the complete project but much of the code is in the discussion)
Basically you would define a new class, in a module I suppose, that inherits TextBox, and inside that class you'd paste in the code that PT Exorcist provided. Then in your form, you would use the class you defined in any place you would have used TextBox.
About PrtScr: Yes, you could disable keys while your program is running, even to the point where the operating system cannot see them when your app isn't even running or does not have focus (I use utilities that do exactly this) but doing so silently is "not cool", and I would think some users would be annoyed. It's a registry setting, which I can't recall off the top of my head. You may not want to do it this way because it's possible for the setting to not be removed correctly (say if your app crashes or the user kills the process). I also found an article in MSDN Magazine archives:
ms-help://MS.VSCC/MS.MSDNVS/dnmag00/html/win320700.htm
"Q
Our team is working on interfacing patient monitoring systems to a central PC. At certain times during the application's processing, we want to prevent the user from switching to another application. Specifically, we'd like to intercept the special Ctrl+Esc, Alt+Tab, and Alt+Esc key combinations while our patient monitoring program is performing certain tasks. Can you offer any suggestions or hints to help us solve this?
Pankaj Duhan A
In Windows, there are usually only a few ways to intercept some type of system event. The mechanism that I always consider first is a hook because hooks are fully supported by Microsoft and infrastructure exists within the system specifically so that certain events can be intercepted. If a hook won't work, I'd think about API hooking. Microsoft does not officially support API hooking, so I always try to avoid it if possible.
Fortunately, this particular problem can be solved easily by setting a hook. Starting with Windows NT® 4.0 Service Pack 3, Microsoft added a low-level keyboard hook, WH_ KEYBOARD_LL, to the system. (This was the second new feature in Windows that I stumbled upon.) The normal, high-level keyboard hook, WH_KEYBOARD, intercepted keystrokes as they were removed from a thread's message queue. The WH_KEYBOARD hook is great for most applications. However, certain keystrokes are never directed to a thread's message queue. The Ctrl+Esc, Alt+Tab, and Alt+Esc key combinations are perfect examples. These keystrokes are handled internally by the system's raw input thread. Since application threads never receive messages for these keystrokes, there is no way that an application can intercept them and prevent the normal processing. This behavior is by design and ensures that a user can always switch to another application's window even if an application's thread enters an infinite loop or hangs.
However, there is a small class of applications that really has a valid need to intercept these keystrokes. To meet the needs of these applications, Microsoft introduced the WH_KEYBOARD_LL hook. This low-level hook is notified of keystrokes just after the user enters them and before the system gets a chance to process them. But this hook has a serious drawback: the thread processing the hook filter function could enter an infinite loop or hang. If this happens, then the system will no longer process keystrokes properly and the user will become incredibly frustrated.
To alleviate this situation, Microsoft places a time limit on low-level hooks. When the system sends a notification to a low-level keyboard hook's filter function, the system gives the function a fixed amount of time to execute. If the function does not return in the allotted time, the system ignores the hook filter function and processes the keystroke normally. The amount of time that is allowed (in milliseconds) is set via the LowLevelHooksTimeout value under the HKEY_CURRENT_USER\Control Panel\Desktop registry subkey.
The DisableLowLevelKeys.cpp file shown in Figure 2 demonstrates how to install a WH_KEYBOARD_LL hook to intercept and discard the low-level Ctrl+Esc, Alt+Tab, and Alt+Esc key combinations. When you run the application, it installs the hook and displays the message box shown in Figure 3.
Figure 3 Disabling Low-level Keys
While the message box is displayed, you will not be able to switch to another application using the usual keystroke combinations. When you press the OK button, the message box is closed and the hook is removed, allowing the low-level keys to be processed by the system as usual."
The sample code is 79k (a bit big to post) but you ought to be able to get it off the Microsoft site.
-
May 14th, 2003, 01:53 AM
#9
Fanatic Member
Aha the name of the API function is SetWindowsHookEx, here is cut/paste from API Guide in VB6:
Code:
'In a module
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
Form1.Print "Shift-S pressed ..."
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
'In a form, called Form1
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'set a keyboard hook
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|