Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

disable print screen

Posted on 1997-07-24
5
Medium Priority
?
335 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

810 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