应该是非常简单的问题,得到答案,马上结账! ( 积分: 50 )

  • 主题发起人 主题发起人 YuZi
  • 开始时间 开始时间
Y

YuZi

Unregistered / Unconfirmed
GUEST, unregistred user!
调用系统更改图标对话框,用下面的申明方法,在XP下打开时会产生错误,<br>也得不能返回完整的选定的文件名。<br>1.<br>function SHChangeIconDialog;external 'shell32.dll' index 62;<br>function SHChangeIconDialog(h:hwnd;filename:pchar; Reserved:integer;var index:integer):integer;stdcall;<br>2.<br>function PickIconDlgA(OwnerWnd: HWND; lpstrFile: PAnsiChar; var nMaxFile: LongInt;<br> var lpdwIconIndex: LongInt): LongBool; stdcall; external 'SHELL32.DLL' index 62;<br>请问谁有准确的更改图标对话框的函数定义。
 
调用系统更改图标对话框,用下面的申明方法,在XP下打开时会产生错误,<br>也得不能返回完整的选定的文件名。<br>1.<br>function SHChangeIconDialog;external 'shell32.dll' index 62;<br>function SHChangeIconDialog(h:hwnd;filename:pchar; Reserved:integer;var index:integer):integer;stdcall;<br>2.<br>function PickIconDlgA(OwnerWnd: HWND; lpstrFile: PAnsiChar; var nMaxFile: LongInt;<br> var lpdwIconIndex: LongInt): LongBool; stdcall; external 'SHELL32.DLL' index 62;<br>请问谁有准确的更改图标对话框的函数定义。
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;btn1: TButton;<br> &nbsp; &nbsp;OpenDialog1: TOpenDialog;<br> &nbsp; &nbsp;procedure btn1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br><br>function SHChangeIconDialogW(h:hwnd;filename:PWideChar; Reserved:integer;var index:integer):integer;stdcall;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>function SHChangeIconDialogW;external 'shell32.dll' index 62;<br><br>{$R *.dfm}<br><br>procedure TForm1.btn1Click(Sender: TObject);<br>var<br> &nbsp;b:integer;<br> &nbsp;str: WideString;<br>begin<br> &nbsp;b:=0;<br> &nbsp;if opendialog1.Execute then<br> &nbsp;begin<br> &nbsp; &nbsp;str := opendialog1.filename;<br> &nbsp; &nbsp;shChangeIconDialogW(handle,PWideChar(str),SizeOf(str),b);<br> &nbsp;end;<br> &nbsp;showmessage(str);<br>end;<br><br>end.
 
to JamesBond_L:你的代码虽然不会出错了,但:<br>更改图标对话框->点“浏览”按钮->选择新文件-><br>结果:仍然无法返回所打开的文件,即无法得知用户选择了哪个带有图标的文件,<br>函数还是等于没有用,
 
unit uMain;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TfrmDemo006 = class(TForm)<br> &nbsp; &nbsp;btn1: TButton;<br> &nbsp; &nbsp;OpenDialog1: TOpenDialog;<br> &nbsp; &nbsp;procedure btn1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br><br>function SHChangeIconDialogW(h:hwnd;filename:PWideChar; Reserved:integer;var index:integer):integer;stdcall;<br><br>var<br> &nbsp;frmDemo006: TfrmDemo006;<br><br>implementation<br><br>function SHChangeIconDialogW;external 'shell32.dll' index 62;<br><br>{$R *.dfm}<br>function StrCopyW(Dest, Source: PWideChar): PWideChar;<br><br>// copies Source to Dest and returns Dest<br><br>asm<br> &nbsp; &nbsp; &nbsp; &nbsp; PUSH EDI<br> &nbsp; &nbsp; &nbsp; &nbsp; PUSH ESI<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV ESI, EAX<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV EDI, EDX<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV ECX, 0FFFFFFFFH<br> &nbsp; &nbsp; &nbsp; &nbsp; XOR AX, AX<br> &nbsp; &nbsp; &nbsp; &nbsp; REPNE SCASW<br> &nbsp; &nbsp; &nbsp; &nbsp; NOT ECX<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV EDI, ESI<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV ESI, EDX<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV EDX, ECX<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV EAX, EDI<br> &nbsp; &nbsp; &nbsp; &nbsp; SHR ECX, 1<br> &nbsp; &nbsp; &nbsp; &nbsp; REP MOVSD<br> &nbsp; &nbsp; &nbsp; &nbsp; MOV ECX, EDX<br> &nbsp; &nbsp; &nbsp; &nbsp; AND ECX, 1<br> &nbsp; &nbsp; &nbsp; &nbsp; REP MOVSW<br> &nbsp; &nbsp; &nbsp; &nbsp; POP ESI<br> &nbsp; &nbsp; &nbsp; &nbsp; POP EDI<br>end;<br><br>procedure TfrmDemo006.btn1Click(Sender: TObject);<br>const<br> &nbsp;strtemp: WideString = '%s';<br>var<br> &nbsp;b:integer;<br> &nbsp;str: array [0..MAX_PATH] of WideChar;//: WideString;<br> &nbsp;TempStr: WideString;<br>begin<br> &nbsp;b:=0;<br> &nbsp;if opendialog1.Execute then<br> &nbsp;begin<br> &nbsp; &nbsp;WideFmtStr(TempStr, '%s', [opendialog1.filename]);<br> &nbsp; &nbsp;StrCopyW(str, PWideChar(TempStr));<br> &nbsp; &nbsp;shChangeIconDialogW(handle,str,SizeOf(str),b);<br> &nbsp;end;<br> &nbsp;showmessage(str);<br>end;<br><br><br>end.
 
谢谢JamesBond_L!已经可以了,但这样的做法似乎有点夸张了,而且PWideChar在9X下能得到支持吗?<br>如果需要在不同的系统下调用不同的方法的话,那还不如自己写一个专门取图标的对话框了。<br>这50分是JamesBond_L的了,明天结贴,谢谢!<br><br>谁知道有更好的方法吗?我会另开贴给100分的,谢谢!!!
 
之所以这样,这个函数是XP可能只支持Unicode的。如果在9x也有这个函数,你把它改成Ansi就行了。也就是要分平台处理,要检测,JVCL也有个这样的控件,它也是分开处理的。
 
JamesBond_L,你知道有什么好用点的选取图标的控件吗?
 
后退
顶部