积累系统性知识
积聚技术精华
  首页    个人中心    撰写积文    建立课题    订立目标    整理积文    管理课题    管理目标    技能Get    代码积累 
在VC中保存图标
error997 (error997)    2014-11-20 20:31:14      目标    课题
   1.
切换到: 纯代码  
   
   BOOL WriteIconToICOFile(LPICONRESOURCE lpIR,LPCTSTR szFileName)   
{   
 HANDLE hFile;   
 UINT i;   
 DWORD dwBytesWritten;      
 //open the file   
 if((hFile=CreateFile(szFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))   ==   INVALID_HANDLE_VALUE   )   
 {   
  MessageBox(hWndMain,"Error Opening File for Writing",szFileName,MB_OK);   
  return FALSE;   
 }   
 //Write the header   
 if(!WriteICOHeader(hFile,lpIR->nNumImages))   
 {   
  MessageBox(hWndMain,"Error Writing ICO File",szFileName,MB_OK);   
  CloseHandle(hFile);   
  return FALSE;   
 }   
 //Write the ICONDIRENTRY's   
 for(i=0;i<lpIR->nNumImages;i++)   
 {   
  ICONDIRENTRY ide;     
  //Convert internal format to ICONDIRENTRY   
  ide.bWidth=lpIR->IconImages[i].Width;   
  ide.bHeight=lpIR->IconImages[i].Height;   
  ide.bReserved=0;   
  ide.wPlanes=lpIR->IconImages[i].lpbi->bmiHeader.biPlanes;   
  ide.wBitCount=lpIR->IconImages[i].lpbi->bmiHeader.biBitCount;   
  if((ide.wPlanes*ide.wBitCount)>=8)   
   ide.bColorCount=0;   
  else   
   ide.bColorCount=1<<(ide.wPlanes*ide.wBitCount);   
  ide.dwBytesInRes=lpIR->IconImages[i].dwNumBytes;   
  ide.dwImageOffset=CalculateImageOffset(lpIR,i);   
  //Write the ICONDIRENTRY out to disk   
  if(!WriteFile(hFile,&ide,sizeof(ICONDIRENTRY),&dwBytesWritten,NULL))   
   return FALSE;   
  //Did we write a full ICONDIRENTRY?   
  if(dwBytesWritten!=sizeof(ICONDIRENTRY))   
   return FALSE;   
 }   
 //Write the image bits for each image   
 for(i=0;i<lpIR->nNumImages;i++)   
 {   
  DWORD dwTemp=lpIR->IconImages[i].lpbi->bmiHeader.biSizeImage;   
  
  //Set the sizeimage member to zero
  lpIR->IconImages[i].lpbi->bmiHeader.biSizeImage=0;   
  //Write the image bits to file   
  if(!WriteFile(hFile,lpIR->IconImages[i].lpBits,lpIR->IconImages[i].dwNumBytes,&dwBytesWritten,NULL))   
   return FALSE;   
  if(dwBytesWritten!=lpIR->IconImages[i].dwNumBytes)   
   return FALSE;   
  //set it back   
  lpIR->IconImages[i].lpbi->bmiHeader.biSizeImage=dwTemp;   
 }   
 CloseHandle(hFile);   
 return FALSE;   
}

   2.

转自 http://blog.csdn.net/y___y/article/details/1325789
(+0)技能Get

建议楼主:搜索关键字 |参考其他资源 |回复 |追问
  error997(error997):   个人中心    课题    目标    代码积累