본문 바로가기

Windows/MFC

gdi plus

[code]
// stdafx.h -----------------------------------------------------------------------------------------

#include <GdiPlus.h>
using namespace Gdiplus;


// GDI+용 더블 버퍼링 클래스
class CGDIPlusDBuffer
{
    HWND            m_hWnd;                // 더블 버퍼링을 실행할 윈도우 핸들
    Graphics*        m_pGraphics;        // 더블 버퍼링용 Graphics 포인터
    Bitmap*            m_pMemBmp;            // 메모리 비트맵 포인터

public:
    // 생성자 : 반드시 윈도우 핸들을 인자로 설정해야 한다
    CGDIPlusDBuffer(HWND hWnd);


    // 소멸자 : 버퍼에 출력된 그래픽을 화면에 출력한다
    virtual ~CGDIPlusDBuffer();    


    // 더블 버퍼링용 Graphics 포인터를 리턴하는 함수
    Graphics* GetGraphics()        { return m_pGraphics; }
};
[/code]


[code]
// stdafx.cpp ---------------------------------------------------------------------------

// 생성자 : 반드시 윈도우 핸들을 인자로 설정해야 한다
CGDIPlusDBuffer::CGDIPlusDBuffer(HWND hWnd)
{
    // 멤버 변수 초기화
    m_hWnd = hWnd;
    m_pGraphics = NULL;
    m_pMemBmp = NULL;    

    CRect rcClient;
    ::GetClientRect(hWnd, &rcClient);

    // 메모리 비트맵을 생성한다
    m_pMemBmp = new Bitmap(rcClient.Width(), rcClient.Height());
    // 메모리 비트맵에 그래픽을 출력할 수 있는 Graphics 객체를 생성한다
    m_pGraphics = Graphics::FromImage(m_pMemBmp);
}



// 소멸자 : 버퍼에 출력된 그래픽을 화면에 출력한다
CGDIPlusDBuffer::~CGDIPlusDBuffer()
{

    // 만약 객체들이 생성되어 있다면
    if(m_pGraphics && m_pMemBmp)
    {
        // 윈도우의 DC를 얻는다
        HDC hDC = ::GetDC(m_hWnd);
        // 윈도우의 화면 Graphics 객체를 생성한다
        Graphics graphics(hDC);

        // 화면 Graphics 객체를 사용하여 메모리 비트맵의 내용을 복사하여 캐쉬 비트맵을 생성한다
        CachedBitmap *pCachedBmp = new CachedBitmap(m_pMemBmp, &graphics);

        // 캐쉬 비트맵을 화면에 출력한다
        graphics.DrawCachedBitmap(pCachedBmp, 0, 0);

        // 캐쉬 비트맵을 제거한다
        delete pCachedBmp;
        // DC를 반환한다
        ::ReleaseDC(m_hWnd, hDC);
    }

    // 객체들을 제거한다
    if(m_pGraphics)        delete m_pGraphics;
    if(m_pMemBmp)        delete m_pMemBmp;    

}
[/code]

[code]
// InitInstance() ------------------------------------------------------------------------
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
[/code]


[code]
// ExitInstance() ------------------------------------------------------------------------
GdiplusShutdown(m_gdiplusToken);
[/code]

'Windows > MFC' 카테고리의 다른 글

CFileDialog 파일 열기 옵션  (0) 2013.10.02
공통 다이얼 로그 (Common Dialog)  (0) 2013.10.02
MFC에서 API를 쓸때 handle 관련  (0) 2013.10.02
TreeList Control 트리리스트 컨트롤  (0) 2013.10.02
mmxmemcpy  (0) 2013.10.02