CImage类的使用

#include "stdafx.h"

#include <windows.h>
#include <atlimage.h>

int __stdcall WinMain(
            HINSTANCE hInstance,
            HINSTANCE hPrevInstance,
            LPSTR lpCmdLine,
            int nShowCmd)
{
    HWND hwnd = ::GetDesktopWindow();
    HDC hDC = ::GetDC(hwnd);

    RECT rect;
    ::GetClientRect(hwnd, &rect);
    HDC hDCMem = ::CreateCompatibleDC(hDC);

    HBITMAP hBitMap = ::CreateCompatibleBitmap(hDC, rect.right, rect.bottom);
    HBITMAP hOldMap = (HBITMAP)::SelectObject(hDCMem, hBitMap);

    ::BitBlt(hDCMem, 0, 0, rect.right, rect.bottom, hDC, 0, 0, SRCCOPY);

    CImage image;
    image.Attach(hBitMap);
    image.Save("c://B.bmp");
    image.Detach();

    ::SelectObject(hDCMem, hOldMap);
    ::DeleteObject(hBitMap);
    ::DeleteDC(hDCMem);
    ::DeleteDC(hDC);

    return 0;
}

 

 

、、、、

2

HBITMAP LoadPngPicture(const TCHAR* szTPngPicName)
{
    CImage    MyImage;
    MyImage.Load(szTPngPicName);
   
if(MyImage.IsNull())
    {
        MessageBox(_T(
"Load Error"));
       
return NULL;
    }
    HBITMAP hbitmap
= MyImage.Detach();
   
return hbitmap;
}

你可能感兴趣的:(c,image,null,include)