Disables screen copies (Print screens), calls derived destructors, and other

Source: Internet
Author: User
Tags bool

I'm developing a program that shows graphics with intellectual property, is there any way to disable the screen copy feature (Print screens) to prevent users from copying images to the clipboard?

There is one way to disable screen copying, but I have to tell you that it is impossible to prevent other applications from copying pixel content from your window. Many Third-party programs can capture screen content, and this procedure is not difficult to write. To intercept pixels on the screen, you can only use BitBlt to copy them from the screen device context, for example:CWindowDC dc(NULL);  // 用 NULL 获取整个屏幕
CDC memdc;
... // 创建, 初始化 memdc
memdc.BitBlt(..., &dc); // 拷贝屏幕内容

To copy the contents of the currently active window, you can extract the content by simply getting the CWnd pointer of the window and then using it to construct a CWINDOWDC.

In short, you can't stop other programs from intercepting the pixels of your window. So, if you just want to disable "screen copy" or stop the feature from doing something, it's really easy. Windows implements the "screen copy" feature by registering a hotkey. In my December 2000 column, I demonstrated how to register an application hotkey with RegisterHotKey (see C + + q&a:sending Messages in Windows, adding hot Keys to your A pplication), Windows uses a predefined hotkey idhot_snapdesktop and Idhot_snapwindow to process "screen copies." The two hotkeys correspond to "Print screen" and "Alt+print screens", which are used to copy the entire display, while the latter only copies the currently active window. To disable these features, you just register these hotkeys, and when the user presses the hotkey, let Windows send wm_hotkey messages to your program, and you can ignore the messages and bypass the default screen copy behavior. Your main frame (mainframe) class is the perfect place to do this.

How to handle hot keys
MainFrame.h
#include "FolderFrame.h"
#include "resource.h"
////////////////
Typical MFC Main frame window, override to disable Printscreen.
//
Class Cmainframe:public CFrameWnd {
Protected
...
afx_msg int OnCreate (lpcreatestruct lpcreatestruct);
Disable Printscreen
afx_msg void OnActivate (UINT nstate, cwnd* pwndother, BOOL bminimized);
afx_msg lresult Onhotkey (WPARAM WP, LPARAM LP);
afx_msg void OnDestroy ();
Declare_message_map ()
};
MainFrame.cpp
#include "StdAfx.h"
#include "MainFrm.h"
#include "View.h"
Implement_dyncreate (CMainFrame, CFrameWnd)
Begin_message_map (CMainFrame, CFrameWnd)
...
Disable Printscreen:
On_wm_create ()
On_wm_destroy ()
On_wm_activate ()
On_message (Wm_hotkey, Onhotkey)
End_message_map ()
...
int CMainFrame::OnCreate (lpcreatestruct lpcreatestruct)
{
...
RegisterHotKey (m_hwnd, idhot_snapdesktop, 0, Vk_snapshot);
return 0;
}
void Cmainframe::ondestroy ()
{
Unregisterhotkey (M_hwnd, idhot_snapdesktop);
}
//////////////////
Handle hotkey:should be Printscreen or Alt-printscreen.
Do No (bypass Windows screen capture)
//
Lresult Cmainframe::onhotkey (WPARAM wp, LPARAM)
{
Unreferenced_parameter (WP);
return 0; Ignore
}
//////////////////
When the window is activated/deactivated, disable/enable alt-printscreen.
(Idhot_snapwindow)
//
void Cmainframe::onactivate (UINT nstate, cwnd* Pwndother,
BOOL bminimized)
{
Cframewnd::onactivate (nstate, Pwndother, bminimized);
if (nstate)
RegisterHotKey (M_hwnd, Idhot_snapwindow, Mod_alt, vk_snapshot);
Else
Unregisterhotkey (M_hwnd, Idhot_snapwindow);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.