| 发表于:2007-03-26 16:37:073楼 得分:0 |
hresult showpic(tchar* lpstrfile, hwnd hwnd, int nscrwidth, int nscrheight) { hdc hdc_temp=getdc(hwnd); ipicture *ppic; istream *pstm; bool bresult; handle hfile = null; dword dwfilesize, dwbyteread; //打开硬盘中的图形文件 hfile=createfile(lpstrfile, generic_read, file_share_read, null, open_existing, file_attribute_normal, null); if (hfile != invalid_handle_value) { dwfilesize=getfilesize(hfile, null);//获取文件字节数 if (dwfilesize==0xffffffff) return e_fail; } else { return e_fail; } //分配全局存储空间 hglobal hglobal = globalalloc(gmem_moveable, dwfilesize); lpvoid pvdata = null; if (hglobal == null) return e_fail; if ((pvdata = globallock(hglobal)) == null)//锁定分配内存块 return e_fail; readfile(hfile, pvdata, dwfilesize, &dwbyteread, null);//把文件读入内存缓冲区 globalunlock(hglobal); createstreamonhglobal(hglobal, true, &pstm); //装入图形文件 bresult = oleloadpicture(pstm,dwfilesize,true,iid_ipicture,(lpvoid*)&ppic); if(failed(bresult)) return e_fail; ole_xsize_himetric hmwidth;//图片的真实宽度 ole_ysize_himetric hmheight;//图片的真实高度 ppic-> get_width(&hmwidth); ppic-> get_height(&hmheight); //将图形输出到屏幕上(有点像bitblt) bresult = ppic-> render(hdc_temp, 0, 0, nscrheight, nscrwidth, 0, hmheight, hmwidth, -hmheight, null); ppic-> release(); closehandle(hfile);//关闭打开的文件 if (succeeded(bresult)) { return s_ok; } else { return e_fail; } } 以上代码自己改吧,适合更多的图片格式 | | |
|