增强printscreen按键-显示光标

如果仅仅是想屏蔽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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值