Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use extended Windows dialogs Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
21-Jan-03
Category
Dialogs
Language
Delphi 2.x
Views
194
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Mike Shkolnik 

How to use extended Windows dialogs

Answer:

Today I want to show a few samples how you can use the extended dialogs from MS 
Windows (Find Files, Find Computer, Select Icon etc) in own code.

Usually the MessageDlg is most used from standard dialogs but inside of Windows 
you'll find a lot of other useful dialogs too.

The any such dialog is declared in the Shell32.dll library and you can use it so:

Select an Icon

this dialog is a same which you'll see when you'll edit an icon of any lnk-file 
(icon on desktop, for example)

Declaration:
1   
2   function PickIconDlgA(OwnerWnd: HWND; lpstrFile: PAnsiChar; var nMaxFile: LongInt; 
3   var
4     lpdwIconIndex: LongInt): LongBool; stdcall; external 'SHELL32.DLL' index 62;
5   
6   //Example (icon of current application will be changed!):
7   
8   procedure TForm1.Button4Click(Sender: TObject);
9   var
10    FileName: array[0..MAX_PATH - 1] of Char;
11    Size, Index: LongInt;
12  begin
13    Size := MAX_PATH;
14    FileName := 'c:\windows\system\shell32.dll';
15    if PickIconDlgA(0, FileName, Size, Index) then
16    begin
17      if (Index <> -1) then
18        Application.Icon.Handle := ExtractIcon(hInstance, FileName, Index);
19    end;
20  end;


Of course, you can define any other file and in the dialog you'll see available 
icons of this executable file.

Find Computer

Declaration:
21  
22  function SHFindComputer(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): 
23  Boolean;
24    stdcall; external 'Shell32.dll' index 91;
25  
26  //Example:
27  
28  begin
29    SHFindComputer(nil, nil);
30  end;


Find Files

Declaration:
31  
32  function SHFindFiles(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): Boolean;
33    stdcall; external 'Shell32.dll' index 90;
34  
35  //Example:
36  
37  begin
38    SHFindFiles(nil, nil);
39  end;


Here the first parameter is a folder where you want to begin a search (nil is a 
Desktop). The second parameter allow to define a previous saved state of search 
process.

IMPORTANT: Note that SHFindFiles and SHFindComputer are not modal dialogs (these 
dialogs will be started in separated thread) so the result of function will be True 
if dialog is created succesfully.

Shutdown Dialog

Declaration:
40  
41  procedure ExitWindowsDialog(ParentWnd: HWND); stdcall; external 'Shell32.dll' index
42    60;
43  
44  Example:
45  
46  begin
47    ExitWindowsDialog(0)
48  end;


Restart Dialog

this dialog allow to ask end-user about Windows restarting and is used when changes 
are made to system that require a shutdown/restart before they will take effect.

Declaration:
49  
50  function RestartDialog(ParentWnd: HWND; Reason: PAnsiChar; Flags: LongInt): LongInt;
51    stdcall; external 'Shell32.dll' index 59;
52  
53  //Example:
54  
55  begin
56    if RestartDialog(0, 'I want to call a RestartDialog ', EW_RESTARTWINDOWS) 
57  			= IDYES then ShowMessage('succesfully started')
58  end;


You can define any reason of restarting (second parameter - additionally to default 
text or nil for default only) and use the another flag (one from the next 
available):

EWX_LOGOFF
EWX_SHUTDOWN
EWX_REBOOT
EW_RESTARTWINDOWS
EW_REBOOTSYSTEM
EW_EXITANDEXECAPP

This dialog is very useful for application which have embedded install procedure.

Out Of Space

Will display a notification dialog about "Out Of Space" for some defined drive.

Declaration:
59  
60  procedure SHHandleDiskFull(Owner: HWND; Drive: UINT); stdcall; external
61  'Shell32.dll' index 185;
62  
63  //Example:
64  
65  begin
66    SHHandleDiskFull(0, 2);
67  end;


Note that second parameter is Drive number where 0 is A:, 1 is B:, 2 is C: etc

Of course, in the Shell32.dll you'll find other dialogs too (Object Properties, Map 
Network Drive, Browse For Folder etc) and you can use these dialogs without any 
problems.

IMPORTANT: Don't forget to add ShlObj and ShellAPI units into uses-clause. 

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC