Search results for 'SHGetPathFromIDList'. 3 post(s) found.
- 2007/09/19 Create new program group in the Start menu
- 2007/09/18 How to get get IE favorites
- 2007/09/10 Browse for Computers, Folders, Files and Printers
Here's how to create a new program group inside the Start-Programs menu:
uses ShlObj;
...
function CreateFolder(Foldername: string; aLocation: integer) : boolean;
var pIdl: PItemIDList;
hPath: PChar;
begin
Result := False;
if SUCCEEDED(SHGetSpecialFolderLocation(0, aLocation, pidl)) then
begin
hPath := StrAlloc(max_path) ;
SHGetPathFromIDList(pIdl, hPath) ;
SetLastError(0) ;
CreateDirectory(PChar(hPath + '\\' + Foldername), nil) ;
if (GetLastError() = 0) or(GetLastError() = ERROR_ALREADY_EXISTS) then
Result := true;
StrDispose(hPath) ;
end;
end;
{ Usage: }
procedure TForm1.Button1Click(Sender: TObject) ;
begin
{constants like 'CSIDL_PROGRAMS'
are defined in the ShlObj unit}
CreateFolder('MyProgramgroup', CSIDL_PROGRAMS) ;
end;
...
function CreateFolder(Foldername: string; aLocation: integer) : boolean;
var pIdl: PItemIDList;
hPath: PChar;
begin
Result := False;
if SUCCEEDED(SHGetSpecialFolderLocation(0, aLocation, pidl)) then
begin
hPath := StrAlloc(max_path) ;
SHGetPathFromIDList(pIdl, hPath) ;
SetLastError(0) ;
CreateDirectory(PChar(hPath + '\\' + Foldername), nil) ;
if (GetLastError() = 0) or(GetLastError() = ERROR_ALREADY_EXISTS) then
Result := true;
StrDispose(hPath) ;
end;
end;
{ Usage: }
procedure TForm1.Button1Click(Sender: TObject) ;
begin
{constants like 'CSIDL_PROGRAMS'
are defined in the ShlObj unit}
CreateFolder('MyProgramgroup', CSIDL_PROGRAMS) ;
end;
Another posts included in "Delphi"
| Detecting and preventing Windows shut down (0) | 2007/09/19 |
| Detecting Drive Types (0) | 2007/09/19 |
| Disable Mouse and Keyboard from Delphi Code (0) | 2007/09/19 |
| Copying Group of Files using Delphi with Standard Animation Dialog (SHF... (0) | 2007/09/19 |
| Controling sound volume from code (0) | 2007/09/19 |
| How to Close Another Application by Windows Caption (0) | 2007/09/19 |
| How to Change the Windows Start button bitmap (0) | 2007/09/19 |
| How to capture the output from a DOS (command/console) Window (0) | 2007/09/19 |
Trackback : Cannot send a trackbact to this post.
-
Subject Beast of burdon b.o.b. bike trailers.
2009/03/31 19:01
Zoo sex pictures animal porn movies beast trailers.
-
Subject different money making ideas
2010/01/29 03:11
moneyideas
-
Subject different money making ideas
2010/01/29 12:08
moneyideas
-
Subject different money making ideas
2010/01/31 16:40
moneyideas
The GetIEFavourites function called from the OnClick event of a button returns a list of all the favorites from your Internet Explorer in a ListBox.
function GetIEFavourites
(const favpath: string):TStrings;
var
searchrec:TSearchrec;
str:TStrings;
path,dir,filename:String;
Buffer: array[0..2047] of Char;
found:Integer;
begin
str:=TStringList.Create;
try
path:=FavPath+'\*.url';
dir:=ExtractFilePath(path) ;
found:=FindFirst(path,faAnyFile,searchrec) ;
while found=0 do begin
SetString(filename, Buffer,
GetPrivateProfileString('InternetShortcut',
PChar('URL'), NIL, Buffer, SizeOf(Buffer),
PChar(dir+searchrec.Name))) ;
str.Add(filename) ;
found:=FindNext(searchrec) ;
end;
found:=FindFirst(dir+'\*.*',faAnyFile,searchrec) ;
while found=0 do begin
if ((searchrec.Attr and faDirectory) > 0)
and (searchrec.Name[1]<>'.') then
str.AddStrings(GetIEFavourites
(dir+'\'+searchrec.name)) ;
found:=FindNext(searchrec) ;
end;
FindClose(searchrec) ;
finally
Result:=str;
end;
end;
procedure TForm1.Button1Click(Sender: TObject) ;
var pidl: PItemIDList;
FavPath: array[0..MAX_PATH] of char;
begin
SHGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl) ;
SHGetPathFromIDList(pidl, favpath) ;
ListBox1.Items:=GetIEFavourites(StrPas(FavPath)) ;
end;
(const favpath: string):TStrings;
var
searchrec:TSearchrec;
str:TStrings;
path,dir,filename:String;
Buffer: array[0..2047] of Char;
found:Integer;
begin
str:=TStringList.Create;
try
path:=FavPath+'\*.url';
dir:=ExtractFilePath(path) ;
found:=FindFirst(path,faAnyFile,searchrec) ;
while found=0 do begin
SetString(filename, Buffer,
GetPrivateProfileString('InternetShortcut',
PChar('URL'), NIL, Buffer, SizeOf(Buffer),
PChar(dir+searchrec.Name))) ;
str.Add(filename) ;
found:=FindNext(searchrec) ;
end;
found:=FindFirst(dir+'\*.*',faAnyFile,searchrec) ;
while found=0 do begin
if ((searchrec.Attr and faDirectory) > 0)
and (searchrec.Name[1]<>'.') then
str.AddStrings(GetIEFavourites
(dir+'\'+searchrec.name)) ;
found:=FindNext(searchrec) ;
end;
FindClose(searchrec) ;
finally
Result:=str;
end;
end;
procedure TForm1.Button1Click(Sender: TObject) ;
var pidl: PItemIDList;
FavPath: array[0..MAX_PATH] of char;
begin
SHGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl) ;
SHGetPathFromIDList(pidl, favpath) ;
ListBox1.Items:=GetIEFavourites(StrPas(FavPath)) ;
end;
Another posts included in "Delphi"
| How to set the "home page" for the Internet Explorer from Delphi code (0) | 2007/09/18 |
| List All Network Drives (0) | 2007/09/18 |
| Retrieving all image links from an HTML document (0) | 2007/09/18 |
| Extracting the domain (host) name from an e-mail address (0) | 2007/09/18 |
| Download a file from the Internet with progress indicator (0) | 2007/09/18 |
| Are we connected to the Internet? (0) | 2007/09/18 |
| Rotate Bitmap (any angle, any center of rotation) (0) | 2007/09/11 |
| TImage.Bitmap fade out (0) | 2007/09/11 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 06:03
moneyideas
-
Subject different money making ideas
2010/01/29 14:35
moneyideas
-
Subject different money making ideas
2010/01/31 16:40
moneyideas
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