Add wxTopLevelWindow::SetContentProtection()

This method allows to exclude a top level window from screen captures.
Windows 7 or newer is required and any macOS version is supported.
Other platforms are not implemented and will return false.

The display example has been extended to demo this ability.

Closes #22066.
This commit is contained in:
Tobias Taschner
2022-01-27 18:14:08 +01:00
committed by Vadim Zeitlin
parent f172f53ac4
commit 0a7b3bb3cf
12 changed files with 188 additions and 0 deletions

View File

@@ -67,6 +67,7 @@ public:
void OnQuit(wxCommandEvent& event);
void OnFromPoint(wxCommandEvent& event);
void OnFullScreen(wxCommandEvent& event);
void OnContentProtection(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
#if wxUSE_DISPLAY
@@ -115,6 +116,8 @@ enum
// menu items
Display_FromPoint = wxID_HIGHEST + 1,
Display_FullScreen,
Display_ContentProtection_None,
Display_ContentProtection_Enable,
// controls
Display_ChangeMode,
@@ -140,6 +143,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Display_Quit, MyFrame::OnQuit)
EVT_MENU(Display_FromPoint, MyFrame::OnFromPoint)
EVT_MENU(Display_FullScreen, MyFrame::OnFullScreen)
EVT_MENU(Display_ContentProtection_None, MyFrame::OnContentProtection)
EVT_MENU(Display_ContentProtection_Enable, MyFrame::OnContentProtection)
EVT_MENU(Display_About, MyFrame::OnAbout)
#if wxUSE_DISPLAY
@@ -210,6 +215,13 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
itemFullScreen->SetBitmap(
wxArtProvider::GetBitmap(wxART_FULL_SCREEN, wxART_MENU)
);
wxMenu* contentProtectionMenu = new wxMenu();
contentProtectionMenu->Append(Display_ContentProtection_None, _("&None"), "", wxITEM_RADIO);
contentProtectionMenu->Check(Display_ContentProtection_None, true);
contentProtectionMenu->Append(Display_ContentProtection_Enable, _("&Enabled"), "", wxITEM_RADIO);
menuDisplay->Append(wxID_ANY, _("Content &Protection"), contentProtectionMenu);
menuDisplay->Append(itemFullScreen);
menuDisplay->AppendSeparator();
menuDisplay->Append(Display_Quit, _("E&xit\tAlt-X"), _("Quit this program"));
@@ -406,6 +418,34 @@ void MyFrame::OnFullScreen(wxCommandEvent& WXUNUSED(event))
ShowFullScreen(!IsFullScreen());
}
void MyFrame::OnContentProtection(wxCommandEvent& event)
{
wxContentProtection contentProtection;
switch (event.GetId())
{
case Display_ContentProtection_Enable:
contentProtection = wxCONTENT_PROTECTION_ENABLED;
break;
default:
contentProtection = wxCONTENT_PROTECTION_NONE;
}
if (SetContentProtection(contentProtection))
{
switch (GetContentProtection())
{
case wxCONTENT_PROTECTION_ENABLED:
wxLogInfo("The contents of this window should now NOT be visible in screen captures.");
break;
case wxCONTENT_PROTECTION_NONE:
wxLogInfo("The contents of this window should now be visible in screen captures.");
break;
}
}
else
wxLogError("Content protection could not be changed");
}
#if wxUSE_DISPLAY
void MyFrame::OnChangeMode(wxCommandEvent& event)