“更换图标”对话框(50分)

  • 主题发起人 主题发起人 莫名
  • 开始时间 开始时间

莫名

Unregistered / Unconfirmed
GUEST, unregistred user!
比如在桌面上有个快捷方式(以LNK为扩展名的),<br>在你的鼠标右键上不是有个属性吗?单击后是不是有个对话框,<br>然后这个对话框里有个“更换图标”的按钮吗?单击后之后,<br>出现的就是我要得到的“更换图标”对话框。 <br>请问如何得到这个“更换图标”对话框??更好写点代码给我……
 
现成的不知道有没有,不过如果自己做的话,可以利用win32 api<br>ExtractIconEx<br>或者<br>ExtractIcon<br>取得可执行文件、dll、或者图标文件的图标
 
不是的怎么读取图标,我要的是更换图标对话框,比如象魔法兔子那样的,<br>那好象是有个专门的函数
 
我以前的练习<br>=========================================================================<br>dlgUnit.pas<br>===========<br>unit dlgUnit;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls,<br>&nbsp; Forms, Dialogs,StdCtrls, ExtCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; Button3: TButton;<br>&nbsp; &nbsp; Button4: TButton;<br>&nbsp; &nbsp; Button5: TButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; CheckBox1: TCheckBox;<br>&nbsp; &nbsp; Button6: TButton;<br>&nbsp; &nbsp; Bevel1: TBevel;<br>&nbsp; &nbsp; Img: TImage;<br>&nbsp; &nbsp; Button7: TButton;<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button6Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; procedure WMQueryEndSession(var Msg: TMessage);<br>&nbsp; &nbsp; &nbsp; message WM_QueryEndSession; // 这个消息是为防止<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 真的退出而设<br>// &nbsp; &nbsp;function InitIconFileName: string;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>// 退出系统的关机函数<br>procedure ExitWindowsDialog(ParentWnd: HWND); stdcall;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; external 'Shell32.dll' index 60;<br><br>// 设备变化后的关机重启选择函数的标志说明<br>// Logoff: Flags := EWX_LOGOFF;<br>// Shutdown: Flags := EWX_SHUTDOWN;<br>// Reboot: Flags := EWX_REBOOT;<br>// Restart: Flags := EW_RESTARTWINDOWS;<br>function RestartDialog(ParentWnd: HWND; Reason: PAnsiChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Flags: LongInt): LongInt; stdcall;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; external 'Shell32.dll' index 59;<br><br>// 选择图标的函数<br>function PickIconDlgA(OwnerWnd: HWND; lpstrFile: PAnsiChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; var nMaxFile: LongInt; var lpdwIconIndex: LongInt):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LongBool;stdcall; external 'SHELL32.DLL' index 62;<br><br>// 运行对话框函数<br>procedure RunFileDlgA(OwnerWnd: HWND; Icon: HICON; lpstrDirectory: PAnsiChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpstrTitle: PAnsiChar; lpstrDescription: PAnsiChar; Flags: LongInt);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stdcall; external 'Shell32.dll' index 61;<br><br>implementation<br>&nbsp;uses ShellAPI;<br>&nbsp;Const App='Windows 未文档化的函数演示';<br>&nbsp;Flags: LongInt = 0;<br>&nbsp;RFF_NOBROWSE = 1;<br>{$R *.DFM}<br><br>procedure TForm1.WMQueryEndSession(var Msg: TMessage);<br>begin // 只演示,不要真的退出 Windows 消息响应<br>&nbsp; if CheckBox1.Checked then Msg.Result := 0<br>&nbsp; else Msg.Result := 1;<br>end;<br><br>{function TForm1.InitIconFileName: string;<br>var<br>&nbsp; MSysDir: array[0..MAX_PATH - 1] of Char;<br>&nbsp; SysDir: string;<br>begin<br>&nbsp; GetSystemDirectory(MSysDir, 255);<br>&nbsp; SysDir := StrPas(MSysDir);<br>&nbsp; if SysDir[Length(SysDir)] &lt;&gt; '/' then<br>&nbsp; begin<br>&nbsp; &nbsp; SysDir := SysDir + '/';<br>&nbsp; end;<br>&nbsp; Result := SysDir + 'SHELL32.DLL';<br>end; }<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>{====实际使用这个函数作为过渡====<br>function RestartExecute: Boolean;<br>begin<br>if RestartDialog(0,nil,Flags) = IDYES then<br>&nbsp;begin<br>&nbsp; Result := True;<br>&nbsp;end<br>else<br>&nbsp;Result := False;<br>end;<br>=================================}<br>begin<br>Flags := Flags or RFF_NOBROWSE;<br>&nbsp; case (Sender as TButton).tag of<br>&nbsp; &nbsp; 0: RestartDialog(self.Handle, '', EWX_SHUTDOWN);<br>&nbsp; &nbsp; 1: RestartDialog(self.Handle, '', EWX_LOGOFF);<br>&nbsp; &nbsp; 2: RestartDialog(self.Handle, '', EWX_REBOOT);<br>&nbsp; &nbsp; 3: RestartDialog(self.Handle, '', EW_RESTARTWINDOWS);<br><br>&nbsp; &nbsp; 4: ExitWindowsDialog(self.Handle);<br>&nbsp; &nbsp; &nbsp;{ 下一句文字显示在 Win2000 中有问题,没时间了,不搞了}<br>&nbsp; &nbsp; 5: RunFileDlgA(self.Handle,self.Icon.Handle,'C:/',<br>&nbsp; &nbsp; &nbsp; &nbsp;'运行','',Flags);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button6Click(Sender: TObject);<br>var // 本段在调试中老放CPU画面,但实际却可以用。<br>&nbsp; fFileName,Temp: string;<br>&nbsp; S: array [0..MAX_PATH - 1] of WideChar;//StrPas<br>// &nbsp;Tem: array [0..MAX_PATH - 1] of Char;<br>&nbsp; fSize, fIndex: LongInt;<br>&nbsp; I:Integer;<br>&nbsp; Icon: TIcon;<br>begin &nbsp; // 我没有办法解决发出的 PAnsiChar 如何保证<br>&nbsp; &nbsp; &nbsp; &nbsp; // 既能送出PAnsiChar又能接收PWideChar!!<br>&nbsp; SetLength(fFileName, 255); &nbsp;// 给fFileName设定长度<br><br>&nbsp; GetSystemDirectory(PChar(fFileName), 255);// 取得系统目录<br>&nbsp; { &nbsp;获得实际的fFileName &nbsp;}<br>&nbsp; SetLength(fFileName, StrLen(PChar(fFileName)));<br>&nbsp; { &nbsp; 拼接Shell32.dll &nbsp;}<br>&nbsp; fFileName:=fFileName + '/' + 'SHELL32.DLL';<br>&nbsp; fSize := MAX_PATH;<br>&nbsp; { 我用了以下的办法解决我的困惑 }<br>&nbsp;For I:=Low(S) to Length(fFileName) do<br>&nbsp; &nbsp;S:=WideChar(fFileName);<br><br>&nbsp; if PickIconDlgA(self.Handle,PAnsiChar(@S),fSize, fIndex)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (fIndex &lt;&gt; -1) then<br>&nbsp; begin<br>&nbsp; SetLength(Temp, MAX_PATH-1);<br>&nbsp; Temp := S; // 将WideString转换回来,这里的 S<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 已经是 PAnsiChar 了<br><br>&nbsp; Icon := TIcon.Create;<br>&nbsp; Form1.Caption :=App+' &nbsp; '+ 'FileName:'+Temp+' ,'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+'Icon:'+ IntToStr(fIndex);<br>&nbsp; Icon.Handle := ExtractIcon(hInstance, PChar(Temp), fIndex);<br>&nbsp; Img.Picture.Icon := Icon;<br>&nbsp; Form1.Icon := Img.Picture.Icon;<br>&nbsp; Icon := nil;<br>&nbsp; Icon.Free;<br>&nbsp; end;<br><br>end;<br><br>end.<br>====================================================================<br>dlgUnit.dfm<br>===================<br>object Form1: TForm1<br>&nbsp; Left = 207<br>&nbsp; Top = 143<br>&nbsp; BorderIcons = [biSystemMenu, biMinimize]<br>&nbsp; BorderStyle = bsSingle<br>&nbsp; Caption = 'Windows 未文档化的函数演示'<br>&nbsp; ClientHeight = 400<br>&nbsp; ClientWidth = 632<br>&nbsp; Color = clBtnFace<br>&nbsp; Font.Charset = GB2312_CHARSET<br>&nbsp; Font.Color = clWindowText<br>&nbsp; Font.Height = -12<br>&nbsp; Font.Name = '宋体'<br>&nbsp; Font.Style = []<br>&nbsp; Icon.Data = {<br>&nbsp; &nbsp; 0000010001002020000000000000A80800001600000028000000200000004000<br>&nbsp; &nbsp; 0000010008000000000080040000000000000000000000000000000000000000<br>&nbsp; &nbsp; 0000000080000080000000808000800000008000800080800000C0C0C000C0DC<br>&nbsp; &nbsp; C000F0CAA6000020400000206000002080000020A0000020C0000020E0000040<br>&nbsp; &nbsp; 0000004020000040400000406000004080000040A0000040C0000040E0000060<br>&nbsp; &nbsp; 0000006020000060400000606000006080000060A0000060C0000060E0000080<br>&nbsp; &nbsp; 0000008020000080400000806000008080000080A0000080C0000080E00000A0<br>&nbsp; &nbsp; 000000A0200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0<br>&nbsp; &nbsp; 000000C0200000C0400000C0600000C0800000C0A00000C0C00000C0E00000E0<br>&nbsp; &nbsp; 000000E0200000E0400000E0600000E0800000E0A00000E0C00000E0E0004000<br>&nbsp; &nbsp; 0000400020004000400040006000400080004000A0004000C0004000E0004020<br>&nbsp; &nbsp; 0000402020004020400040206000402080004020A0004020C0004020E0004040<br>&nbsp; &nbsp; 0000404020004040400040406000404080004040A0004040C0004040E0004060<br>&nbsp; &nbsp; 0000406020004060400040606000406080004060A0004060C0004060E0004080<br>&nbsp; &nbsp; 0000408020004080400040806000408080004080A0004080C0004080E00040A0<br>&nbsp; &nbsp; 000040A0200040A0400040A0600040A0800040A0A00040A0C00040A0E00040C0<br>&nbsp; &nbsp; 000040C0200040C0400040C0600040C0800040C0A00040C0C00040C0E00040E0<br>&nbsp; &nbsp; 000040E0200040E0400040E0600040E0800040E0A00040E0C00040E0E0008000<br>&nbsp; &nbsp; 0000800020008000400080006000800080008000A0008000C0008000E0008020<br>&nbsp; &nbsp; 0000802020008020400080206000802080008020A0008020C0008020E0008040<br>&nbsp; &nbsp; 0000804020008040400080406000804080008040A0008040C0008040E0008060<br>&nbsp; &nbsp; 0000806020008060400080606000806080008060A0008060C0008060E0008080<br>&nbsp; &nbsp; 0000808020008080400080806000808080008080A0008080C0008080E00080A0<br>&nbsp; &nbsp; 000080A0200080A0400080A0600080A0800080A0A00080A0C00080A0E00080C0<br>&nbsp; &nbsp; 000080C0200080C0400080C0600080C0800080C0A00080C0C00080C0E00080E0<br>&nbsp; &nbsp; 000080E0200080E0400080E0600080E0800080E0A00080E0C00080E0E000C000<br>&nbsp; &nbsp; 0000C0002000C0004000C0006000C0008000C000A000C000C000C000E000C020<br>&nbsp; &nbsp; 0000C0202000C0204000C0206000C0208000C020A000C020C000C020E000C040<br>&nbsp; &nbsp; 0000C0402000C0404000C0406000C0408000C040A000C040C000C040E000C060<br>&nbsp; &nbsp; 0000C0602000C0604000C0606000C0608000C060A000C060C000C060E000C080<br>&nbsp; &nbsp; 0000C0802000C0804000C0806000C0808000C080A000C080C000C080E000C0A0<br>&nbsp; &nbsp; 0000C0A02000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C0<br>&nbsp; &nbsp; 0000C0C02000C0C04000C0C06000C0C08000C0C0A000F0FBFF00A4A0A0008080<br>&nbsp; &nbsp; 80000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF000000<br>&nbsp; &nbsp; 0000000000000000000000000000000000000000000000000000000000000000<br>&nbsp; &nbsp; 000000000000000000000000000000A4A4A4F700000000000000000000000000<br>&nbsp; &nbsp; 0000000000000000000000000098FC0000000000000000010100000000000000<br>&nbsp; &nbsp; 00000000000000000000FC000000000000FC989898FC0000009BA40000000000<br>&nbsp; &nbsp; 0000000000000000FC00000000FC98FCFCFCFCFCFC0000000A0001A400000000<br>&nbsp; &nbsp; 0000000000000000000000FC98FCFCFC000000FC00000000000A010100000000<br>&nbsp; &nbsp; 000000000000000000FC98FCFCFC0000B7A400000000000000031D0000000000<br>&nbsp; &nbsp; 00000000000000ACAC00FCFC000007B7F76EA4000101011F0100000000000000<br>&nbsp; &nbsp; 000000000000E3D9D9000000B707B7F76EA40001016EA4011F00EC0000000000<br>&nbsp; &nbsp; 00000000F4E1D9DADADA000007B7076EA46E00A46EF76EA400EC000000000000<br>&nbsp; &nbsp; 000000F4E1D9D9D1D19999000007B7F700000000006EA400ECA4000000000000<br>&nbsp; &nbsp; 0000F4E0D1D09090D0905900006E076EA46EA4B7A4006E00EC9B000000000000<br>&nbsp; &nbsp; 0000EAD090D0D0D0D090000000006E07B707B707B70000000000000000000000<br>&nbsp; &nbsp; 0009D090D0D0D0D0D8000000000000B707B7F76EF7006EF76EF7000000000000<br>&nbsp; &nbsp; 00EAD0D0D0D8D8D8D80000000000B7F7B7F7B707B700006EF7B7000000000000<br>&nbsp; &nbsp; 09D8D0D0D8D8D8D80000000000B707B7F7B7F6B707B707006EF7000000000000<br>&nbsp; &nbsp; 09D0D0D8D8D8D8E0000000000007B707B7F6B7F6B707006EF76E000000000000<br>&nbsp; &nbsp; EBD0D8D8D8E0E0E0000000000000076EF7B70700F7B700F7B7076EF700000000<br>&nbsp; &nbsp; EBD8D8D8E0E0A80600000000000000006EF7B700000000B7076EF70000000000<br>&nbsp; &nbsp; EBD8D8E0E06828E00000000000000000006E07B7070A00F700076E0000000000<br>&nbsp; &nbsp; EBD8E0E068292972000000000000000000006E07B707006E0000000B00000000<br>&nbsp; &nbsp; 09D8E0E02932323200000000000000000000006EF7B700F76EF70A0B00000000<br>&nbsp; &nbsp; 09E0E0E0323273737300000000000000000000000000006EF7B7F70000000000<br>&nbsp; &nbsp; 09EAE0693273737CBC000000000000000000000000000A006EF76E0000000000<br>&nbsp; &nbsp; 0009683273737CF409BD000000000000000000000A0A00000000000000000000<br>&nbsp; &nbsp; 00097332737C7CF5080808FF00000000000A0A0A000000000000000000000000<br>&nbsp; &nbsp; 0000097373BBBCBD08F60809BC73730A0A000000000000000000000000000000<br>&nbsp; &nbsp; 00000009B2B3BCF509080809BC733269E8000000000000000000000000000000<br>&nbsp; &nbsp; 0000000008BCB3F4F5F5F5BC7C737272E0E0E0EA080000000000000000000000<br>&nbsp; &nbsp; 00000000000909F4F3BCBC7C73733229E8E9F408000000000000000000000000<br>&nbsp; &nbsp; 000000000000000809F4F4BCF2B2B3F309090000000000000000000000000000<br>&nbsp; &nbsp; 000000000000000000090909090909090000000000000000000000000000FFFF<br>&nbsp; &nbsp; FFFFFFFF87FFFFFE001FFFF00007FFC00003FFC00003FFC00003FF800003FF00<br>&nbsp; &nbsp; 0007FC00000FF800000FF000000FF000000FE0000007E0000007C0000007C000<br>&nbsp; &nbsp; 0003C0000001C0000003C0000003C0000003C0000003C0000003C0000001E000<br>&nbsp; &nbsp; 0001E0000001F0000003F800000FFC0001FFFE0003FFFF800FFFFFE03FFF}<br>&nbsp; OldCreateOrder = False<br>&nbsp; PixelsPerInch = 96<br>&nbsp; TextHeight = 12<br>&nbsp; object Bevel1: TBevel<br>&nbsp; &nbsp; Left = 11<br>&nbsp; &nbsp; Top = 217<br>&nbsp; &nbsp; Width = 36<br>&nbsp; &nbsp; Height = 36<br>&nbsp; &nbsp; Shape = bsFrame<br>&nbsp; end<br>&nbsp; object Label1: TLabel<br>&nbsp; &nbsp; Left = 8<br>&nbsp; &nbsp; Top = 3<br>&nbsp; &nbsp; Width = 189<br>&nbsp; &nbsp; Height = 12<br>&nbsp; &nbsp; Caption = '以下均在 Windows 2000 中编制'<br>&nbsp; &nbsp; Font.Charset = GB2312_CHARSET<br>&nbsp; &nbsp; Font.Color = clBlack<br>&nbsp; &nbsp; Font.Height = -12<br>&nbsp; &nbsp; Font.Name = '宋体'<br>&nbsp; &nbsp; Font.Style = [fsBold]<br>&nbsp; &nbsp; ParentFont = False<br>&nbsp; &nbsp; Transparent = True<br>&nbsp; end<br>&nbsp; object Img: TImage<br>&nbsp; &nbsp; Left = 13<br>&nbsp; &nbsp; Top = 219<br>&nbsp; &nbsp; Width = 32<br>&nbsp; &nbsp; Height = 32<br>&nbsp; &nbsp; Transparent = True<br>&nbsp; end<br>&nbsp; object Button1: TButton<br>&nbsp; &nbsp; Tag = 4<br>&nbsp; &nbsp; Left = 11<br>&nbsp; &nbsp; Top = 54<br>&nbsp; &nbsp; Width = 171<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '关机重新启动效果'<br>&nbsp; &nbsp; TabOrder = 0<br>&nbsp; &nbsp; OnClick = Button2Click<br>&nbsp; end<br>&nbsp; object Button2: TButton<br>&nbsp; &nbsp; Left = 11<br>&nbsp; &nbsp; Top = 87<br>&nbsp; &nbsp; Width = 171<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '是否立即关机效果'<br>&nbsp; &nbsp; TabOrder = 1<br>&nbsp; &nbsp; OnClick = Button2Click<br>&nbsp; end<br>&nbsp; object Button3: TButton<br>&nbsp; &nbsp; Tag = 1<br>&nbsp; &nbsp; Left = 11<br>&nbsp; &nbsp; Top = 119<br>&nbsp; &nbsp; Width = 171<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '设置改变重新启动效果 A'<br>&nbsp; &nbsp; TabOrder = 2<br>&nbsp; &nbsp; OnClick = Button2Click<br>&nbsp; end<br>&nbsp; object Button4: TButton<br>&nbsp; &nbsp; Tag = 2<br>&nbsp; &nbsp; Left = 11<br>&nbsp; &nbsp; Top = 152<br>&nbsp; &nbsp; Width = 171<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '设置改变重新启动效果 B'<br>&nbsp; &nbsp; TabOrder = 3<br>&nbsp; &nbsp; OnClick = Button2Click<br>&nbsp; end<br>&nbsp; object Button5: TButton<br>&nbsp; &nbsp; Tag = 3<br>&nbsp; &nbsp; Left = 11<br>&nbsp; &nbsp; Top = 184<br>&nbsp; &nbsp; Width = 171<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '设置改变重新启动效果 C'<br>&nbsp; &nbsp; TabOrder = 4<br>&nbsp; &nbsp; OnClick = Button2Click<br>&nbsp; end<br>&nbsp; object CheckBox1: TCheckBox<br>&nbsp; &nbsp; Left = 7<br>&nbsp; &nbsp; Top = 28<br>&nbsp; &nbsp; Width = 193<br>&nbsp; &nbsp; Height = 17<br>&nbsp; &nbsp; Caption = '只演示,不要真的退出 Windows'<br>&nbsp; &nbsp; Checked = True<br>&nbsp; &nbsp; State = cbChecked<br>&nbsp; &nbsp; TabOrder = 5<br>&nbsp; end<br>&nbsp; object Button6: TButton<br>&nbsp; &nbsp; Left = 66<br>&nbsp; &nbsp; Top = 222<br>&nbsp; &nbsp; Width = 115<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '图标选择效果'<br>&nbsp; &nbsp; TabOrder = 6<br>&nbsp; &nbsp; OnClick = Button6Click<br>&nbsp; end<br>&nbsp; object Button7: TButton<br>&nbsp; &nbsp; Tag = 5<br>&nbsp; &nbsp; Left = 11<br>&nbsp; &nbsp; Top = 258<br>&nbsp; &nbsp; Width = 171<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '运行对话框效果'<br>&nbsp; &nbsp; TabOrder = 7<br>&nbsp; &nbsp; OnClick = Button2Click<br>&nbsp; end<br>&nbsp; object Memo1: TMemo<br>&nbsp; &nbsp; Left = 204<br>&nbsp; &nbsp; Top = 1<br>&nbsp; &nbsp; Width = 426<br>&nbsp; &nbsp; Height = 397<br>&nbsp; &nbsp; Color = clInfoBk<br>&nbsp; &nbsp; Font.Charset = ANSI_CHARSET<br>&nbsp; &nbsp; Font.Color = clWindowText<br>&nbsp; &nbsp; Font.Height = -12<br>&nbsp; &nbsp; Font.Name = 'Courier New'<br>&nbsp; &nbsp; Font.Style = []<br>&nbsp; &nbsp; Lines.Strings = (<br>&nbsp; &nbsp; &nbsp; 'unit dlgUnit;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'interface'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'uses'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Windows, Messages, SysUtils, Classes, Graphics, '<br>&nbsp; &nbsp; &nbsp; 'Controls,'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Forms, Dialogs,StdCtrls, ExtCtrls;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'type'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;TForm1 = class(TForm)'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Button1: TButton;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Button2: TButton;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Button3: TButton;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Button4: TButton;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Button5: TButton;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Label1: TLabel;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;CheckBox1: TCheckBox;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Button6: TButton;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Bevel1: TBevel;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Img: TImage;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Button7: TButton;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;Memo1: TMemo;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;procedure Button2Click(Sender: TObject);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;procedure Button6Click(Sender: TObject);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;private'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;procedure WMQueryEndSession(var Msg: TMessage);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp;message WM_QueryEndSession; // 这个消息是为防止'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 真的退出而设'<br>&nbsp; &nbsp; &nbsp; '// &nbsp; &nbsp;function InitIconFileName: string;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;public'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;{ Public declarations }'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;end;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'var'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Form1: TForm1;'<br>&nbsp; &nbsp; &nbsp; '// 退出系统的关机函数'<br>&nbsp; &nbsp; &nbsp; 'procedure ExitWindowsDialog(ParentWnd: HWND); stdcall;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;external '#39'Shell32.dll'#39' index 60;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; '// 设备变化后的关机重启选择函数的标志说明'<br>&nbsp; &nbsp; &nbsp; '// Logoff: Flags := EWX_LOGOFF;'<br>&nbsp; &nbsp; &nbsp; '// Shutdown: Flags := EWX_SHUTDOWN;'<br>&nbsp; &nbsp; &nbsp; '// Reboot: Flags := EWX_REBOOT;'<br>&nbsp; &nbsp; &nbsp; '// Restart: Flags := EW_RESTARTWINDOWS;'<br>&nbsp; &nbsp; &nbsp; 'function RestartDialog(ParentWnd: HWND; Reason: '<br>&nbsp; &nbsp; &nbsp; 'PAnsiChar;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Flags: LongInt): LongInt; '<br>&nbsp; &nbsp; &nbsp; 'stdcall;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;external '#39'Shell32.dll'#39' index '<br>&nbsp; &nbsp; &nbsp; '59;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; '// 选择图标的函数'<br>&nbsp; &nbsp; &nbsp; 'function PickIconDlgA(OwnerWnd: HWND; lpstrFile: '<br>&nbsp; &nbsp; &nbsp; 'PAnsiChar;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp;var nMaxFile: LongInt; var lpdwIconIndex: '<br>&nbsp; &nbsp; &nbsp; 'LongInt):'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; LongBool;stdcall; external '#39'SHELL32.DLL'#39' index '<br>&nbsp; &nbsp; &nbsp; '62;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; '// 运行对话框函数'<br>&nbsp; &nbsp; &nbsp; 'procedure RunFileDlgA(OwnerWnd: HWND; Icon: HICON; '<br>&nbsp; &nbsp; &nbsp; 'lpstrDirectory: PAnsiChar;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; lpstrTitle: PAnsiChar; lpstrDescription: '<br>&nbsp; &nbsp; &nbsp; 'PAnsiChar; '<br>&nbsp; &nbsp; &nbsp; 'Flags: LongInt);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; stdcall; external '#39'Shell32.dll'#39' index 61;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'implementation'<br>&nbsp; &nbsp; &nbsp; ' uses ShellAPI;'<br>&nbsp; &nbsp; &nbsp; ' Const App='#39'Windows 未文档化的函数演示'#39';'<br>&nbsp; &nbsp; &nbsp; ' Flags: LongInt = 0;'<br>&nbsp; &nbsp; &nbsp; ' RFF_NOBROWSE = 1;'<br>&nbsp; &nbsp; &nbsp; '{$R *.DFM}'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'procedure TForm1.WMQueryEndSession(var Msg: TMessage);'<br>&nbsp; &nbsp; &nbsp; 'begin // 只演示,不要真的退出 Windows 消息响应'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp;// 这里不能自己表示 ,要以非模态处理!!'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;if CheckBox1.Checked then Msg.Result := 1'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;else Msg.Result := 0;'<br>&nbsp; &nbsp; &nbsp; 'end;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; '{function TForm1.InitIconFileName: string;'<br>&nbsp; &nbsp; &nbsp; 'var'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;MSysDir: array[0..MAX_PATH - 1] of Char;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;SysDir: string;'<br>&nbsp; &nbsp; &nbsp; 'begin'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;GetSystemDirectory(MSysDir, 255);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;SysDir := StrPas(MSysDir);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;if SysDir[Length(SysDir)] &lt;&gt; '#39'/'#39' then'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;begin'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;SysDir := SysDir + '#39'/'#39';'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;end;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Result := SysDir + '#39'SHELL32.DLL'#39';'<br>&nbsp; &nbsp; &nbsp; 'end; }'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'procedure TForm1.Button2Click(Sender: TObject);'<br>&nbsp; &nbsp; &nbsp; '{====实际使用这个函数作为过渡===='<br>&nbsp; &nbsp; &nbsp; 'function RestartExecute: Boolean;'<br>&nbsp; &nbsp; &nbsp; 'begin'<br>&nbsp; &nbsp; &nbsp; 'if RestartDialog(0,nil,Flags) = IDYES then'<br>&nbsp; &nbsp; &nbsp; ' begin'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Result := True;'<br>&nbsp; &nbsp; &nbsp; ' end'<br>&nbsp; &nbsp; &nbsp; 'else'<br>&nbsp; &nbsp; &nbsp; ' Result := False;'<br>&nbsp; &nbsp; &nbsp; 'end;'<br>&nbsp; &nbsp; &nbsp; '=================================}'<br>&nbsp; &nbsp; &nbsp; 'begin'<br>&nbsp; &nbsp; &nbsp; 'Flags := Flags or RFF_NOBROWSE;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;case (Sender as TButton).tag of'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;0: RestartDialog(self.Handle, '#39#39', EWX_SHUTDOWN);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;1: RestartDialog(self.Handle, '#39#39', EWX_LOGOFF);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;2: RestartDialog(self.Handle, '#39#39', EWX_REBOOT);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;3: RestartDialog(self.Handle, '#39#39', EW_RESTARTWINDOWS);'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;4: ExitWindowsDialog(self.Handle);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; { 下一句文字显示在 Win2000 中有问题,没时间了,不搞了}'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp;5: RunFileDlgA(self.Handle,self.Icon.Handle,'#39'C:/'#39','<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; '#39'运行'#39','#39#39',Flags);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;end;'<br>&nbsp; &nbsp; &nbsp; 'end;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'procedure TForm1.Button6Click(Sender: TObject);'<br>&nbsp; &nbsp; &nbsp; 'var // 本段在调试中老放CPU画面,但实际却可以用。'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;fFileName,Temp: string;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;S: array [0..MAX_PATH - 1] of WideChar;//StrPas'<br>&nbsp; &nbsp; &nbsp; '// &nbsp;Tem: array [0..MAX_PATH - 1] of Char;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;fSize, fIndex: LongInt;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;I:Integer;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Icon: TIcon;'<br>&nbsp; &nbsp; &nbsp; 'begin &nbsp; // 我没有办法解决发出的 PAnsiChar 如何保证'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp;// 既能送出PAnsiChar又能接收PWideChar!!'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;SetLength(fFileName, 255); &nbsp;// 给fFileName设定长度'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; ' &nbsp;GetSystemDirectory(PChar(fFileName), 255);// 取得系统目录'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;{ &nbsp;获得实际的fFileName &nbsp;}'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;SetLength(fFileName, StrLen(PChar(fFileName)));'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;{ &nbsp; 拼接Shell32.dll &nbsp;}'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;fFileName:=fFileName + '#39'/'#39' + '#39'SHELL32.DLL'#39';'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;fSize := MAX_PATH;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;{ 我用了以下的办法解决我的困惑 }'<br>&nbsp; &nbsp; &nbsp; ' For I:=Low(S) to Length(fFileName) do'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; S:=WideChar(fFileName);'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; ' &nbsp;if PickIconDlgA(self.Handle,PAnsiChar(@S),fSize, '<br>&nbsp; &nbsp; &nbsp; 'fIndex)'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and (fIndex &lt;&gt; -1) '<br>&nbsp; &nbsp; &nbsp; 'then'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;begin'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;SetLength(Temp, MAX_PATH-1);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Temp := S; // 将WideString转换回来,这里的 S'<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 已经是 PAnsiChar 了'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Icon := TIcon.Create;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Form1.Caption :=App+'#39' &nbsp; '#39'+ '#39'FileName:'#39'+Temp+'#39' ,'#39<br>&nbsp; &nbsp; &nbsp; ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +'#39'Icon:'#39'+ IntToStr(fIndex);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Icon.Handle := ExtractIcon(hInstance, PChar(Temp), '<br>&nbsp; &nbsp; &nbsp; 'fIndex);'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Img.Picture.Icon := Icon;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Form1.Icon := Img.Picture.Icon;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Icon := nil;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;Icon.Free;'<br>&nbsp; &nbsp; &nbsp; ' &nbsp;end;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'end;'<br>&nbsp; &nbsp; &nbsp; ''<br>&nbsp; &nbsp; &nbsp; 'end.')<br>&nbsp; &nbsp; ParentFont = False<br>&nbsp; &nbsp; ScrollBars = ssVertical<br>&nbsp; &nbsp; TabOrder = 8<br>&nbsp; end<br>end<br><br>
 
我主页http://ph11.126.com上正好有此控件(带源码),你下载一下吧!<br>http://go8.163.com/windstorm2000/vcls/ICONDLG.ZIP
 
好,先请了。偶先看看去
 
To Ale. 你是个高手呀!可以交个朋友吗?我的QQ:6102278<br><br>但那个程序读出来的路径是乱码呀?
 
你的程序是在 98 里吧,就用下面的过程:<br>unit Unit1;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; end;<br><br>// 选择图标的 API 函数<br>function PickIconDlgA(OwnerWnd: HWND; lpstrFile: PAnsiChar;<br>&nbsp; var nMaxFile: LongInt; var lpdwIconIndex: LongInt):<br>&nbsp; LongBool; stdcall; external 'SHELL32.DLL' index 62;<br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br>uses<br>&nbsp; ShellAPI; // 这个单元一定要加 !!!<br>const<br>&nbsp; App = '98 中选择图标的函数演示';<br>{$R *.DFM}<br>//******************* Button1Click *************************<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; fFileName: string;<br>&nbsp; fSize, fIndex: LongInt;<br>begin<br>&nbsp; SetLength(fFileName, 255); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 给fFileName设定长度,其实是分配内存.<br>&nbsp; GetSystemDirectory(PChar(fFileName), 255); &nbsp; &nbsp; &nbsp;// 调用 API 取得系统目录<br>&nbsp; SetLength(fFileName, StrLen(PChar(fFileName))); // &nbsp; 获得实际的fFileName<br>&nbsp; fFileName := fFileName + '/' + 'SHELL32.DLL'; &nbsp; // &nbsp; 拼接Shell32.dll<br>&nbsp; fSize := MAX_PATH;<br>&nbsp; if PickIconDlgA(self.Handle, PAnsiChar(fFileName), fSize, fIndex) // 调用图标选择 API 函数<br>&nbsp; &nbsp; and (fIndex &lt;&gt; -1) then<br>&nbsp; begin<br>&nbsp; &nbsp; Form1.Caption := App + ' &nbsp; ' + 'FileName:' + fFileName + ' ,' &nbsp; // 在 Form 的标题栏显示文件名<br>&nbsp; &nbsp; &nbsp; + 'Icon:' + IntToStr(fIndex);<br>&nbsp; &nbsp; Form1.Icon.Handle := ExtractIcon(hInstance, &nbsp; // 把选择的图标赋给 Form 的标题栏图标<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PChar(fFileName), fIndex); <br>&nbsp; end;<br>end;<br>end.<br>
 
后退
顶部