Prevent a Screen Capture

Posted on 2003-11-04
Last Modified: 2013-11-20

I'm writing an application, and I'm trying to prevent the user to grab a screen capture using the Print Screen button, or a third-party tool.
What is the best way? It doens't has to be full waterproof, just dummyproof.
The more secure, the better.

Can I use MFC with some hooks?

Thanks in advance,
Question by:eXecutiVe
  • 5
  • 5
  • 2
  • +1
LVL 12

Expert Comment

ID: 9683573

 Yes you should use SetWindowsHookEx and CallNextHookEx

  You can hook the keyboard and stop ctrl and alt printscreen getting through by not calling the next hook function.
  With third party apps is could be difficult because to capture the screen simply requires you to create a compatible bitmap with the desktop an do a could hook into the bitblt API see this article


   You might also want to monitor the clipboard as useually the image is placed there during this operation.

   Let me know which line of attack you'd like to pursue :)


Author Comment

ID: 9683748
The article of bugslayer points to Smooth Working Set (I don't know what that is).

Can you give me some more information about that hook into bitblt? What exactly should I override or something? I think we're on the right track.

Thanks in advance!
LVL 49

Expert Comment

ID: 9684963
Not an answer, but I am curious...
I have racked my brain and can't think of a single reasonable purpose for such a function.  Why do you need it?
-- Dan
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

LVL 48

Expert Comment

ID: 9685143

DisableLowLevelKeys sample disables Alt+Tab, Ctrl+Esc and other key combinations. You can use this sample, jusr change the keys you want to disable in the LowLevelKeyboardProc function.

Author Comment

ID: 9685195
To DanRollins:
I have to design such tool for some architects who want to preview images to their customers, but the danger is that the customer doesn't pay the architect, but runs away with the jpeg inside.

(Sorry for my bad english, I'm aware if it hehe)

Is there anybody with some more info on the bitblt hook?

Thanks in advance!
LVL 12

Expert Comment

ID: 9688589
  If you take a look a HFIBN_Test.cpp in the bugslayer example  

Here are the changes you need to make to the test program for BitBlt

Here is the BitBlt function

BOOL My_NewBitBlt (
  HDC hdcDest, // handle to destination DC
  int nXDest,  // x-coord of destination upper-left corner
  int nYDest,  // y-coord of destination upper-left corner
  int nWidth,  // width of destination rectangle
  int nHeight, // height of destination rectangle
  HDC hdcSrc,  // handle to source DC
  int nXSrc,   // x-coordinate of source upper-left corner
  int nYSrc,   // y-coordinate of source upper-left corner
  DWORD dwRop  // raster operation code
    // Handle the Call

  typedef int (__stdcall *BITBLTPROC)(HDC ,int ,int ,int ,int ,HDC,int ,int ,DWORD) ;

   BITBLTPROC pfnOrigBitBlt = NULL ;

    stToHook.szFunc = "BitBltA" ;  // none unicode version
    stToHook.pProc  = (PROC)My_NewBitBlt;  // this is your new proc for BitBlt

    DWORD uiCount ;

    BOOL bRet =
        HookImportedFunctionsByName ( GetModuleHandle ( NULL ) ,
                                      "GDI32.DLL"             ,
                                      1                        ,
                                      &stToHook                ,
                                      (PROC*)&pfnOrigBitBlt    ,
                                      &uiCount                  ) ;

You will need to use HookImportedFunctionByName.Cpp and BugSlayerUtil.h

Build a sample program first and let us know how it goes

Author Comment

ID: 9691190
Getting closer...

The hook works now fine (I've tested it with a button that does a BitBlt), but when I use a screen capture program, my hook isn't called. They seem to use another function.

Anybody some ideas?

Thank you very much william campbell

LVL 12

Expert Comment

ID: 9695534
Do you have access to the Resource Kit for Win2k? There is a program called APIMON.EXE. Perhaps you could use this to find out what API's they are using. There is also StretchBlt!

Author Comment

ID: 9697822
I think they do a bitblt from the desktop window and it seems I'm not able to catch that call.
But there must be a way I believe.
Can't I modify the onDraw function? Or clear every 100miliseconds  the clipboard or something?

I'm really desperate
Thank you in advance for your time

LVL 12

Accepted Solution

williamcampbell earned 500 total points
ID: 9697993

 I think I might have an idea.

 Create an app with the image as part of the resource (in a dll) when the app is launched it goes full screen and displays the image. If the app looses focus close the app immediately (they are trying to get to another app). Or if ctrl or alt are pressed immediately close the app, do this via the keyboard hook. What do you think?

LVL 49

Expert Comment

ID: 9698063
You *might* find some sort of kludgy workaround, but the only valid solution to this problem is to not send a usable image to somebody who will steal it from you.  

I recommend embedding a "watermark" (say the words "CONFIDENTIAL, Do Not COPY") writen in dim grey text in a diagonal lines all over the "background" of the image.  And obviously, place a bright, clear, copyright notice at several places in the image.

You could also show them an image in which the resolution had been so compormised that the result would provide a reasonable idea of what the final would look like, but still not be usable.  

Another idea is to do what map-makers have done for years... intentionally embed subtle mistakes in the image.  If the image gets passed around, the mistakes act as a signature.  You can sue the person who infringes your copyright and get a nice new home in Beverly Hills, California and never need to work another day in your life.

-- Dan
LVL 12

Expert Comment

ID: 9698086

 You could also create a screen saver of the image and lock the workstation with a password :) Doesnt prevent them from taking a picture with a digital camera however :p

Author Comment

ID: 9698231
Is there a way using directX and overlay or something so the screen can't be captured?


Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 78
isEverywhere  challenge 19 74
twoTwo  challenge 35 101
abstract class with all non abstract mentods 6 76
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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