to use extended Windows dialogs

简介:
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: 

1. 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: 
function PickIconDlgA(OwnerWnd: HWND; lpstrFile: PAnsiChar; var nMaxFile: LongInt; var lpdwIconIndex: LongInt): LongBool; stdcall; external 
'SHELL32.DLL' index 62; 

Example (icon of current application will be changed!): 

procedure TForm1.Button4Click(Sender: TObject); 
var 
  FileName: array[0..MAX_PATH-1] of Char; 
  Size, Index: LongInt; 
begin 
  Size := MAX_PATH; 
  FileName := 'c:\windows\system\shell32.dll'; 
  if PickIconDlgA(0, FileName, Size, Index) then 
  begin 
    if (Index <> -1) then 
      Application.Icon.Handle := ExtractIcon(hInstance, FileName, Index); 
  end; 
end; 


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

2. Find Computer 

Declaration: 
function SHFindComputer(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): Boolean; stdcall; external 'Shell32.dll' index 91; 

Example: 

begin 
  SHFindComputer(nil, nil); 
end; 

3. Find Files 

Declaration: 
function SHFindFiles(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): Boolean; stdcall; external 'Shell32.dll' index 90; 

Example: 

begin 
  SHFindFiles(nil, nil); 
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. 

4. Shutdown dialog 

Declaration: 
procedure ExitWindowsDialog(ParentWnd: HWND); stdcall; external 'Shell32.dll' index 60; 

Example: 

begin 
  ExitWindowsDialog(0) 
end; 


5. RestartDialog 
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: 
function RestartDialog(ParentWnd: HWND; Reason: PAnsiChar; Flags: LongInt): LongInt; stdcall; external 'Shell32.dll' index 59; 

Example: 
begin 
  if RestartDialog(0, 'I want to call a RestartDialog ', EW_RESTARTWINDOWS) 
= IDYES then 
    ShowMessage('succesfully started') 
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. 

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

Declaration: 
procedure SHHandleDiskFull(Owner: HWND; Drive: UINT); stdcall; external 
'Shell32.dll' index 185; 

Example: 

begin 
  SHHandleDiskFull(0, 2); 
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.



    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2007/08/20/862457.html,如需转载请自行联系原作者


相关文章
|
3月前
|
XML 数据格式 Windows
【Azure 云服务】Azure Cloud Service (Extended Support) 云服务开启诊断日志插件 WAD Extension (Windows Azure Diagnostic) 无法正常工作的原因
【Azure 云服务】Azure Cloud Service (Extended Support) 云服务开启诊断日志插件 WAD Extension (Windows Azure Diagnostic) 无法正常工作的原因
|
Linux Windows
报错:Web server failed to start. Port 9002 was already in use.端口被占用解决(Windows)
报错:Web server failed to start. Port 9002 was already in use.端口被占用解决(Windows)
663 0
|
数据安全/隐私保护 Windows 小程序
(转载)Windows: "net use" command introduction
1)建立空连接: net use ""IP"ipc$ "" /user:"" (一定要注意:这一行命令中包含了3个空格) 2)建立非空连接: net use ""IP"ipc$ "密码" /user:"用户名" (同样有3个空格) 3)映射默认共享: net use z: ""IP"c$ "密码" ...
670 0
|
关系型数据库 数据安全/隐私保护 PostgreSQL
|
Linux Windows 虚拟化
Does anyone successfully use USB drive in Windows7 guest?
Hi, Does anyone successfully use USB drive in Windows7 guest? If I pass a USB drive to Windows7 guest, Device Manager may find this device but th...
1051 0
|
Windows
Windows 7 出错:Cann't access Input/Mic device or device is already in use.
在Web中使用vaxsip时,拨号 出错:Windows 7 出错:Cann't access Input/Mic device or device is already in use. 解决方法: 系统右下角声音图标 右键->声音(S)->录制->麦克风->“右键"设置为默认设备(不是默认通信设...
944 0
|
Windows
Windows 7 出错:Cann&#39;t access Input/Mic device or device is already in use.
在Web中使用vaxsip时,拨号 出错:Windows 7 出错:Cann't access Input/Mic device or device is already in use. 解决方法: 系统右下角声音图标 右键->声音(S)->录制->麦克风->“右键"设置为默认设备(不是默认通信设...
974 0