求各位大神指点一下小弟 为什么显示不了图片
// MyPictureView.cpp : implementation of the CMyPictureView class
//
#include "stdafx.h"
#include "MyPicture.h"
#include "MyPictureDoc.h"
#include "MyPictureView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMyPictureView
IMPLEMENT_DYNCREATE(CMyPictureView, CView)
BEGIN_MESSAGE_MAP(CMyPictureView, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
END_MESSAGE_MAP()
// CMyPictureView construction/destruction
CMyPictureView::CMyPictureView()
{
// TODO: add construction code here
}
CMyPictureView::~CMyPictureView()
{
}
BOOL CMyPictureView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CMyPictureView drawing
void CMyPictureView::OnDraw(CDC* pDC)
{
CMyPictureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
pDC = GetDC();
ShowJpg(pDC, "F:\KuGou\专辑\Super Girl.jpg", 0, 0);
ReleaseDC(pDC);
// TODO: add draw code for native data here
}
// CMyPictureView printing
BOOL CMyPictureView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyPictureView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyPictureView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CMyPictureView diagnostics
#ifdef _DEBUG
void CMyPictureView::AssertValid() const
{
CView::AssertValid();
}
void CMyPictureView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyPictureDoc* CMyPictureView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyPictureDoc)));
return (CMyPictureDoc*)m_pDocument;
}
#endif //_DEBUG
// CMyPictureView message handlers
bool CMyPictureView::ShowJpg(CDC* pDC, CString strPath, int x, int y)
{
IStream *pStm = NULL;
CFileStatus fstatus;
CFile file;
LONG cb = 0;
if (file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&&((cb-fstatus.m_size)!=-1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
pvData = GlobalLock(hGlobal);
if (pvData != NULL)
{
file.Read(pvData,cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal,TRUE,&pStm);
}
}
}
else
{
return false;
}
IPicture *pPic;
if (SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC jpgWidth;
OLE_XSIZE_HIMETRIC jpgHeight;
pPic->get_Width(&jpgWidth);
pPic->get_Height(&jpgHeight);
double fX,fY;
fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)jpgWidth/((double)pDC->GetDeviceCaps(HORZRES)*100.0);
fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)jpgHeight/((double)pDC->GetDeviceCaps(VERTRES)*100.0);
CRect rect;
GetClientRect(&rect);
if (fX < rect.Width()&&fY < rect.Height())
{
pPic->Render(*pDC,0,0,(DWORD)fX,(DWORD)fY,0,jpgHeight,jpgWidth,-jpgHeight,NULL);
}
else
{
pPic->Render(*pDC,x,y,rect.Width(),rect.Height(),0,jpgHeight,jpgWidth,-jpgHeight,NULL);
}
}
return true;
}