Solved

disable print screen

Posted on 1997-07-24
5
278 Views
Last Modified: 2008-03-17
I am trying to find a way within VB to disable the print screen key within my application.  I have secure information displayed and I don't want users to be able use the print screen key and then go into another application and paste and print information.  I only want this to be for this application and I don't want to disable the cut and paste for other applications they may have running.  Any ideas?
0
Comment
Question by:lilaudrey
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:ChrisLewis
ID: 1428840
You cannot disable the printscreen key in VB, but here's the start of a work around.

You can try this to start.

In a form with Keypreview set to TRUE...

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  Debug.Print "UP:" & KeyCode
  If KeyCode = vbKeyPrint Or vbKeySnapshot Then
    Clipboard.Clear
    MsgBox "No Print Screens!"
  End If

End Sub

This doesn't eliminate the printScreen, just immediately clears the copy buffer.  This, however, has some problems.  It only works if your form has focus.  If it's visible in the background, PrintScreen will still work.

Ways around this include minimizing the form when it looses forcus,  and also setting the form on top always.

To minimize on non use, try this.

Set a timer  in the form, with the following code. (interval real low - 2 or 3 based on processing needs)  

Private Sub Timer1_Timer()
  DoEvents
  Select Case apiGetFocus()
    Case Me.hWnd
    Case Text1.hWnd
    Case Text2.hWnd
    Case Command1.hWnd
    Case Else
      Me.WindowState = vbMinimized
  End Select
End Sub
You will have to put a line for each control on your form!

Ad a declare in a module:
Declare Function apiGetFocus Lib "user32" Alias "GetFocus" () As Long

This should work, even though it's kinda clunky

Hope this helps

Chris
0
 

Author Comment

by:lilaudrey
ID: 1428841
The first part works great, however the part on minimizing when it looses focus does not work.  Could this have something to do with the fact that we are using 16 bit VB instead of 32.  It bombs using your method on some DLL file.  I need both parts to work if I am to use this solution.    Thanks
0
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 100 total points
ID: 1428842
Yup, Would definately bomb in the 16 bit world.  For the 16 bit world, use the following API call:

Declare Function GetFocus Lib "User" Alias apiGetFocus () as Integer

Hope this helps

Chris
0
 

Author Comment

by:lilaudrey
ID: 1428843
Thanks,  I will try that and let you know if it works.  I agree it is sort of a weird solution but if it works it will be a great help in solving my security problem and will allow us to implement.
0
 

Author Comment

by:lilaudrey
ID: 1428844
Chris,
This doesn't seem to work either.  I do not have a user.dll.  Is this  my problem and if so could you send me one at acampbell @ppg.com
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 57
Updates not working for MS Windows 7 12 152
How to compare ms sql hashbytes results within vb6 5 54
MsgBox 4 45
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 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

19 Experts available now in Live!

Get 1:1 Help Now