AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Monitore und dessen Positionen anzeigen (Bildschirmanordnung)
Thema durchsuchen
Ansicht
Themen-Optionen

Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

Ein Thema von dGeek · begonnen am 18. Feb 2015 · letzter Beitrag vom 19. Feb 2015
Antwort Antwort
Seite 3 von 3     123   
dGeek
(Gast)

n/a Beiträge
 
#21

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

  Alt 18. Feb 2015, 22:12
Nein. Ich habe nur ein kleines Fenster und da möchte ich kleine Shapes reinpacken welche die Monitore darstellen sollen.
Das mit der Größe habe ich hinbekommen. Das mit dem Minisbereich nicht.
  Mit Zitat antworten Zitat
dGeek
(Gast)

n/a Beiträge
 
#22

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

  Alt 18. Feb 2015, 22:47
Ok also ich habe wirklich Eigeninitiative gezeigt und lasse mir nicht alles vorkauen.

Aber nun bin ich am Ende und besser bekomme ich es nicht hin.
(Einfach in eine Form packen die etwa 500px hoch und 400p breit ist).

Wenn mir nun noch jemand helfen könnte die Skalierung richtig hinzubekommen sodass alle Monitore (Shapes) richtig auf der Form angezeigt werden können, wäre ich sehr dankbar.

Delphi-Quellcode:
procedure TForm2.FormShow(Sender: TObject);
const
  aScale = 7;
var
  p: TPoint;
  iMostTop, iPrimaryX, iPrimaryY, iPrimary, i: Integer;
  aShape: TShape;
  aLabel: TLabel;
  procedure drawScreen(iMonCnt: Integer; bPrimary: Boolean = False);
  begin
    p := Point(Screen.Monitors[iMonCnt].Left, Screen.Monitors[iMonCnt].Top);

    if Assigned((FindComponent('aScreen' + IntToStr(iMonCnt + 1)) as TShape)) then
      (FindComponent('aScreen' + IntToStr(iMonCnt + 1)) as TShape).Free;

    aShape := TShape.Create(Self);
    aShape.Parent := Self;
    aShape.Name := 'aScreen' + IntToStr(iMonCnt + 1);
    aShape.Anchors := [];

    aShape.Width := prozentwert(Screen.Monitors[iMonCnt].Width, aScale);
    aShape.Height := prozentwert(Screen.Monitors[iMonCnt].Height, aScale);

    if bPrimary then
    begin
      aShape.Left := (Self.Width div 2) - (aShape.Width div 2);
      aShape.Top := iMostTop; // (Self.Height div 2) - (aShape.Height div 2);
      iPrimaryX := aShape.Left;
      iPrimaryY := aShape.Top;
    end
    else
    begin
      aShape.Left := prozentwert(p.X, aScale) + iPrimaryX;
      aShape.Top := prozentwert(p.Y, aScale) + iPrimaryY;
    end;

    if Assigned((FindComponent('aLabel' + IntToStr(iMonCnt + 1)) as TLabel)) then
      (FindComponent('aLabel' + IntToStr(iMonCnt + 1)) as TLabel).Free;

    aLabel := TLabel.Create(Self);
    aLabel.Parent := Self;
    aLabel.Name := 'aLabel' + IntToStr(iMonCnt + 1);
    aLabel.Anchors := aShape.Anchors;
    aLabel.Font.Size := -13;
    aLabel.Font.Style := [fsBold];
    aLabel.AutoSize := False;
    aLabel.Left := aShape.Left + 1;
    aLabel.Top := aShape.Top + (aShape.Height div 2) - (aLabel.Height div 2);
    aLabel.Width := aShape.Width - 2;
    aLabel.Alignment := taCenter;
    aLabel.Caption := IntToStr(iMonCnt + 1);
    aLabel.Visible := True;
    aLabel.BringToFront;

    Repaint;
  end;

begin
  iMostTop := 0;
  for i := 0 to Screen.MonitorCount - 1 do
  begin
    if Screen.Monitors[i].Top < iMostTop then
      iMostTop := Screen.Monitors[i].Top;
  end;
  iMostTop := iMostTop + 20;

  for i := 0 to Screen.MonitorCount - 1 do
  begin
    if Screen.Monitors[i].Primary then
    begin
      iPrimary := i;
      drawScreen(i, True);
      break;
    end;
  end;

  for i := 0 to Screen.MonitorCount - 1 do
  begin
    if i = iPrimary then
      Continue;

    drawScreen(i);
  end;
end;
  Mit Zitat antworten Zitat
BadenPower

Registriert seit: 17. Jun 2009
616 Beiträge
 
#23

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

  Alt 18. Feb 2015, 23:13
Die Funktion "prozentwert()" fehlt.
Programmieren ist die Kunst aus Nullen und Einsen etwas sinnvollen zu gestalten.
Der bessere Künstler ist allerdings der Anwender, denn dieser findet Fehler, welche sich der Programmierer nicht vorstellen konnte.
  Mit Zitat antworten Zitat
dGeek
(Gast)

n/a Beiträge
 
#24

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

  Alt 19. Feb 2015, 02:22
Delphi-Quellcode:
function prozentwert(i, p: Integer): Integer;
begin
 Result := (i div 100) * p;
end;
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.115 Beiträge
 
Delphi 12 Athens
 
#25

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

  Alt 19. Feb 2015, 09:28
10% von 290 sind?

20
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
BadenPower

Registriert seit: 17. Jun 2009
616 Beiträge
 
#26

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

  Alt 19. Feb 2015, 10:43
Kleines Quick 'n Dirty:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, Forms, Classes, Controls, ComCtrls, ExtCtrls, StdCtrls, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure MonitorPanelResize(Sender: TObject);
  private
    procedure ShowMonitors();
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses
  SysUtils, Math;


{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  liZ1: Integer;
  lPanel: TPanel;
begin
  Position := poScreenCenter;
  Color := $444444;
  lPanel := TPanel.Create(Self);
  lPanel.Parent := Self;
  lPanel.Name := 'MonitorPanel';
  lPanel.Caption := '';
  lPanel.ParentBackground := true;
  lPanel.BevelOuter := bvNone;
  lPanel.AlignWithMargins := true;
  lPanel.Margins.SetBounds(10,10,10,10);
  lPanel.Align := alClient;
  lPanel.OnResize := MonitorPanelResize;
  ShowMonitors();
end;

procedure TForm1.MonitorPanelResize(Sender: TObject);
begin
  ShowMonitors();
end;

procedure TForm1.ShowMonitors();
var
  liZ1: Integer;
  lScaleFactor: Extended;
  lOffsetX: Integer;
  lOffsetY: Integer;
  lPanel: TPanel;
  lParentPanel: TPanel;
begin
  lParentPanel := TPanel(Self.FindComponent('MonitorPanel'));

  for liZ1 := lParentPanel.ControlCount - 1 downto 0 do
   begin
    lParentPanel.Controls[liZ1].Free;
   end;

  lScaleFactor := Min(lParentPanel.Width / Screen.DesktopWidth,lParentPanel.Height / Screen.DesktopHeight);
  lOffsetX := Round(Screen.DesktopLeft * lScaleFactor);
  lOffsetY := Round(Screen.DesktopTop * lScaleFactor);

  for liZ1 := 0 to Screen.MonitorCount - 1 do
   begin
    lPanel := TPanel.Create(lParentPanel);
    lPanel.Parent := lParentPanel;
    lPanel.ParentBackground := false;
    lPanel.Color := $888888;
    lPanel.BevelInner := bvLowered;
    lPanel.BevelWidth := Max(Round(10 * lScaleFactor),1);
    lPanel.Caption := IntToStr(Screen.Monitors[liZ1].MonitorNum + 1);
    lPanel.Top := Round(Screen.Monitors[liZ1].Top * lScaleFactor) - lOffsetY;
    lPanel.Left := Round(Screen.Monitors[liZ1].Left * lScaleFactor) - lOffsetX;
    lPanel.Height := Round(Screen.Monitors[liZ1].Height * lScaleFactor);
    lPanel.Width := Round(Screen.Monitors[liZ1].Width * lScaleFactor);
    lPanel.Font.Size := Max(lPanel.Height div 2,8);
   end;

end;

end.
EDIT:
Programmieren ist die Kunst aus Nullen und Einsen etwas sinnvollen zu gestalten.
Der bessere Künstler ist allerdings der Anwender, denn dieser findet Fehler, welche sich der Programmierer nicht vorstellen konnte.

Geändert von BadenPower (19. Feb 2015 um 15:37 Uhr) Grund: Kleine verbesserte Version
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 3 von 3     123   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz