Jump to content

Function to prevent screenshotting your application.


Draygoes
 Share

Recommended Posts

"Ok, so what is it?"
Just as it says in the title, you can choose to allow or disallow screenshots of your program.
"But why?"
You know that feeling when you first opened the CD tray with a line of code? Feels kind of like magic right? That's why I did this, it's a fun little magic trick that someone might find some real use for.
"Weirdo."
Hehe, I'm a bit tired right now. 😄

 

;WORKS AS OF VERSION 3.3.14.5



$WDA_NONE = 0x00000000;Imposes no restrictions on where the window can be displayed.
$WDA_MONITOR = 0x00000001;The window content is displayed only on a monitor. Everywhere else, the window appears with no content or may not appear at all.
Local $hGUI

;Usage - Just insert either function with no arguments any time after GUICreate.
Func _preventscreenshot()
    DllCall("user32.dll", "BOOL", "SetWindowDisplayAffinity", "HWnd", $hGUI, "DWORD", $WDA_MONITOR)
EndFunc
Func _allowscreenshot()
    DllCall("user32.dll", "BOOL", "SetWindowDisplayAffinity", "HWnd", $hGUI, "DWORD", $WDA_NONE)
EndFunc



;Example Use. It just calls the functions right after showing the GUI. The functions have no parameters.


#include <GUIConstantsEx.au3>
; Create a GUI with various controls.
    Global $hGUI = GUICreate("Try to screenshot me!!!")
    _preventscreenshot()
    Local $idOK = GUICtrlCreateButton("Close", 310, 370, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    MsgBox(64, "Screenshots are disabled.", "If you try to take a screenshot of the application window with this message open, the window will not appear in the screenshot. Clicking OK closes this dialog and ENABLES screenshotting.")
    _allowscreenshot()
; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

 

canscreenshot.AU3

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Are you aware that the API call, with an example, already exists?

Help File:  _WinAPI_SetWindowDisplayAffinity

Edited by TheXman
Link to comment
Share on other sites

Oh, no I can't say that I was aware. I'm very new to the WinAPI side of things.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...