Search results for 'BrowseDialog'. 1 post(s) found.
By using the SHBrowseForFolder Windows API function and Delphi we can invoke a Windows system dialog used to browse for files and folders on users hard drive as well as network computers and printers.
First, let's look at what SHBrowseForFolder needs. Here's the function declaration:
We pass in a complicated record type BrowseInfo to initialize and customize the Browse For Folder dialog box. We get back an item ID list (let's say: location of the selected folder, not to confuse to much).
Now we'll see how to fill in a record structure with information that initializes the Browse for Folder dialog box, then call SHBrowseForFolder to display the dialog box.
BrowseInfo structure
Two of the main elements of BrowseInfo are the lpszTitle and ulFlags fields. The dialog box displays the contents of lpszTitle in a static text control above the treeview. The ulFlags element sets the value which determines what the dialog displays and allows the user to select.
We can specify zero or more of the flags in order to make the dialog box much more useful than just browsing for folders. Some of the flags that can be specified to enhance the Browse For Folders dialog box are:
| BIF_BROWSEFORCOMPUTER | Only returns computers. If the user selects anything other than a computer, the OK button is grayed. |
| BIF_BROWSEFORPRINTER | Only returns printers. If the user selects anything other than a printer, the OK button is grayed. |
| BIF_RETURNONLYFSDIRS | Only returns file system directories. If the user selects folders that aren't part of the file system, the OK button is grayed. |
| BIF_BROWSEINCLUDEFILES | The browse dialog will display files as well as folders |
Delphi code
When we put all this in a Delphi function that will create the structure, initialize it, and call SHBrowseForFolder() to display the dialog box, we get something like:
uses ShellAPI, ShlObj;
...
function BrowseDialog(const Title: string; const Flag: integer): string;
var
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
Result:='';
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
with BrowseInfo do begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(Title);
ulFlags := Flag;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
...
function BrowseDialog(const Title: string; const Flag: integer): string;
var
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
Result:='';
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
with BrowseInfo do begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(Title);
ulFlags := Flag;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
The BrowseDialog function takes two parameters: Title and Flag. Title represents the text that appears above the treeview (lpszTitle field of the BrowseInfo record). Flag parameter is used to fill the ulFlags field.
The function can now be simply called (to display the folder selected by the user) like:
procedure TfrMain.btnBrowseClick(Sender: TObject);
var sTitle, sFolder: string;
iFlag : integer;
begin
sTitle:='Choose a ' +
rgBrowseFor.Items[rgBrowseFor.ItemIndex];
case rgBrowseFor.ItemIndex of
0: iFlag := BIF_RETURNONLYFSDIRS;
1: iFlag := BIF_BROWSEINCLUDEFILES;
2: iFlag := BIF_BROWSEFORCOMPUTER;
3: iFlag := BIF_BROWSEFORPRINTER;
end;
sFolder := BrowseDialog(sTitle, iFlag);
if sFolder <> '' then
edSelected.text := sFolder
else
edSelected.text := 'Nothing selected';
end;
var sTitle, sFolder: string;
iFlag : integer;
begin
sTitle:='Choose a ' +
rgBrowseFor.Items[rgBrowseFor.ItemIndex];
case rgBrowseFor.ItemIndex of
0: iFlag := BIF_RETURNONLYFSDIRS;
1: iFlag := BIF_BROWSEINCLUDEFILES;
2: iFlag := BIF_BROWSEFORCOMPUTER;
3: iFlag := BIF_BROWSEFORPRINTER;
end;
sFolder := BrowseDialog(sTitle, iFlag);
if sFolder <> '' then
edSelected.text := sFolder
else
edSelected.text := 'Nothing selected';
end;
Another posts included in "Delphi"
| Checking If File Is In Use (0) | 2007/09/10 |
| Convert a mapped drive to a full UNC path (0) | 2007/09/10 |
| Does my CD-ROM drive contain an audio CD? (0) | 2007/09/10 |
| How to draw Transparent Text on bitmap (0) | 2007/09/01 |
| How Do I Remove The Application Icon From The Taskbar? (0) | 2007/08/25 |
| How To Show The Print Dialog And Print Text Files (0) | 2007/08/25 |
| How To Make An Animated Application Icon (0) | 2007/08/25 |
| How To Pass The Focus To The Next/prior Control (0) | 2007/08/25 |
Trackback : Cannot send a trackbact to this post.
-
Subject Meridia dosage.
2009/01/16 13:45
Meridia meridia best prices on the net. Meridia without prescriptions. Discount meridia.
-
Subject Viagra effects.
2009/03/07 11:09
Viagra. Buy viagra online. Viagra online. Cheap viagra. Viagra description. Viagra london. Viagra sale. Discount viagra.
-
Subject Buy percocet online.
2009/03/17 10:00
Compare brand name and generic percocet. Buy percocet online. Generic percocet. Percocet. Long term percocet withdrawal symptoms. Percocet dangers of abuse. How do i get off percocet.
-
Subject different money making ideas
2010/01/25 08:51
moneyideas
-
Subject different money making ideas
2010/01/28 22:10
moneyideas
-
Subject different money making ideas
2010/01/29 06:33
moneyideas
-
Subject different money making ideas
2010/01/31 16:38
moneyideas

Prev

Rss Feed