home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 February
/
Chip_2002-02_cd1.bin
/
sharewar
/
apaths
/
APSOURCE.ZIP
/
PickPath.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-03-26
|
3KB
|
95 lines
/* PickPath - March 26th, 2001
**
** Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
**
** This module displays a folder selection dialog and allows
** the user to select an exisiting folder from the list.
**
** Called: w = Window handle of the parent.
** msg = Message prompt string to be displayed.
** path = Buffer to contain selected folder path.
**
** Returns: TRUE upon success, or FALSE if an error exists.
** The "path" will contain the folder selected by the
** user when the [Open] button is selected.
**
** Notes: This routine uses the standard MS Windows 9x/NT
** Folder selection dialog box.
**
** If the "path" buffer passed as an arguement to
** this function contains a valid folder that
** directory will be selected and made the starting
** point for all subsequent path specifications.
*/
#include "AppPaths.h"
static int CALLBACK reflect (HWND w,UINT msg,WPARAM wp,LPARAM lp);
extern BOOL far PickPath (HWND w,LPCSTR msg,LPSTR path)
{
auto BROWSEINFO info = { NIL };
auto BOOL pick = FALSE;
auto LPMALLOC m;
auto LPSTR tmp;
auto LPITEMIDLIST root;
auto LPITEMIDLIST user;
if (SHGetMalloc (&m) == E_FAIL)
return (FALSE);
if ((tmp = (LPSTR) m->lpVtbl->Alloc (m,KSTRING)) == NULL)
return (FALSE);
SHGetSpecialFolderLocation (w,CSIDL_DESKTOP,&root);
info.hwndOwner = w;
info.pidlRoot = root;
info.pszDisplayName = tmp;
info.lpszTitle = (msg && *msg) ? msg : "Select a folder";
info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
info.lParam = (LPARAM) path;
info.lpfn = (BFFCALLBACK) reflect;
if ((user = SHBrowseForFolder (&info)) != NULL) {
SHGetPathFromIDList (user,tmp);
lstrcpy (path,tmp);
m->lpVtbl->Free (m,user);
pick = TRUE;
}
m->lpVtbl->Free (m,root);
m->lpVtbl->Free (m,tmp);
return (pick);
}
static int CALLBACK reflect (HWND w,UINT msg,WPARAM wp,LPARAM lp)
{
auto LPITEMIDLIST list;
auto char path[KSTRING];
switch (msg) {
case BFFM_INITIALIZED :
SendMessage (w,BFFM_SETSELECTION,TRUE,lp);
break;
case BFFM_SELCHANGED :
list = (LPITEMIDLIST) wp;
SHGetPathFromIDList (list,path);
SendMessage (w,BFFM_SETSTATUSTEXT,NIL,(LPARAM) path);
break;
}
return (FALSE);
}
/* end of PickPath.c - written by Gregory Braun */