Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BROWSE FOR FOLDER 1

Status
Not open for further replies.

Robertus

Programmer
Feb 16, 2001
81
0
0
RO
Does anybody have some short source code wich displays the BROWSE for FOLDER Windows dialog ?
I'd apreciate your help

Thanks in advance!
 
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlobj.h>
#include <iostream>

BOOL GetDirectory( HWND hWnd,LPSTR lpzTitle,LPSTR lpzConfirm,
LPSTR lpzHoldDir,BOOL bConfirm );

int main()
{
char sHoldDir[_MAX_PATH];

std::cout << &quot;Choose a directory...&quot; <<
std::endl;

GetDirectory( NULL,&quot;Choose a folder...&quot;,
&quot;Is this the correct folder?&quot;,
sHoldDir,TRUE );

std::cout<< &quot;The directory in question: &quot;
<< sHoldDir <<
std::endl;

return 0;
}

BOOL GetDirectory( HWND hWnd,LPSTR lpzTitle,LPSTR lpzConfirm,
LPSTR lpzHoldDir,BOOL bConfirm )
{
LPITEMIDLIST pidl;
IMalloc *imalloc=0;
LPMALLOC pMalloc=0;
BROWSEINFO bi ={ 0 };

while( TRUE )
{

bi.hwndOwner =hWnd;
bi.lpszTitle =lpzTitle;
bi.pszDisplayName=lpzHoldDir;
pidl=SHBrowseForFolder( &bi );

if( pidl )
{

SHGetPathFromIDList( pidl,lpzHoldDir );
if( strcmp( lpzHoldDir,&quot;&quot; )==0 )
strcpy( lpzHoldDir,&quot;C:\\&quot; );


if( SUCCEEDED( SHGetMalloc( &imalloc ) ) )
{
imalloc->Free( pidl );
imalloc->Release();
}
if( bConfirm )
{
if( MessageBox( hWnd,lpzHoldDir,lpzConfirm,
MB_YESNO | MB_ICONQUESTION ) == IDYES )

return TRUE;
}
else
return TRUE;

}
else
{
strcpy( lpzHoldDir,&quot;<CANCEL>&quot; );
return FALSE;
}


}


} Mike L.G.
mlg400@linuxmail.org
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top