Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Monitore und dessen Positionen anzeigen (Bildschirmanordnung) (https://www.delphipraxis.net/184002-monitore-und-dessen-positionen-anzeigen-bildschirmanordnung.html)

dGeek 18. Feb 2015 22:12

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)
 
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.

dGeek 18. Feb 2015 22:47

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)
 
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;

BadenPower 18. Feb 2015 23:13

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)
 
Die Funktion "prozentwert()" fehlt.

dGeek 19. Feb 2015 02:22

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)
 
Delphi-Quellcode:
function prozentwert(i, p: Integer): Integer;
begin
 Result := (i div 100) * p;
end;

himitsu 19. Feb 2015 09:28

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)
 
10% von 290 sind?

20 :roll:

BadenPower 19. Feb 2015 10:43

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)
 
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:


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:14 Uhr.
Seite 3 von 3     123   

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