获得桌面图标所在窗口--兼容Win7

来源:互联网 发布:java中的goto 编辑:程序博客网 时间:2024/05/14 03:18

Win7父窗口类名是 WorkerW,但是WorkerW有多个


function Find_Window(XParent: HWND; XFromIndex: Integer; const XClassNames: array of string): HWND;

var

  LName: string;

  LChild: HWND;

begin

  Result := XParent;

  if (XFromIndex < Low(XClassNames)) or (XFromIndex > High(XClassNames)) then

  begin

    Exit;

  end;


  LName := XClassNames[XFromIndex];

  LChild := 0;

  while True do

  begin

    LChild := FindWindowEx(XParent, LChild, PChar(LName), nil);

    if LChild = 0 then

    begin

      Result := 0;

      Exit;

    end;

    Result := Find_Window(LChild, XFromIndex + 1, XClassNames);

    if Result <> 0 then

      Exit;

  end;

end;


function FindDesktopIconWindow(var RetParent, RetChild: HWND): Boolean;

var

  LDesktop: HWND;

begin

  LDesktop := GetDesktopWindow;

  RetChild := Find_Window(LDesktop, 0, ['Progman', 'SHELLDLL_DefView', 'SysListView32']);

  if RetChild = 0 then

  begin

    RetChild := Find_Window(LDesktop, 0, ['WorkerW', 'SHELLDLL_DefView', 'SysListView32']);

  end;


  if RetChild <> 0 then

  begin

    RetParent := GetParent(GetParent(RetChild));

  end;


  Result := (RetChild <> 0) and (RetParent <> 0) and (RetParent <> LDesktop); 

end;

0 0
原创粉丝点击