博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
to use extended Windows dialogs
阅读量:7078 次
发布时间:2019-06-28

本文共 3574 字,大约阅读时间需要 11 分钟。

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,如需转载请自行联系原作者

你可能感兴趣的文章
JavaScript常用开发工具集合
查看>>
加快网络信息安全配套工程建设
查看>>
AMD全新企业级CPU与APU路线图曝光
查看>>
富瑞:微博财报将超预期 广告主预算正向微博迁移
查看>>
听CIO们关于与经营管理同事协同工作的建议
查看>>
论国产化芯片出路 破“玻璃巨人之危”
查看>>
软件测试管理的一点经验
查看>>
FB等社交媒体都争做原创视频 是为了广告费吗?
查看>>
运营商积极布局物联网 万亿级市场有望启动
查看>>
云平台大数据助推昆明市“互联网+农业”行动实施
查看>>
他将网络安全威胁比喻成癌症
查看>>
视频监控热成像技术在民用领域的广泛应用
查看>>
《大众创业做电商——淘宝与微店 开店 运营 推广 一册通》一一2.1 电子商务的发展历史...
查看>>
Light Table —— 多语言集成开发环境
查看>>
未来桌面 PC 会消失吗?
查看>>
换个 timeline 看知乎
查看>>
《UG NX10中文版完全自学手册》——2.6 常用工具
查看>>
《深入理解Hadoop(原书第2版)》——1.5我们能处理多大的数据量
查看>>
《CCNP TSHOOT 300-135认证考试指南》——6.9节三层EtherChannel故障工单
查看>>
Google AI 发明了自己的防窃听加密算法
查看>>