• 桌面截屏


     

      

    //捕获桌面屏幕
    BOOL CFunction::ScreenCapture()
    {
        // 获取桌面窗口句柄
        HWND hDesktopWnd = ::GetDesktopWindow();
        if (hDesktopWnd == NULL)
        {
            return FALSE;
        }
    
        // 获取桌面窗口DC
        HDC hdc = ::GetDC(hDesktopWnd);
        if (hdc == NULL)
        {
            return FALSE;
        }
    
        // 创建兼容DC
        HDC mdc = ::CreateCompatibleDC(hdc);
        if (mdc == NULL)
        {
            return FALSE;
        }
    
        // 获取计算机屏幕的宽和高
        DWORD dwScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
        if (dwScreenWidth == NULL)
        {
            return FALSE;
        }
        DWORD dwScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
        if (dwScreenHeight == NULL)
        {
            return FALSE;
        }
    
        // 创建兼容位图
        HBITMAP bmp = ::CreateCompatibleBitmap(hdc, dwScreenWidth, dwScreenHeight);
        if (bmp == NULL)
        {
            return FALSE;
        }
    
        // 选中位图
        HBITMAP holdbmp = (HBITMAP)::SelectObject(mdc, bmp);
        if (holdbmp == NULL)
        {
            return FALSE;
        }
    
        // 将窗口内容绘制到位图上
        ::BitBlt(mdc, 0, 0, dwScreenWidth, dwScreenHeight, hdc, 0, 0, SRCCOPY);
    
        // 绘制鼠标
        PaintMouse(mdc);
    
        // 保存为图片
        SaveBmp(bmp);
    
        return TRUE;
    }
    
    //绘制鼠标
    BOOL CFunction::PaintMouse(HDC hdc)
    {
        // 创建兼容DC
        HDC bufdc = ::CreateCompatibleDC(hdc);
    
        //获取光标信息
        CURSORINFO cursorInfo = { sizeof(CURSORINFO) };
        ::GetCursorInfo(&cursorInfo);
    
        // 获取光标的图标信息
        ICONINFO iconInfo = { 0 };
        ::GetIconInfo(cursorInfo.hCursor, &iconInfo);
    
        // 绘制白底黑鼠标(AND)
        ::SelectObject(bufdc, iconInfo.hbmMask);
        ::BitBlt(hdc, cursorInfo.ptScreenPos.x, cursorInfo.ptScreenPos.y, 20, 20, bufdc, 0, 0, SRCAND);
    
        // 绘制黑底彩色鼠标(OR)
        ::SelectObject(bufdc, iconInfo.hbmColor);
        ::BitBlt(hdc, cursorInfo.ptScreenPos.x, cursorInfo.ptScreenPos.y, 20, 20,
            bufdc, 0, 0, SRCPAINT);
    
        // 释放资源
        DeleteObject(iconInfo.hbmColor);
        DeleteObject(iconInfo.hbmMask);
        DeleteDC(bufdc);
    
        return TRUE;
    }
    
    //保存为图片
    BOOL CFunction::SaveBmp(HBITMAP hBmp)
    {
        CImage image;
    
        // 附加位图句柄
        image.Attach(hBmp);
    
        // 保存成JPG格式图片
        image.Save(_T("mybmp1.jpg"));
    
        return TRUE;
    }
  • 相关阅读:
    BZOJ3064: Tyvj 1518 CPU监控
    BZOJ3160: 万径人踪灭
    BZOJ3527: [Zjoi2014]力
    BZOJ2194: 快速傅立叶之二
    FFT模板
    Splay树再学习
    POJ2406 Power Strings KMP算法
    POJ2752 Seek the Name,Seek the Fame KMP算法
    POJ3461 Oulipo KMP算法
    POJ2004 Mix and build Trie树? dp?
  • 原文地址:https://www.cnblogs.com/ndyxb/p/12912733.html
Copyright © 2020-2023  润新知