如何调用“选择图标”对话框?Icondialog (100分)

  • 主题发起人 主题发起人 hlsoft
  • 开始时间 开始时间
H

hlsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在xp下调用“选择图标”对话框?
 
试试以下代码吧,手头上暂时没 XP ,但应没问题:

// uses clause:
uses ShellAPI, ShellExt

// declarations:
var
pszFileName: Pointer;
nIconIndex: DWORD;

// implementation:
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
GetMem(pszFileName, MAX_PATH*SizeOf(WideChar));
StringToWideChar('', pszFileName, MAX_PATH+1);
end
else
begin
GetMem(pszFileName, MAX_PATH*SizeOf(AnsiChar));
StrPCopy(pszFileName, '');
end;
nIconIndex := 0;
SHPickIcon(Handle, pszFileName, MAX_PATH, nIconIndex);
FreeMem(pszFileName);
 
uses shellapi;
{$R *.DFM}

function SHChangeIconDialog(hOwner:hwnd;szFilename:PWideChar;Reserved:longint; var
lpIconIndex:Longint):Longint;stdcall;external 'shell32.dll' index 62;


function GetIconFromExe(ExeName:WideString):HIcon;
var
ic:longint;
idx:longint;
begin
ic:=SHChangeIconDialog(form1.handle,pWideChar(ExeName),255,idx);//调用图标更换对话框
if ic<>0 then //成功调用
result:=ExtractIcon(0,pchar(string(ExeName)),idx);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Picture.Icon.Handle := GetIconFromExe('D:/Program Files/Internet Explorer/IEXPLORE.exe');
end;
 
我的目的是调用选择图标对话框后返回图标文件名及图标序号

to zw84611
还是不太好用,当选到一个没有图标的文件后,再选其他的图标文见就不能正确返回图标名称及图标序号了,要不没有返回序号,要不出现图标名称残缺,比如c:/windows/system32/shell32.dll,1
程序返回的是c:/windows/system32/shell32.d,1 缺少了扩展名'dll'中的'll'

to bkfx
无法编译,ShellExt是什么?
 
unit ShellExt;

interface

uses Windows, ShlObj;

const
// FormatID
SHFMT_ID_DEFAULT = $FFFF;
SHFMT_ID_720 = $0005;
SHFMT_ID_1440 = $0006;

// Format Options
SHFMT_OPT_FULL = $0001;
SHFMT_OPT_SYSONLY = $0002;

// Format Error Codes
SHFMT_ERROR = $FFFFFFFF;
SHFMT_CANCEL = $FFFFFFFE;
SHFMT_NOFORMAT = $FFFFFFFD;

// RunFile Flags
RFF_NOBROWSE = $01;
RFF_NODEFAULT = $02;
RFF_CALCDIRECTORY = $04;
RFF_NOLABEL = $08;
RFF_NOSEPARATEMEM = $20;

// RunFile Results
RF_OK = $00;
RF_CANCEL = $01;
RF_RETRY = $02;

//SHObjectProperties Flags
OPF_PRINTERNAME = $01;
OPF_PATHNAME = $02;

function SHRestart(hwndOwner: HWND; lpszReason: Pointer; ulFlags: UINT): DWORD;
stdcall; external 'Shell32.dll' index 59;

procedure SHExitWindows(hwndOwner: HWND);
stdcall; external 'Shell32.dll' index 60;

procedure SHRunFile(hwndOwner: HWND; hIcon: HICON; pszDirectory: Pointer;
lpTitle: Pointer; lpszDescription: Pointer; ulFlags: UINT);
stdcall; external 'Shell32.dll' index 61;

function SHPickIcon(hwndOwner: HWND; pszFileName: Pointer; uMaxSize: DWORD;
var nIconIndex: DWORD): LongBool; stdcall; external 'Shell32.dll' index 62;

function SHFormatDrive(hwndOwner: HWND; uDrive: UINT; uFormatID: UINT;
ulFlags: UINT): DWORD; stdcall; external 'Shell32.dll' name 'SHFormatDrive';

function SHAbout(hwndOwner: HWND; pszApp: PAnsiChar; lpszOther: PAnsiChar;
hIcon: HICON): DWORD; stdcall; external 'Shell32.dll' name 'ShellAboutA';

function SHFindFiles(Root: PItemIDList; SavedSearch: PItemIDList): LongBool;
stdcall; external 'Shell32.dll' index 90;

function SHFindComputer(Root: PItemIDList; SavedSearch: PItemIDList): LongBool;
stdcall; external 'Shell32.dll' index 91;

function SHOutOfMemoryMessageBox(hwndOwner: HWND; lpCaption: Pointer;
ulFlags: UINT): Integer; stdcall; external 'Shell32.dll' index 126;

function SHNetConnectionDialog(hwndOwner: HWND; pszResourceName: Pointer;
ulResourceType: UINT): DWORD; stdcall; external 'Shell32.dll' index 160;

function SHObjectProperties(hwndOwner: HWND; ulFlags: UINT;
pszObjectName: Pointer; pszInitialTabName: Pointer): LongBool;
stdcall; external 'Shell32.dll' index 178;

procedure SHHandleDiskFull(hwndOwner: HWND; uDrive: UINT);
stdcall; external 'Shell32.dll' index 185;


implementation

end.
 
后退
顶部