Solved

disable print screen

Posted on 1997-07-24
5
272 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now