viewgif.cpp

来自「Visual C++ 的学习资料一」· C++ 代码 · 共 98 行

CPP
98
字号
// ViewGif.cpp : implementation file
//

#include "stdafx.h"
#include "GIF.h"
#include "ViewGif.h"
#include <Atlbase.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CViewGif dialog


CViewGif::CViewGif(CWnd* pParent /*=NULL*/)
	: CDialog(CViewGif::IDD, pParent)
{
	//{{AFX_DATA_INIT(CViewGif)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CViewGif::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CViewGif)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CViewGif, CDialog)
	//{{AFX_MSG_MAP(CViewGif)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CViewGif message handlers

BOOL CViewGif::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CViewGif::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	char buf[512];
	::GetCurrentDirectory(512,buf);
	strcat(buf,"\\test.gif");
	CFileStatus fstatus; 
    CFile file; 
	IStream *pStm;
    LONG cb; 	
    if(file.Open(buf,CFile::modeRead)&&file.GetStatus(buf,fstatus)&& 
    ((cb = fstatus.m_size) != -1)) 
    { 
    HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb); 
    LPVOID pvData = NULL; 
    if (hGlobal != NULL) 
    { 
    if ((pvData = GlobalLock(hGlobal)) != NULL) 
    { 
    file.ReadHuge(pvData, cb); 
    GlobalUnlock(hGlobal); 
    CreateStreamOnHGlobal(hGlobal, TRUE, &pStm); 
    } 
    } 
    }
	IPicture *pPic; 
	//CComQIPtr<IPicture> pPic;
     if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,false,IID_IPicture,(LPVOID*)&pPic)))
	{
	long a,b;
	pPic->get_Width(&a);
	pPic->get_Height(&b);
	CSize sz(a,b);
	CDC *pdc=GetDC();
	pdc->HIMETRICtoDP(&sz);
	CRect rect;
	this->GetClientRect(&rect);
	pPic->Render(*pdc,rect.left+1,rect.top+1,sz.cx,sz.cy,0,b,a,-b,&rect);
	}
	// Do not call CDialog::OnPaint() for painting messages
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?