求各位大神指点一下小弟 为什么显示不了图片

Wolf_Bevis 2015-01-31 10:30:38
// 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;

}
...全文
113 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2015-03-14
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
worldy 2015-01-31
  • 打赏
  • 举报
回复
代码整体逻辑应该没有什么问题,单步运行看看在哪出错,仔细检查每个状态值

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧