可否用ExtractAssociatedIcon()读取
并且该函数的第二个常数不能转换cstring
我该怎么办

解决方案 »

  1.   

    The ExtractIcon function retrieves a handle to an icon from the specified executable file, dynamic-link library (DLL), or icon file. To retrieve an array of handles to large or small icons, use the ExtractIconEx function. HICON ExtractIcon(
      HINSTANCE hInst,          // instance handle
      LPCTSTR lpszExeFileName,  // filename of file with icon
      UINT nIconIndex           // index of icon to extract
    );
      

  2.   

    如果我要从exe中读出icon  Extracticon也行????
      

  3.   

    为什么ExtractAssociatedIcon()的第二个参数为什么不能用cstring 
    LPCTSTR 和LPTSTR 区别在哪
      

  4.   

    我该怎样把CString该为LPTSTR呢
    我急啊
    或者给个ExtractAssociatedIcon()例子
      

  5.   

    http://www.vchelp.net/vchelp/zsrc/cicon.asp?type_id=74&class_id=1&cata_id=11&article_id=139&search_term=http://soft.shangdu.com/cywl/new/2003-4-2/20034295455.htmhttp://www.pconline.com.cn/pcedu/empolder/gj/vc/10206/67799.html
      

  6.   

    抄了一段代码
    CFileDialog fileDialog( TRUE,"*.ICO",NULL,NULL,"资源文件(*.ICO,*.BMP,*.EXE,*.DLL,*.ICL)|*.ICO;*.BMP;*.EXE;*.DLL;*.ICL||");
    if (fileDialog.DoModal() == IDOK) 
    {
    szOpenFileName=fileDialog.GetPathName();
            szOpenFileExtName= fileDialog.GetFileExt ();
    szOpenFileExtName.MakeLower (); m_List.ResetContent (); //选清空左侧图标列表框 //读取并显示ICON文件
            if(szOpenFileExtName =="ico") 
    {
    lpIR=pIcons->ReadIconFromICOFile (szOpenFileName);
    HICON hIcon;
    hIcon=ExtractIcon(AfxGetInstanceHandle(),szOpenFileName,0);
                if(hIcon!=NULL)
    m_List.AddString (szOpenFileName);
    CStatic* pStatic = (CStatic*) GetDlgItem(IDC_ICONS);
            pStatic->SetIcon (hIcon);
    }
    else if(szOpenFileExtName == "bmp") //读取并显示BMP文件
    {
                pIcons->IconImageFromBMPFile (szOpenFileName,&lpIR->IconImages[0],TRUE);
    HICON hIcon;
    hIcon=pIcons->MakeIconFromResource (&lpIR->IconImages [0]);
    if(hIcon!=NULL) 
    m_List.AddString (szOpenFileName);
                CStatic* pStatic = (CStatic*) GetDlgItem(IDC_ICONS);
            pStatic->SetIcon (hIcon);
    }
            else //读取并显示EXE、DLL等资源文件
    {
       HINSTANCE  hLibrary;    // Load the DLL/EXE - NOTE: must be a 32bit EXE/DLL for this to work
       if( (hLibrary = LoadLibraryEx( szOpenFileName, NULL, LOAD_LIBRARY_AS_DATAFILE )) == NULL )
       {
      // Failed to load - abort
    MessageBox( szOpenFileName+ "文件载入错误,必须是WIN32的文件!", "错误", MB_OK );
    return;
       }
         // Store the info
       EDII.szFileName =szOpenFileName;
       EDII.hInstance = hLibrary;
        
       // Fill in the listbox with the icons available
       if( ! EnumResourceNames( EDII.hInstance, RT_GROUP_ICON, (ENUMRESNAMEPROC )MyEnumProcedure, (LPARAM)GetSafeHwnd()) )
       {
    MessageBox( "列举图标资源名时出错!", "错误", MB_OK );
    return;
       }
    } m_List.SetCurSel (0);
    if( m_List.GetCount()  == 0 )
    {
    MessageBox( "此文件中没有图标资源!", "错误", MB_OK );
    //无图标资源,置保存和复制按钮为无效状态
    m_Copy.EnableWindow (false);
    m_SaveAs.EnableWindow (false);
    return;
    }
            //有图标资源,置保存和复制按钮为有效状态
    m_Copy.EnableWindow (true);
    m_SaveAs.EnableWindow (true); //刷新调用OnPaint来显示图标
    InvalidateRect(NULL,TRUE);
    } 如何将提取出的图标资源保存为Ico或Bmp格式。
    //保存图标资源为ICO或BMP格式文件 
     
     
    void CIconSnapDlg::OnButtonSaveas() 
    {
    LPTSTR lpIconID;   CFileDialog fileDialog( FALSE,"*.ICO",NULL,NULL,"图标文件(*.ICO)|*.ICO|位图文件(*.BMP)|*.BMP||");
    if (fileDialog.DoModal() == IDOK) 
    {
    szSaveFileName=fileDialog.GetPathName();
            szSaveFileExtName= fileDialog.GetFileExt ();
    szSaveFileExtName.MakeLower (); if(szOpenFileExtName=="exe"||szOpenFileExtName=="dll"||szOpenFileExtName=="icl")
                if((lpIconID=(LPTSTR)m_List.GetItemData (m_List.GetCurSel()))!= (LPTSTR)LB_ERR)
         lpIR=pIcons->ReadIconFromEXEFile (szOpenFileName,lpIconID);
             if(szSaveFileExtName=="bmp")
    {
      if(lpIR!=NULL && m_List.GetCount ()>0)
      {
    BeginWaitCursor();
    pIcons->IconImageToBMPFile (szSaveFileName,&lpIR->IconImages [0]);
    EndWaitCursor();
      }
      else
                 MessageBox( "没有可保存的图标资源!", "错误", MB_OK );
    }
    else if(szSaveFileExtName=="ico")
    {
              if(lpIR!=NULL && m_List.GetCount ()>0)
      {
    BeginWaitCursor();
    pIcons->WriteIconToICOFile (lpIR,szSaveFileName);
    EndWaitCursor();
      }
      else
             MessageBox( "没有可保存的图标资源!", "错误", MB_OK );
    }
    }
    }