来自我的程序;
你看对你有用吗?加入 ShellAPI 单元;
主要使用 ExtractAssociatedIcon(); procedure TForm1.Button4Click(Sender: TObject);
//draw application iconvar
Icon : hIcon;
IconIndex : word;
begin
IconIndex := 1;
Icon := ExtractAssociatedIcon(HInstance, Pchar(Application.ExeName), IconIndex);
DrawIcon(Canvas.Handle, 110, 70, Icon);
end;
你看对你有用吗?加入 ShellAPI 单元;
主要使用 ExtractAssociatedIcon(); procedure TForm1.Button4Click(Sender: TObject);
//draw application iconvar
Icon : hIcon;
IconIndex : word;
begin
IconIndex := 1;
Icon := ExtractAssociatedIcon(HInstance, Pchar(Application.ExeName), IconIndex);
DrawIcon(Canvas.Handle, 110, 70, Icon);
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, Buttons,ShellAPI,CommCtrl, ExtCtrls, ImgList;type
WinInfo=record
ico:HICON;
Handle:HWND;
end;type
pWinInfo=^WinInfo;type
TfrmEnumWindow = class(TForm)
bbRefresh: TBitBtn;
LV_Show: TListView;
imgList: TImageList;
procedure bbRefreshClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
mStrWinName:TStringList;
mStrClassName:TStringList;
mStrWinHandle:TStringList;
frmEnumWindow: TfrmEnumWindow;
//declare owner function
function EnumWindowsProc(Handle:HWND;lp:LPARAM):LongBool;stdcall;implementation{$R *.DFM}function EnumWindowsProc(Handle:HWND;lp:LPARAM):LongBool;stdcall;
var
lpWinName:Array[0..255] of char;
lpClassName:Array[0..255]of char;
lpNameLen:integer;
begin
lpNameLen:=GetWindowText(Handle,lpWinName,sizeof(lpWinName)-1);
if((lpNameLen>0)and(IsWindowVisible(Handle)))then
begin
mStrWinHandle.Add(IntToStr(Handle));
mStrWinName.Add(Copy(lpWinName,1,lpNameLen));
lpNameLen:=GetClassName(Handle,lpClassName,sizeof(lpClassName)-1);
if((lpNameLen>0)and(IsWindowVisible(Handle)))then
mStrClassName.Add(Copy(lpClassName,1,lpNameLen));
end;
EnumWindowsProc:=LongBool(1);
end;
procedure TfrmEnumWindow.bbRefreshClick(Sender: TObject);
var
i:Integer;
xItem:TListItem;
wInfo:pWinInfo;
ico:TIcon;
index:integer;
begin
mStrWinName.Clear;
mStrClassName.Clear;
mStrWinHandle.Clear; while(ImgList.Count>0)do ImgList.Delete(0); LV_Show.Items.Clear;
EnumWindows(TFNWndEnumProc(@EnumWindowsProc),LPARAM(0)); for i:=0 to mStrWinName.Count -1 do
begin
ico:=TIcon.Create;
wInfo:=new(pWinInfo);
xItem:=LV_Show.Items.Add;
xItem.Caption:=mStrWinName.Strings[i];
xItem.SubItems.Add(mstrClassName.Strings[i]);
wInfo^.Handle:=StrToInt(mstrWinHandle.Strings[i]);
wInfo^.ico:=SendMessage(wInfo^.Handle,WM_GETICON,ICON_BIG,0);
xItem.Data:=wInfo;
ico.Handle:=wInfo^.ico;
index:=ImgList.AddIcon(ico);
if(index<>-1)then
xItem.ImageIndex:=index
else
xItem.ImageIndex:=-1;
ico.Destroy;
end;
end;procedure TfrmEnumWindow.FormCreate(Sender: TObject);begin
//var
// h_SysImgList:integer;
// finfo:SHFileInfo;
// h_SysImgList := SHGetFileInfo('C:\',
// 0,
// fInfo,
// SizeOf(finfo),
// SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
// SendMessage(LV_Show.Handle,LVM_SETIMAGELIST,LVSIL_SMALL,h_SysImgList); mStrWinName:=TStringList.Create;
mStrClassName:=TStringList.Create;
mStrWinHandle:=TStringList.Create;end;end.谢谢不过
都不对,
我已经做出来了。
可有的窗体的ICON
我还是不能找到
一定是有的。
因为我按下ALT+TAB时有显示!参考:
MSDN Sendmessage中的WM_GETICON,
它道是说,ALT+TAB也是由它实现的