Einzelnen Beitrag anzeigen

Benutzerbild von Cylence
Cylence

Registriert seit: 2. Sep 2004
Ort: Allgäu
246 Beiträge
 
Delphi 7 Enterprise
 
#3

AW: Taskbar Programm-Einträge auslesen

  Alt 21. Mär 2012, 15:00
Ich selbst habs mal wo mit twindowlist gemacht, ein popupmenü mit dem ich die items die in der taskleiste sind anzeige...

Delphi-Quellcode:



procedure TMainform.GetTasks;
label nxt;
var
  win1:TWindowList;
  tx1,tx2:Integer;
  upd1:Boolean;
  ts1,hwnd1,
  old_map: TStringList;
  PrgIcon : HIcon;
  XIcon : TIcon;
  IcOBMP, EcoBMP : TBitmap;
  NewMenuItem : TMenuitem;
  function sendmsg(Handle : HWND; Msg : Cardinal; wParam, lParam : Integer):Cardinal;
  begin
    SendMessageTimeout(Handle,Msg,wParam,lParam, SMTO_ABORTIFHUNG, 500, Result);
  end;
begin
  win1:=TWindowList.Create(self);
  ts1:=TStringList.Create;
  hwnd1:=TStringList.Create;
  old_map := TStringList.Create;
  try
    upd1:=false;
    for tx1:=0 to win1.Count-1 do begin
      if win1.Windows[tx1].IsVisible and win1.Windows[tx1].IsEnabled and IsMainAppWindow(win1.Windows[tx1].WinHandle) then begin
        hwnd1.Add(Inttostr(win1.Windows[tx1].WinHandle));
        ts1.Add(win1.Windows[tx1].WinCaption);
      end;
    end;
    if hwnd1.Count = 0 then begin
       win1.Free;
       ts1.free;
       hwnd1.Free;
       old_map.Free;
       Exit;
    end;
    for tx1:=0 to hwnd1.Count-1 do begin
    if old_map.IndexOf(hwnd1.Strings[tx1])=-1 then begin
      old_map.Clear;
      for tx2:=0 to hwnd1.Count -1 do old_map.Add(hwnd1.Strings[tx2]);
      upd1:=true;
      goto nxt;
      end;
    end;
    for tx1:=0 to old_map.Count-1 do begin
      if hwnd1.IndexOf(old_map.Strings[tx1])=-1 then begin
        old_map.Clear;
        for tx2:=0 to hwnd1.Count -1 do old_map.Add(hwnd1.Strings[tx2]);
      upd1:=true;
      goto nxt;
      end;
    end;
    for tx1:=0 to hwnd1.Count-1 do begin
      if not(hwnd1.Strings[tx1]=old_map.Strings[tx1]) then begin
        old_map.Clear;
        for tx2:=0 to hwnd1.Count -1 do old_map.Add(hwnd1.Strings[tx2]);
        upd1:=true;
        goto nxt;
      end;
    end;
    nxt:if upd1 then begin
       TasksMenu.Items.Clear;
       for tx1 := 0 to ts1.Count - 1 do begin
          NewMenuItem := TMenuitem.Create(TasksMenu);
          NewMenuItem.Caption := ts1.Strings[tx1];
          NewMenuItem.Tag := tx1;
          NewMenuItem.Hint := hwnd1.Strings[tx1];
          NewMenuItem.OnClick := TaskItemClick;
          NewMenuItem.Visible := True;
          NewMenuItem.ImageIndex := 25;
          XIcon := TIcon.Create;
          IcOBMP := TBitmap.Create;
          EcoBMP := TBitmap.Create;
          try
            PrgIcon := sendmsg(StrToInt(hwnd1.Strings[tx1]), WM_GETICON, ICON_SMALL2, 0);
            if PrgIcon = 0 then PrgIcon := sendmsg(StrToInt(hwnd1.Strings[tx1]), WM_GETICON, ICON_SMALL, 0);
            if PrgIcon <> 0 then begin
                XIcon.Handle := PrgIcon;
                IcOBMP.Width:= XIcon.Width;
                IcOBMP.Height:= XIcon.Height;
                IcOBMP.Canvas.Draw(0, 0, XIcon);
                EcoBMP.Height := 32;
                EcoBMP.Width := 32;
                EcoBMP.Canvas.StretchDraw(Rect(0,0,32,32),IcoBMP);
                EcoBMP.Height := 16;
                EcoBMP.Width := 16;
                try
                  NewMenuItem.Bitmap := EcOBMP;
                except

                end;
            end;
            NewMenuItem.ImageIndex := -1;
          finally
            XIcon.Free;
            IcOBMP.Free;
            EcoBMP.Free;
          end;
          TasksMenu.Items.Add(NewMenuItem);
       end;
    end;
  finally
    win1.Free;
    ts1.free;
    hwnd1.Free;
    old_map.Free;
  end;
end;
Tom
Just DO it
  Mit Zitat antworten Zitat