• 屏幕截图(带光标)


    原文链接地址:http://blog.csdn.net/VisualEleven/article/details/6093484

    // 屏幕截图程序,可运行PC,WinCE,Windows Mobile平台上
    
    void SaveScreenToFile(LPCTSTR szFileName)
    {
        HDC hScrDC = ::GetDC(NULL);
        HDC hMemDC = NULL;
        
        BYTE *lpBitmapBits = NULL; 
        
        int nWidth = GetSystemMetrics(SM_CXSCREEN);
        int nHeight = GetSystemMetrics(SM_CYSCREEN); 
        
        hMemDC = ::CreateCompatibleDC(hScrDC); 
        
        BITMAPINFO bi; 
        ZeroMemory(&bi, sizeof(BITMAPINFO));
        bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        bi.bmiHeader.biWidth = nWidth;
        bi.bmiHeader.biHeight = nHeight;
        bi.bmiHeader.biPlanes = 1;
        bi.bmiHeader.biBitCount = 24;
    
        HCURSOR hCursor = GetCursor();
        POINT ptCursor;
        GetCursorPos(&ptCursor);
        ICONINFO IconInfo = {0};
        if(GetIconInfo(hCursor, &IconInfo))
        {
            ptCursor.x -= IconInfo.xHotspot;
            ptCursor.y -= IconInfo.yHotspot;
            if(NULL != IconInfo.hbmMask)
                DeleteObject(IconInfo.hbmMask);
            if(NULL != IconInfo.hbmColor)
                DeleteObject(IconInfo.hbmColor);
        }
        
        
        HBITMAP bitmap = ::CreateDIBSection(hMemDC, &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0);
        HGDIOBJ oldbmp = ::SelectObject(hMemDC, bitmap); 
        
        ::BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY);
        DrawIconEx(hMemDC, ptCursor.x, ptCursor.y, hCursor, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT);
    
        BITMAPFILEHEADER bh;
        ZeroMemory(&bh, sizeof(BITMAPFILEHEADER));
        bh.bfType = 0x4d42;  //bitmap  
        bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
        bh.bfSize = bh.bfOffBits + ((nWidth*nHeight)*3);
        
        CFile file;
        if(file.Open(szFileName, CFile::modeCreate | CFile::modeWrite))
        {  
            file.Write(&bh, sizeof(BITMAPFILEHEADER));
            file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER));
            file.Write(lpBitmapBits, 3 * nWidth * nHeight);
            file.Close();
        }
        
        ::SelectObject(hMemDC, oldbmp);
        ::DeleteObject(bitmap);
        ::DeleteObject(hMemDC);
        ::ReleaseDC(NULL, hScrDC);
    }
    BOOL DrawIconEx(          HDC hdc,
        int xLeft,
        int yTop,
        HICON hIcon,
        int cxWidth,
        int cyWidth,
        UINT istepIfAniCur,
        HBRUSH hbrFlickerFreeDraw,
        UINT diFlags
    );
    //The DrawIconEx function draws an icon or cursor into the specified device context, performing the specified raster operations, and stretching or compressing the icon or cursor as specified.
  • 相关阅读:
    Http异常状态码解决方案。
    integer 面试题。
    int转换为String,常用的四种方法。
    Implicit super constructor Array() is undefined for default constructor. Must define an explicit constructor
    Eclipse的常用设置。
    构造方法详解。
    this关键字。
    面向对象--构造方法知识点。
    生成1-100之间的随机数。
    redis回顾
  • 原文地址:https://www.cnblogs.com/wuyuan2011woaini/p/4815587.html
Copyright © 2020-2023  润新知