【框架-MFC】保存HICON或HCURSOR对象到*.ico文件
2016-11-23 11:11
405 查看
void CMyDlg::SaveIcon(HICON hIconToSave, LPCTSTR sIconFileName) { if(hIconToSave==NULL || sIconFileName==NULL) return; //warning: this code snippet is not bullet proof. //do error check by yourself [masterz] 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); pChar pathbuf[1024]; pCharCpy(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(); }
相关文章推荐
- 【框架-MFC】动态创建HICON或HCURSOR对象
- 【框架-MFC】保存HBITMAP对象到*.bmp文件
- 用MFC建立COM服务器对象的框架步骤
- VC 2010 + MFC:自定义文档视图框架,去除新建、保存、打开等菜单功能,让文档程序个性化
- VS2013/MFC编程入门之三十七(文档、视图和框架:各对象之间的关系)
- 用MFC建立COM服务器对象的框架步骤
- 【框架-MFC】关于CFileDialog保存文件获取扩展名(后缀名)
- 用MFC建立COM服务器对象的框架步骤
- MFC应用程序之视图、文档、框架、应用程序类对象间的相互引用及调用
- VS2010/MFC编程入门之四十(文档、视图和框架:各对象之间的关系)
- VS2010/MFC编程入门之四十(文档、视图和框架:各对象之间的关系)
- .Net CSLA框架 验证规则问题 “对象含无效值,因此不能保存”
- VC/MFC怎样将位图CBitmap对象保存成为bmp格式文件? from http://coding1688.iteye.com/blog/1547035
- VC/MFC怎样将位图CBitmap对象保存成为bmp格式文件?(你在网上找的不一定灵,看我的一定灵)
- (转载)VS2010/MFC编程入门之四十(文档、视图和框架:各对象之间的关系)
- VS2010/MFC编程入门之四十(文档、视图和框架:各对象之间的关系)
- 利用MFC Document/View框架完成图形显示和保存功能
- VS2010/MFC编程入门之四十(文档、视图和框架:各对象之间的关系)
- MFC加载HCURSOR/HICON/HBITMAP
- 用MFC建立COM服务器对象的框架步骤