|
From: Landon on 21 May 2008 05:36 I use Visual C++ 4.2. I am developing an application which will collect all shortcuts file name ONLY without the extension into a text file. So if the path is : C:\Windows\ABC.lnk the the application will only take ABC. There is an exception of: VALID shortcut files which going to be collected are ALL shortcut files(*.lnk) to an application(*.exe) ONLY, NOT shortcut files to FOLDERS / other files. I have successful in collecting all *.lnk files thus creating the text file which contain the shortcuts names but they also include shortcut to FOLDER and other files, I haven't filter it for EXE only. How to prevent non-EXE shortcuts from being read? I have tried: http://msdn.microsoft.com/en-us/library/bb776891.aspx but when it comes to the point of I call the ResolveIt function on my code below (inside the AddShortcutsList function), the sequence jumps out of it and did not process into the function. When I call the ResolveIt function I wrote XXXXX on the THIRD argument because I don't know what I should pass as the THIRD argument. Can you please help me solving this problem? Thank you very much. Here is my code to get them and then creating the text file containing the shortcuts file name: void CUsrcpDlg::AddShortcutsList( CStringList& List, LPCTSTR lpszBasePath, LPCTSTR lpszPath, LPCTSTR lpszFileName ) { CString strWildCardPathName = lpszBasePath; CString strBasePath = lpszBasePath; if( lpszPath != NULL && lstrlen( lpszPath ) > 0 ) { strWildCardPathName += "\\"; strWildCardPathName += lpszPath; } strWildCardPathName += "\\"; strWildCardPathName += lpszFileName; WIN32_FIND_DATA FindData; HANDLE hFile = ::FindFirstFile( strWildCardPathName, &FindData ); if( hFile == INVALID_HANDLE_VALUE ) return; CString strFileName; HRESULT hres = ResolveIt( m_hWnd, strFileName, XXXXX,MAX_PATH ); if ( SUCCEEDED( hres ) ) AfxMessageBox( m_cShortcutsFilePath ); do { strFileName = FindData.cFileName; if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { if( strFileName == _T( "." ) || strFileName == _T( ".." ) ) continue; if( lpszPath != NULL && lstrlen( lpszPath ) > 0 ) { strFileName = "\\" + strFileName; strFileName = lpszPath + strFileName; } AddShortcutsList( List, lpszBasePath, strFileName, "*.lnk" ); } else { if( lpszPath != NULL && lstrlen( lpszPath ) > 0 ) { strFileName = "\\" + strFileName; strFileName = lpszPath + strFileName; } List.AddTail( strFileName ); } } while( ::FindNextFile( hFile, &FindData ) ); ::FindClose( hFile ); } BOOL CUsrcpDlg::WriteShortcutsFile() { CString sShortcutsFileName; sShortcutsFileName.Format( "%sShortcuts.txt", m_cComputerNamePath ); CStdioFile cFile; if( !cFile.Open( sShortcutsFileName, CFile::modeCreate | CFile::modeWrite, NULL ) ) return FALSE; CStringList ShortcutsList; AddShortcutsList( ShortcutsList, m_cShortcutsPath, "", "*.lnk" ); POSITION pos = ShortcutsList.GetHeadPosition(); while( pos != NULL ) { CString sFile = ShortcutsList.GetNext( pos ); CString sTemp = sFile.Left( sFile.GetLength() - 4 ); cFile.WriteString( sTemp + "\n" ); } cFile.Close(); return TRUE; }
From: Victor on 21 May 2008 08:03 Have a look at the IShellLink interface and its IShellLink::GetPath method in MSDN. Victor "Landon" wrote: > I use Visual C++ 4.2. > > I am developing an application which will collect all shortcuts file name > ONLY without the extension into a text file. > > So if the path is : > C:\Windows\ABC.lnk the the application will only take ABC. > > There is an exception of: > VALID shortcut files which going to be collected > are ALL shortcut files(*.lnk) to an application(*.exe) ONLY, NOT shortcut > files to FOLDERS / other files. > > I have successful in collecting all *.lnk files thus creating the text file > which contain > the shortcuts names but they also include shortcut to FOLDER and other > files, I haven't > filter it for EXE only. > > How to prevent non-EXE shortcuts from being read? > > I have tried: > http://msdn.microsoft.com/en-us/library/bb776891.aspx > but when it comes to the point of I call the ResolveIt function on my code > below (inside the AddShortcutsList function), > the sequence jumps out of it and did not process into the function. > > When I call the ResolveIt function I wrote XXXXX on the THIRD argument > because I don't know what I should pass as the THIRD argument. > > Can you please help me solving this problem? > > Thank you very much. > > Here is my code to get them and then creating the text file containing the > shortcuts file name: > > void CUsrcpDlg::AddShortcutsList( CStringList& List, LPCTSTR lpszBasePath, > LPCTSTR lpszPath, LPCTSTR lpszFileName ) > { > CString strWildCardPathName = lpszBasePath; > CString strBasePath = lpszBasePath; > > if( lpszPath != NULL && lstrlen( lpszPath ) > 0 ) { > strWildCardPathName += "\\"; > strWildCardPathName += lpszPath; > } > strWildCardPathName += "\\"; > strWildCardPathName += lpszFileName; > > WIN32_FIND_DATA FindData; > HANDLE hFile = ::FindFirstFile( strWildCardPathName, &FindData ); > > if( hFile == INVALID_HANDLE_VALUE ) return; > > CString strFileName; > > HRESULT hres = ResolveIt( m_hWnd, strFileName, XXXXX,MAX_PATH ); > if ( SUCCEEDED( hres ) ) > AfxMessageBox( m_cShortcutsFilePath ); > > do { > strFileName = FindData.cFileName; > > if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { > if( strFileName == _T( "." ) || strFileName == _T( ".." ) ) continue; > > if( lpszPath != NULL && lstrlen( lpszPath ) > 0 ) { > strFileName = "\\" + strFileName; > strFileName = lpszPath + strFileName; > } > AddShortcutsList( List, lpszBasePath, strFileName, "*.lnk" ); > } > else > { > if( lpszPath != NULL && lstrlen( lpszPath ) > 0 ) { > strFileName = "\\" + strFileName; > strFileName = lpszPath + strFileName; > } > List.AddTail( strFileName ); > } > } while( ::FindNextFile( hFile, &FindData ) ); > > ::FindClose( hFile ); > } > > > BOOL CUsrcpDlg::WriteShortcutsFile() > { > CString sShortcutsFileName; > sShortcutsFileName.Format( "%sShortcuts.txt", m_cComputerNamePath ); > > CStdioFile cFile; > if( !cFile.Open( sShortcutsFileName, CFile::modeCreate | CFile::modeWrite, > NULL ) ) > return FALSE; > > CStringList ShortcutsList; > AddShortcutsList( ShortcutsList, m_cShortcutsPath, "", "*.lnk" ); > POSITION pos = ShortcutsList.GetHeadPosition(); > while( pos != NULL ) { > CString sFile = ShortcutsList.GetNext( pos ); > CString sTemp = sFile.Left( sFile.GetLength() - 4 ); > cFile.WriteString( sTemp + "\n" ); > } > > cFile.Close(); > > return TRUE; > } >
|
Pages: 1 Prev: How to create the chm help file like MSDN? Next: OnCancelMode |