Hi,
I am using visual studio 8 to create an application. I need to incorporate file browser window in a .cpp file. The code i have only browses the folders and sub folders but does not display the individual files. Can anyone help me with this..? Any help would be greatly appreciated. Thanks a lot.

my code is

void BrowseFolder( void )
{
    TCHAR path[MAX_PATH];
    BROWSEINFO bi = { 0 };
    bi.lpszTitle = (LPCWSTR)("All Folders Automatically Recursed.");
    LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );

    if ( pidl != 0 )
    {
        SHGetPathFromIDList ( pidl, (LPWSTR)path );
        SetCurrentDirectory ( (LPCWSTR)path );
        SearchFolder( path );
        IMalloc * imalloc = 0;
        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
        {
            imalloc->Free ( pidl );
            imalloc->Release ( );
        }
    }
}


void SearchFolder( TCHAR * path ) 
{         
    WIN32_FIND_DATA FindFileData; 
	HWND m_listbox_hwnd;
    HANDLE hFind;     
    TCHAR filename[ MAX_PATH + 256 ];     
    TCHAR pathbak[ MAX_PATH ];     
       
    strcpy( (char *)pathbak, (char *)path );
   
    hFind = FindFirstFile ( (LPCWSTR)"*.*", &FindFileData );
    do     
    {                
        if ( hFind != INVALID_HANDLE_VALUE )         
        {                         
            if ( ! ( strcmp( (char *)FindFileData.cFileName, "." ) ) || 
                ! ( strcmp( (char *)FindFileData.cFileName, ".." ) ) )             
            {                 
                continue;             
            }             
            strcpy( (char *)path, (char *)pathbak );          
            sprintf((char *) path, "%s\\%s", (char *)path, FindFileData.cFileName );            
            if ( ( SetCurrentDirectory( path ) ) )             
            {                 
                SearchFolder( path );             
            }
            SendMessage( m_listbox_hwnd, LB_ADDSTRING, 0, path );
        }     
    }    
    while ( FindNextFile ( hFind, &FindFileData ) 
        && hFind != INVALID_HANDLE_VALUE );     
    FindClose ( hFind );
}

hi,
Its working.. Thanks a lot.. :)

regards,
AM

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.