Hi,
How do I prevent taking screenshots of my application’s main window?
I tested the undocumented API first: Declare Function CGSSetWindowCaptureExcludeShape Lib “ApplicationServices” (cid As UInt32, wid As UInt32, region As Ptr) As Integer, used by KeepassXC app, but it seems to no longer work…
then function “NSWindowSharingNone” of sharingType property on NSWindow with this code. It compiles but does not seem to prevent capture… If you have any information to move forward, I am interested…
Sub DisableWindowCapture()
#If TargetMacOS Then
// Déclaration pour obtenir l'instance NSApplication
Declare Function NSClassFromString Lib "Cocoa" (aClassName As CFStringRef) As Ptr
Declare Function sharedApplication Lib "Cocoa" Selector "sharedApplication" (NSApp As Ptr) As Ptr
Declare Function mainWindow Lib "Cocoa" Selector "mainWindow" (NSApp As Ptr) As Ptr
Declare Sub setSharingType Lib "Cocoa" Selector "setSharingType:" (NSWindow As Ptr, sharingType As Integer)
Const NSWindowSharingNone = 0
// Obtenir l'instance partagée de l'application
Dim appClass As Ptr = NSClassFromString("NSApplication")
Dim sharedApp As Ptr = sharedApplication(appClass)
// Obtenir la fenêtre principale
Dim mainWnd As Ptr = mainWindow(sharedApp)
// Définir le SharingType de la fenêtre principale sur None
setSharingType(mainWnd, NSWindowSharingNone)
#EndIf
End Sub
Sub Opening()
DisableWindowCapture()
System.DebugLog("La capture d'écran de cette fenêtre est désactivée.")
End Sub
Thanks
Dan