void FileProperties::Load() { if(!loaded) { loaded=true; smallIcon=GetFileIcon(fullPath, SHGFI_SMALLICON | SHGFI_ICON); bigIcon=GetFileIcon(fullPath, SHGFI_LARGEICON | SHGFI_ICON); displayName=GetFileDisplayName(fullPath); typeName=GetFileTypeName(fullPath); lastWriteTime=GetFileLastWriteTime(fullPath); size=GetFileSize(fullPath); } }
void CDlgFiles::RefreshRemoteFolder( CHotlineFolder* pFolder ) { if ( m_pCurrentRemote && ( pFolder != m_pCurrentRemote ) ) return; m_pCurrentRemote = pFolder; m_RemoteList.DeleteAllItems( ); CHotlineFileBase* pFile; int iIndex; CString sTemp; for ( int iItem = 0; iItem < pFolder->GetChildCount( ); iItem++ ) { pFile = pFolder->GetChild( iItem ); iIndex = m_RemoteList.InsertItem( iItem, pFile->GetItemName( ), GetFileIcon( pFile ) ); m_RemoteList.SetItemData( iIndex, ( DWORD )pFile ); if ( pFile->IsFolder( ) ) sTemp.Format( "[%d]", pFile->GetChildCount( ) ); else FileSize( sTemp, ( ( CHotlineFile* )pFile )->GetFileSize( ) ); // sTemp.Format( "(%d)", ( ( CHotlineFile* )pFile )->GetFileSize( ) ); m_RemoteList.SetItemText( iIndex, 1, sTemp ); } // Affichage du nom du répertoire UpdateData( ); GetRemotePathName( pFolder, m_sRemoteName ); UpdateData( FALSE ); // Restauration de la dernière position connue, si applicable int iLastPos; if ( m_Position.Lookup( m_pCurrentRemote, ( void*& )iLastPos ) ) m_RemoteList.EnsureVisible( iLastPos, FALSE ); }
// Fill all information about a directory or a file. FOREACH(WString, file, files) { Ptr<list::ListViewItem> item=new list::ListViewItem; WString fullPath=path+L"\\"+file; // Get large icon. item->largeImage=GetFileIcon(fullPath, SHGFI_LARGEICON | SHGFI_ICON); // Get small icon. item->smallImage=GetFileIcon(fullPath, SHGFI_SMALLICON | SHGFI_ICON); // Get display name item->text=GetFileDisplayName(fullPath); // Get type name item->subItems.Add(GetFileTypeName(fullPath)); // Get last write time item->subItems.Add(FileTimeToString(GetFileLastWriteTime(fullPath))); // Get file size item->subItems.Add(FileSizeToString(GetFileSize(fullPath))); listView->GetItems().Add(item); }
CSysImageList::CSysImageList() { SHFILEINFO ssfi; TCHAR windir[MAX_PATH] = { 0 }; GetWindowsDirectory(windir, _countof(windir)); // MAX_PATH ok. hSystemImageList = (HIMAGELIST)SHGetFileInfo(windir, 0, &ssfi, sizeof ssfi, SHGFI_SYSICONINDEX | SHGFI_SMALLICON); int cx, cy; ImageList_GetIconSize(hSystemImageList, &cx, &cy); auto emptyImageList = ImageList_Create(cx, cy, ILC_COLOR32 | ILC_MASK, ImageList_GetImageCount(hSystemImageList), 10); Attach(emptyImageList); m_dirIconIndex = GetFileIcon(L"Doesn't matter", FILE_ATTRIBUTE_DIRECTORY, 0); m_dirOpenIconIndex = GetFileIcon(L"Doesn't matter", FILE_ATTRIBUTE_DIRECTORY, SHGFI_OPENICON); m_defaultIconIndex = GetFileIcon(L"", FILE_ATTRIBUTE_NORMAL, 0); }
bool CPPageFormats::IsRegistered(CString ext) { BOOL bIsDefault = FALSE; CString strProgID = _T("SPlayer") + ext; CString FileIcon = GetFileIcon(ext); if ( m_pAAR == NULL) { // Default manager (requiered at least Vista) HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC , __uuidof(IApplicationAssociationRegistration), (void**)&m_pAAR); } if (m_pAAR) { // The Vista way HRESULT hr; hr = m_pAAR->QueryAppIsDefault(ext, AT_FILEEXTENSION, AL_EFFECTIVE, g_strRegisteredAppName, &bIsDefault); } else { // The 2000/XP way CRegKey key; TCHAR buff[256]; ULONG len = sizeof(buff); memset(buff, 0, len); if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, ext)) return false; if(ERROR_SUCCESS != key.QueryStringValue(NULL, buff, &len) && !CString(buff).Trim().IsEmpty()) return false; bIsDefault = (buff == strProgID); } if(!f_setContextFiles) { CRegKey key; TCHAR buff[MAX_PATH]; ULONG len = sizeof(buff); if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open"), KEY_READ)) { CString strCommand = ResStr(IDS_OPEN_WITH_MPC); if (ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len)) f_setContextFiles = (strCommand.CompareNoCase(CString(buff)) == 0); } } // Check if association is for this instance of MPC if (bIsDefault) { CRegKey key; TCHAR buff[MAX_PATH]; ULONG len = sizeof(buff); bIsDefault = FALSE; if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"), KEY_READ)) { CString strCommand = GetOpenCommand(); if (ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len)) bIsDefault = (strCommand.CompareNoCase(CString(buff)) == 0); } } if(bIsDefault){ // SetFileAssociation(ext, strProgID, TRUE); } return !!bIsDefault; }
bool CPPageFormats::RegisterExt(CString ext, bool fRegister, CString PerceivedType) { CRegKey key; bool bSetValue; CString strProgID = _T("SPlayer") + ext; CString strLabel = _T(""); if(ext == _T(".rar")){ return true; } if(fRegister){ //为保证成功注册清理垃圾 //AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT, ext); AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT, _T("KMPlayer") + ext); AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT, _T("QQPlayer") + ext); AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT, _T("stormplayer") + ext); AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT, _T("RealPlayer") + ext+L".6"); AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT, _T("RealPlayer") + ext+L".10"); AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT, _T("Xmp") + ext); } CString path, fn, cmd; if(!MakeRegParams(ext, path, fn, strLabel, cmd)) return(false); strLabel = GetFileTypeName(ext); if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, ext)) return(false); if (!PerceivedType.IsEmpty()) { key.SetStringValue (L"PerceivedType", PerceivedType); } BOOL bIsRAR = (ext.Right(3).MakeLower() == _T("rar")); if (bIsRAR) return true; if(!fRegister && !bIsRAR) { if(fRegister != IsRegistered(ext)) SetFileAssociation (ext, strProgID, fRegister); key.Attach(HKEY_CLASSES_ROOT); key.RecurseDeleteKey(strProgID); return(true); } bSetValue = fRegister || (ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"), KEY_READ)); // Create ProgID for this file type if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)) return(false); if(ERROR_SUCCESS != key.SetStringValue(NULL, strLabel)) return(false); // Add to playlist option if(f_setContextFiles || bIsRAR) { if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue"))) return(false); if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_ADD_TO_PLAYLIST))) return(false); if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue\\command"))) return(false); if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetEnqueueCommand()))) return(false); } else { key.Attach(HKEY_CLASSES_ROOT); key.RecurseDeleteKey(strProgID + _T("\\shell\\enqueue")); } // Play option if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open"))) return(false); if(f_setContextFiles || bIsRAR) { if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC))) return(false); } else { if(ERROR_SUCCESS != key.SetStringValue(NULL, _T(""))) return(false); } if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"))) return(false); if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetOpenCommand()))) return(false); // Play option if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\openewnd"))) return(false); if(f_setContextFiles || bIsRAR) { if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC_IN_NEW_WND))) return(false); } else { if(ERROR_SUCCESS != key.SetStringValue(NULL, _T(""))) return(false); } if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\openewnd\\command"))) return(false); if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetOpenCommand(true)))) return(false); if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, g_strRegisteredKey + _T("\\FileAssociations"))) return(false); if(ERROR_SUCCESS != key.SetStringValue(ext, strProgID)) return(false); if(f_setAssociatedWithIcon && !bIsRAR) { CString AppIcon = GetFileIcon(ext); TCHAR buff[MAX_PATH]; if((AppIcon.IsEmpty()) && (::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH))) { AppIcon = buff; AppIcon = "\""+AppIcon+"\""; AppIcon += _T(",0"); } if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))) return(false); if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, AppIcon))) return(false); } else { key.Attach(HKEY_CLASSES_ROOT); key.RecurseDeleteKey(strProgID + _T("\\DefaultIcon")); } if (fRegister && !bIsRAR) SetFileAssociation(ext, strProgID, fRegister); return(true); }
BOOL CPPageFormats::SetFileAssociation(CString strExt, CString strProgID, bool fRegister) { CString extoldreg, extOldIcon; CRegKey key; HRESULT hr = S_OK; TCHAR buff[MAX_PATH]; ULONG len = sizeof(buff); memset(buff, 0, len); if (m_pAAR == NULL) { // Default manager (requiered at least Vista) HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), (void**)&m_pAAR); if (FAILED(hr)) { m_pAAR = NULL; } } CString FileIcon = GetFileIcon(strExt); if (m_pAAR) { // Register MPC for the windows "Default application" manager if(ERROR_SUCCESS == key.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\RegisteredApplications"))) { key.SetStringValue(g_strRegisteredAppName/*_T("Media Player Classic")*/, g_strRegisteredKey); if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, g_strRegisteredKey)) return(false); // ==>> TODO icon !!! key.SetStringValue(_T("ApplicationDescription"), ResStr(IDS_APP_DESCRIPTION), REG_EXPAND_SZ); //key.SetStringValue(_T("ApplicationIcon"), AppIcon, REG_EXPAND_SZ); key.SetStringValue(_T("ApplicationName"), g_strRegisteredAppName, REG_EXPAND_SZ); } // The Vista way CString strNewApp; if (fRegister) { // Create non existing file type if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strExt)) return(false); WCHAR* pszCurrentAssociation; // Save current application associated if (SUCCEEDED (m_pAAR->QueryCurrentDefault (strExt, AT_FILEEXTENSION, AL_EFFECTIVE, &pszCurrentAssociation))) { if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)) return(false); key.SetStringValue( NULL , pszCurrentAssociation); // //key.SetStringValue(g_strOldAssoc, pszCurrentAssociation); // Get current icon for file type if (ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, CString(pszCurrentAssociation) + _T("\\DefaultIcon"))) { if(ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && !FileIcon.Trim().IsEmpty()) { } } if (!FileIcon.IsEmpty() && ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))) key.SetStringValue (NULL, FileIcon); CoTaskMemFree (pszCurrentAssociation); } strNewApp = g_strRegisteredAppName; } else { if(ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, strProgID)) return(false); if(ERROR_SUCCESS == key.QueryStringValue(g_strOldAssoc, buff, &len)) strNewApp = buff; // TODO : retrieve registered app name from previous association (or find Bill function for that...) } hr = m_pAAR->SetAppAsDefault(strNewApp, strExt, AT_FILEEXTENSION); if(hr != S_OK){ return false; } } else { // The 2000/XP way if (fRegister) { // Set new association if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strExt)) return(false); len = sizeof(buff); memset(buff, 0, len); if(ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && !CString(buff).Trim().IsEmpty()) extoldreg = buff; if(ERROR_SUCCESS != key.SetStringValue(NULL, strProgID)) return(false); // Get current icon for file type /* if (!extoldreg.IsEmpty()) { if (ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, extoldreg + _T("\\DefaultIcon"))) { len = sizeof(buff); memset(buff, 0, len); if(ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && !CString(buff).Trim().IsEmpty()) extOldIcon = buff; } } */ // Save old association if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)) return(false); key.SetStringValue(g_strOldAssoc, extoldreg); if (!FileIcon.IsEmpty() && ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))) key.SetStringValue (NULL, FileIcon); /* if (ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))) { key.SetStringValue(NULL, FileIcon); } */ /* if (!extOldIcon.IsEmpty() && (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon")))) key.SetStringValue (NULL, extOldIcon); */ } else { // Get previous association len = sizeof(buff); memset(buff, 0, len); if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)) return(false); if(ERROR_SUCCESS == key.QueryStringValue(g_strOldAssoc, buff, &len) && !CString(buff).Trim().IsEmpty()) extoldreg = buff; // Set previous association if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strExt)) return(false); key.SetStringValue(NULL, extoldreg); } } return SUCCEEDED (hr); }
int CSysImageList::GetFileIconIndex(const CString& file) const { return GetFileIcon(file, FILE_ATTRIBUTE_NORMAL, 0); }
int CSysImageList::GetDefaultIconIndex() const { return GetFileIcon(_T(""), FILE_ATTRIBUTE_NORMAL, 0); }
int CSysImageList::GetDirOpenIconIndex() const { return GetFileIcon(_T("Doesn't matter"), FILE_ATTRIBUTE_DIRECTORY, SHGFI_OPENICON); }
int CSysImageList::GetDirIconIndex() const { return GetFileIcon(_T("Doesn't matter"), FILE_ATTRIBUTE_DIRECTORY, 0); }
BOOL CDeskTopDlg::OnInitDialog() { CDialog::OnInitDialog(); HWND hProgMan = ::FindWindow(L"ProgMan", NULL); if(hProgMan) { HWND hShellDefView = ::FindWindowEx(hProgMan, NULL, L"SHELLDLL_DefView", NULL); if(hShellDefView) m_hWndDesktop = ::FindWindowEx(hShellDefView, NULL, L"SysListView32", NULL); } ::SetParent(m_hWnd,m_hWndDesktop); MoveWindow(0,0,GetSystemMetrics ( SM_CXSCREEN ) ,GetSystemMetrics ( SM_CYSCREEN )); m_DeskIconManager.SetShowWnd(m_hWnd); CFileFind finder; CString strPath; BOOL bWorking = finder.FindFile(L"C:\\Users\\GaoZan\\Desktop\\*.*"); while(bWorking) { bWorking = finder.FindNextFile(); strPath = finder.GetFilePath(); OutputDebugStringW(strPath+L"\n"); if(finder.IsDirectory() && !finder.IsDots()) { int a=0; } else if(!finder.IsDirectory() && !finder.IsDots()) { CString strIconText; strIconText = finder.GetFileTitle(); CString strNotePadPath(strPath); SHFILEINFO stFileInfo; :: SHGetFileInfo( strNotePadPath,0,&stFileInfo,sizeof(stFileInfo),SHGFI_ICON); HICON hIcon = GetFileIcon(strPath); m_DeskIconManager.AddIcon(strIconText,/*stFileInfo.hIcon*/hIcon,strPath); } } bWorking = finder.FindFile(L"C:\\Users\\Public\\Desktop\\*.*"); while(bWorking) { bWorking = finder.FindNextFile(); strPath = finder.GetFilePath(); OutputDebugStringW(strPath+L"\n"); if(finder.IsDirectory() && !finder.IsDots()) { int a=0; } else if(!finder.IsDirectory() && !finder.IsDots()) { CString strIconText; strIconText = finder.GetFileTitle(); CString strNotePadPath(strPath); SHFILEINFO stFileInfo; :: SHGetFileInfo( strNotePadPath,0,&stFileInfo,sizeof(stFileInfo),SHGFI_ICON); HICON hIcon = GetFileIcon(strPath); m_DeskIconManager.AddIcon(strIconText,/*stFileInfo.hIcon*/hIcon,strPath); } } // for (int i=0;i<10;i++) // { // CString strIconText; // strIconText.Format(L"图标_%d",i); // // CString strNotePadPath("C:\\Users\\GaoZan\\Desktop\\ADSafe.lnk"); // SHFILEINFO stFileInfo; // :: SHGetFileInfo( strNotePadPath,0,&stFileInfo,sizeof(stFileInfo),SHGFI_ICON); // // m_DeskIconManager.AddIcon(strIconText,stFileInfo.hIcon); // } return TRUE; // 除非将焦点设置到控件,否则返回 TRUE }
Add(wxS("changed"), GetChangedIcon()); Add(wxS("class"), AstadeIcons::GetClassIcon()); Add(wxS("component"), GetComponentIcon()); Add(wxS("composition"), GetCompositionIcon()); Add(wxS("incomposition"), wxBitmap(GetCompositionIcon().ConvertToImage().Mirror(false))); Add(wxS("configuration"), GetConfigurationIcon()); Add(wxS("const"), GetConstIcon()); Add(wxS("constraint"), GetConstraintIcon()); Add(wxS("constructor"), GetConstructorIcon()); Add(wxS("containundocumented"), GetContainUndocumentedIcon()); Add(wxS("connection"), GetConnectionIcon()); Add(CODE_CPlusPlus, GetCppIcon()); Add(wxS("deprecated"), GetDeprecatedIcon()); Add(wxS("destructor"), GetDestructorIcon()); Add(wxS("doxygen"), GetDoxygenIcon()); Add(wxS("file"), GetFileIcon()); Add(wxS("folder"), GetFolderIcon()); Add(wxS("generalisation"), GetGeneralisationIcon()); Add(wxS("ingeneralisation"), wxBitmap(GetGeneralisationIcon().ConvertToImage().Mirror(false))); Add(wxS("h"), GetHIcon()); Add(wxS("if"), GetIfIcon()); Add(wxS("inline"), GetInlineIcon()); Add(wxS("internaltransition"), GetInternaltransitionIcon()); Add(wxS("isundocumented"), GetIsUndocumentedIcon()); Add(CODE_JAVA, GetJavaIcon()); Add(wxS("lib"), GetLibIcon()); Add(wxS("loading"), GetLoadingIcon()); Add(wxS("make"), GetMakeIcon()); Add(wxS("manual"), GetManualIcon()); Add(wxS("model"), GetModelIcon()); Add(wxS("namespace"), GetNamespaceIcon());