Autor Beitrag
Premaider
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: So 25.03.12 16:03 
Hey Leute,
ich habe mir ein Programm geschrieben das mir ein gewünschtes Fenster in eine gewünschte Größe bringt.
Das Problem dabei ist das wenn man z.b. 1280x720 Pixel eingibt der Rahmen des Fensters mit dabei ist. Ich möchte das nur das Fenster 1280x720p hat und nicht Das Fenster+Rahmen. Wie stelle ich das mit GetSystemMetrics an ?
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 25.03.12 16:15 
Dafür musst Du nur ClientWidth und Clientheight setzen ...

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS

Für diesen Beitrag haben gedankt: Premaider
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: So 25.03.12 16:19 
Wie mache ich das ? Ich bin noch ein ziemlicher Anfänger :D
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 25.03.12 16:24 
Das sind Propertys des Forms, entweder im Objektinspektor, oder per Code Form1.Clientwidth := ....

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: So 25.03.12 16:27 
Es ändert aber ja nicht die Größe von Form1 sondern von externen Programmen wie Minecraft oder so :D
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 25.03.12 18:32 
Schau einfach mal in die Doku: ;-)
msdn.microsoft.com/e...esktop/ms724385.aspx
Nun musst du nur noch wissen (oder abfragen) was für ein Rand das Fenster hat, dann kannst du den entsprechenden Wert abfragen, z.B.:
Zitat:
SM_CXFIXEDFRAME
7
The thickness of the frame around the perimeter of a window that has a caption but is not sizable, in pixels. SM_CXFIXEDFRAME is the height of the horizontal border, and SM_CYFIXEDFRAME is the width of the vertical border.
This value is the same as SM_CXDLGFRAME.
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: So 25.03.12 20:26 
Nur irgendwie muss ich die ja von einander abziehen.

Oder wäre das dann z.b. "SM_CYBORDER + 1280" und "SM_CYBORDER + 720" ?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 25.03.12 20:33 
user profile iconPremaider hat folgendes geschrieben Zum zitierten Posting springen:
Oder wäre das dann z.b. "SM_CYBORDER + 1280" und "SM_CYBORDER + 720" ?
Wenn du mit SM_CYBORDER das Ergebnis der Funktion GetSystemMetrics mit diesem Parameter meinst, dann fast ja.

Überlege dir zusätzlich einmal ganz genau wofür das Y stehen könnte. :zwinker:
Und wenn es dir nicht klar ist, schau in die Doku...
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: So 25.03.12 21:22 
Aber wenn man
GetSystemMetrics(SM_CYBORDER);
hat gibt es doch kein :=
In welcher Art und Weise hat man da ein Ergebnis ?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 25.03.12 22:08 
Hmm, vielleicht solltest du dir erst einmal anschauen wie Funktionsaufrufe überhaupt funktionieren...
www.delphi-treff.de/...uren-und-funktionen/

user profile iconPremaider hat folgendes geschrieben Zum zitierten Posting springen:
Aber wenn man
GetSystemMetrics(SM_CYBORDER);
hat gibt es doch kein :=
Wenn man das Ergebnis nirgends zuweisen will, braucht man das auch nicht. Irgendetwas musst du mit dem Wert aber machen. Ob du den nun in eine Variable packst oder direkt damit rechnest, musst du schon selbst schreiben.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  BorderHeight: Integer;
begin
  BorderHeight := GetSystemMetrics(SM_CYBORDER);
// oder direkt benutzen:
  ShowMessage('Höhe mit Rand: ' + IntToStr(720 + GetSystemMetrics(SM_CYBORDER)));
// ...

Für diesen Beitrag haben gedankt: Premaider
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 26.03.12 17:06 
Also bei mir sieht es jetzt so aus.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
 HWND:THandle;
 Width:Integer;
 Height:Integer;
begin
  Width:= 1280 + GetSystemMetrics(SM_CXBORDER);
  Height:= 720 + GetSystemMetrics(SM_CYBORDER);
  HWND := FindWindow(nil, PChar(Edit1.Text));
  SetWindowPos(HWND,HWND_TOPMOST,0,0,Width,Height,SWP_NOMOVE);
end;


Aber es ist immernoch 1862x682 Pixel :(
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 26.03.12 17:46 
Width und Height sind relativ ungünstige Bezeichner, da es die schon als Eigenschaften des Formulars gibt.

Davon abgesehen:
Was sagt denn der Debugger? Stimmen Breite und Höhe? Bekommst du ein Handle (wird das Fenster also gefunden)?
Zudem:
Wie wäre es mit Fehlerbehandlung? Abfragen, ob das Handle gültig ist (ungleich INVALID_HANDLE_VALUE), Rückgabewert von SetWindowPos nicht einfach wegwerfen, ...
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 26.03.12 17:51 
Das Fenster wird gefunden alles funktioniert auch, nur es wird in 1262x682 Pixel anstatt 1280x720 Pixel gesetzt. Also der Rand des Fensters wurde nicht dazugezählt.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 26.03.12 18:15 
Was gibt SetWindowPos denn zurück und welchen Wert hatte das Handle z.B.?
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 26.03.12 18:41 
Wie kann ich das herrausfinden ? Meine eben mit meiner "Aussage" das, dass das Fenster sich in der Größe ändert :D
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mo 26.03.12 19:08 
Kannst Du das Zielfenster manuell größer ziehen, wenn da Constraints definiert sind ist es Essig.

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 26.03.12 19:10 
Ja kann man manuell größer machen. Ist Minecraft :D
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 26.03.12 19:11 
Wie wäre es mit Haltepunkte setzen? Dann noch die Maus über die Variable mit dem Handle halten, wenn das Programm dort ankommt. Oder Strg + F7 drücken und direkt den Namen der Variablen zur Auswertung eingeben. Hier steht ein wenig dazu:
www.delphi-treff.de/...s-delphi-7/debugger/

Und den Rückgabewert kannst du ja auch direkt abfragen und z.B. mit ShowMessage und BoolToStr ausgeben.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 26.03.12 19:18 
Überleg doch mal, was du hier tust :zwinker: Nehmen wir mal dieses Bild.
aerowin

Rot markiert ist der Teil, dessen Größe du auf 1280x720 setzen möchtest.
"Außen" ist das, dessen Größe SetWindowPos ändert. Da ist also was übrig, nämlich:
ausblenden Quelltext
1:
2:
3:
4:
- Rahmen links   = GetSystemMetrics(SM_CXBORDER)
- Rahmen rechts  = GetSystemMetrics(SM_CXBORDER)
- Rahmen unten   = GetSystemMetrics(SM_CYBORDER)
- Fenstertitel   = GetSystemMetrics(SM_CYCAPTION)


Wie groß ist also dein Fenster außen?

ausblenden Delphi-Quelltext
1:
2:
Breite:= 1280 + 2 * GetSystemMetrics(SM_CXBORDER);
Höhe:= 720 + GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYCAPTION);


Eventuell kommt auf die Höhe noch ein SM_CYBORDER drauf, bin mir aber nicht sicher ob das nicht vielleicht schon in SM_CYCAPTION mitgezählt wird.
Einloggen, um Attachments anzusehen!
_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Premaider Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 26.03.12 19:27 
Sorry, das funktioniert auch nicht. Ich habe euch mal die Projektdatein hochgeladen. Vielleicht habe ich einfach einen Fehler den ich nicht finde.

P.S. Ist es möglich, dass mein Programm nicht diesen Windows 98 Stil hat sondern so wie es vom Betriebssystem vorgesehen ist ?
(Habs hinbekommen :D) Liegt es vllt an Delphi 7 ??
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von Premaider am Mo 26.03.12 20:19, insgesamt 1-mal bearbeitet