如果仅仅是想屏蔽printscreen按键
那么直接在你的程序重新registered即可
RegisterHotKey(m_hWnd, IDHOT_SNAPDESKTOP, 0, VK_SNAPSHOT);
RegisterHotKey(m_hWnd, IDHOT_SNAPWINDOW, MOD_ALT, VK_SNAPSHOT);更详细说明: http://www.vckbase.com/document/viewdoc/?id=1566
//--------------------------------------------------------------------------------------------------------------------
键盘printscreen按键默认情况
printscreen 截屏(不截光标)
printscreen+alt 截当前窗口(不截光标)
本文增强printscreen按键功能,使之
printscreen 截屏(显示光标)
printscreen+alt 截当前窗口(显示光标)
主要处理过程:
registered printscreen按键的hotkey,见本文头,
在WNDPROC中处理WM_HOTKEY,判断printscreen按键事件,截图并画光标,保存截图内容到剪切板。
关键代码:
截图
void TmainForm::SaveScreenBmpToClipboard()
{
HDC hdc=GetDC(NULL);
if(hdc)
{
HDC memDC=CreateCompatibleDC(hdc);
assert(memDC);
HBITMAP hBmp=CreateCompatibleBitmap(hdc,Screen->Width,Screen->Height);
assert(hBmp);
SelectObject(memDC,hBmp);
::BitBlt(memDC,0,0,Screen->Width,Screen->Height,hdc,0,0,SRCCOPY);
DrawCursor(memDC);
if(OpenClipboard(Handle))
{
assert(EmptyClipboard());
assert(SetClipboardData(CF_BITMAP,hBmp));
assert(CloseClipboard());
}
else
{
MessageBoxA(NULL,"无法打开剪切板!","提示",MB_ICONERROR);
}
DeleteObject(hBmp);
DeleteObject(memDC);
ReleaseDC(NULL,hdc);
}
}
画出光标
void TmainForm::DrawCursor(HDC hdc,bool bScreen)
{
HCURSOR hCursor=GetCursor();
POINT ptCursor;
GetCursorPos(&ptCursor);
if(!bScreen)
{
::ScreenToClient(GetForegroundWindow(),&ptCursor);
}
//获取光标的图标数据
ICONINFO IconInfo;
if (GetIconInfo(hCursor, &IconInfo))
{
ptCursor.x -= ((int) IconInfo.xHotspot);
ptCursor.y -= ((int) IconInfo.yHotspot);
if (IconInfo.hbmMask != NULL)
DeleteObject(IconInfo.hbmMask);
if (IconInfo.hbmColor != NULL)
DeleteObject(IconInfo.hbmColor);
}
//在兼容设备描述表上画出该光标
DrawIconEx(
hdc, // handle to device context
ptCursor.x, ptCursor.y,
nCursorType==0?hCursor:LoadCursor(NULL,MAKEINTRESOURCE(nCursorType)), // handle to icon to draw
0,0, // width of the icon
0, // index of frame in animated cursor
NULL,
DI_NORMAL | DI_COMPAT
// icon-drawing flags
);
}
下载地址:http://download.csdn.net/detail/qq752923276/4270836