增强printscreen按键-显示光标
  lcYh0pvD0OAe 2023年11月02日 55 0


如果仅仅是想屏蔽printscreen按键

那么直接在你的程序重新registered即可


RegisterHotKey(m_hWnd, IDHOT_SNAPDESKTOP, 0, VK_SNAPSHOT);


RegisterHotKey(m_hWnd, IDHOT_SNAPWINDOW, MOD_ALT, VK_SNAPSHOT);

//--------------------------------------------------------------------------------------------------------------------

键盘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   
    ); 
}



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  CiIZfyyIq65u   2023年11月30日   28   0   0 icoico
  VhtxyaVzvLBv   2023年11月25日   31   0   0 sedsedSQLicoSQLico
lcYh0pvD0OAe