• 屏幕截图(带光标)


    原文链接地址: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.
  • 相关阅读:
    CSS权重
    object.create(null) 和 {}创建对象的区别
    CSS边框作图
    细说HTML头部标签
    利用a标签导出csv文件
    细说CSS伪类和伪元素
    HTML标签的权重
    《SPA设计与架构》之客户端路由
    《SPA设计与架构》之JavaScript模块化
    《SPA设计与架构》之MV*框架
  • 原文地址:https://www.cnblogs.com/wuyuan2011woaini/p/4815587.html
Copyright © 2020-2023  润新知