禁用屏幕拷贝(Print Screen),调用派生的析构函数及其它......
2007-03-15 21:56:11 来源:WEB开发网核心提示: // 热键的处理方法// MainFrame.h#include "FolderFrame.h"#include "resource.h"// Typical MFC Main frame window, override to disable Pr
// 热键的处理方法
// 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 nothing (bypass Windows screen capture)
//
LRESULT CMainFrame::OnHotKey(WPARAM wp, LPARAM)
{
UNREFERENCED_PARAMETER(wp);
return 0; // ignore
}
//////////////////
// When 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);
}
上述代码段展示了一个典型的 MFC CMainFrame 类实现。OnCreate/OnDestroy 函数用来注册/注销 IDHOT_SNAPDESKTOP 热键;OnActivate 函数用来在应用程序 处于激活/和非激活状态时注册/注销 IDHOT_SNAPWINDOW 热键。当你的窗口处于非激活状态时,通过重新启用 IDHOT_SNAPWINDOW,当别的应用程序拥有焦点时,用户仍然能用 Alt+Print Screen 来复制屏幕。
更多精彩
赞助商链接