45fan.com - 路饭网

搜索: 您的位置主页 > 电脑频道 > 电脑教程 > 阅读资讯:在VC中通过图标句丙保存ico图标的方法

在VC中通过图标句丙保存ico图标的方法

2016-09-07 13:58:49 来源:www.45fan.com 【

在VC中通过图标句丙保存ico图标的方法

void CMyDlg::SaveIcon(HICON hIconToSave, LPCTSTR sIconFileName)
{
if(hIconToSave==NULL || sIconFileName==NULL)
return;
PICTDESC picdesc;
picdesc.cbSizeofstruct = sizeof(PICTDESC);
picdesc.picType = PICTYPE_ICON ;
picdesc.icon.hicon = hIconToSave;
IPicture* pPicture=NULL;
OleCreatePictureIndirect(&picdesc, IID_IPicture, TRUE,(VOID**)&pPicture);
LPSTREAM pStream;
CreateStreamOnHGlobal(NULL,TRUE,&pStream);
LONG size;
HRESULT hr=pPicture->SaveAsFile(pStream,TRUE,&size);
char pathbuf[1024];
strcpy(pathbuf,sIconFileName);
CFile iconfile;
iconfile.Open(pathbuf, CFile::modeCreate|CFile::modeWrite);
LARGE_INTEGER li;
li.HighPart =0;
li.LowPart =0;
ULARGE_INTEGER ulnewpos;
pStream->Seek( li,STREAM_SEEK_SET,&ulnewpos);
ULONG uReadCount = 1;
while(uReadCount>0)
{

pStream->Read(pathbuf,sizeof(pathbuf),&uReadCount);
if(uReadCount>0)
iconfile.Write(pathbuf,uReadCount);
}
pStream->Release();
iconfile.Close();
}

 

本文地址:http://www.45fan.com/dnjc/73682.html
Tags: 通过 保存 图标
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部