| 发表于:2007-06-16 16:47:301楼 得分:65 |
在ondraw 函数中调用如下代码: ::coinitialize(null); // com 初始化 hresult hr; cfile file; file.open( text( "c:\\1.jpg "), cfile::moderead ¦ cfile::sharedenynone ); // 读入文件内容 dword dwsize = file.getlength(); hglobal hmem = ::globalalloc( gmem_moveable, dwsize ); lpvoid lpbuf = ::globallock( hmem ); file.read( lpbuf, dwsize ); file.close(); ::globalunlock( hmem ); istream * pstream = null; ipicture * ppicture = null; // 由 hglobal 得到 istream,参数 true 表示释放 istream 的同时,释放内存 hr = ::createstreamonhglobal( hmem, true, &pstream ); assert ( succeeded(hr) ); hr = ::oleloadpicture( pstream, dwsize, true, iid_ipicture, ( lpvoid * )&ppicture ); assert(hr==s_ok); long nwidth,nheight; // 宽高,mm_himetric 模式,单位是0.01毫米 ppicture-> get_width( &nwidth ); // 宽 ppicture-> get_height( &nheight ); // 高 ////////原大显示////// //csize sz( nwidth, nheight ); //pdc-> himetrictodp( &sz ); // 转换 mm_himetric 模式单位为 mm_text 像素单位 //ppicture-> render(pdc-> m_hdc,0,0,sz.cx,sz.cy, // 0,nheight,nwidth,-nheight,null); ////////按窗口尺寸显示//////// crect rect; getclientrect(&rect); ppicture-> render(pdc-> m_hdc,0,0,rect.width(),rect.height(), 0,nheight,nwidth,-nheight,null); if ( ppicture ) ppicture-> release();// 释放 ipicture 指针 if ( pstream ) pstream-> release(); // 释放 istream 指针,同时释放了 hmem ::couninitialize(); | | |
|