AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

How to handle window move?

Ein Thema von WojTec · begonnen am 31. Mai 2010 · letzter Beitrag vom 31. Mai 2010
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

How to handle window move?

  Alt 31. Mai 2010, 10:09
Hello. I need to save window position to restore it on next start. But how to handle this event? TForm has only OnResise, what about move?
  Mit Zitat antworten Zitat
pixfreak

Registriert seit: 6. Jul 2007
112 Beiträge
 
Delphi XE3 Professional
 
#2

Re: How to handle window move?

  Alt 31. Mai 2010, 10:43
Hi,

in the OnDestroy event just save your window position (Left, Top, Width, Height) and maybe your windowstate (maximized...) in a file, ini-file or in a registry key.

Thereafter in OnCreate read your values back and the window will be displayed at the same position...


VG Pixfreak

Edit: see Manipulate INI Files and store window pos
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: How to handle window move?

  Alt 31. Mai 2010, 12:03
Yap, I thought about this, but this is wrong idea, because if window is maximized, it has desktop size and position is (0, 0). Finally last position in wsNormal state can't be stored. Do you know solution for this problem?
  Mit Zitat antworten Zitat
blackfin
(Gast)

n/a Beiträge
 
#4

Re: How to handle window move?

  Alt 31. Mai 2010, 12:12
Maybe this helps?:


Delphi-Quellcode:
var
 rc: TRect;
..
.
// get position
GetWindowRect(self.Handle,rc);


// set position
MoveWindow(self.Handle,rc.left,rc.top,(rc.right-rc.left),(rc.bottom-rc.top),true) ;
  Mit Zitat antworten Zitat
fnhofm

Registriert seit: 16. Mär 2006
Ort: Nürnberg
25 Beiträge
 
Delphi XE2 Professional
 
#5

Re: How to handle window move?

  Alt 31. Mai 2010, 12:16
Hi,

you can use this code in the close or destroy event handler of the form (I used a TMemIniFile)

Delphi-Quellcode:
var
  LWindowPlacement: TWindowPlacement;
begin
  Ini.WriteInteger(Name, 'WindowState', Integer(WindowState));
  LWindowPlacement.length := SizeOf(TWindowPlacement);

  if GetWindowPlacement(Handle, LWindowPlacement) then
  begin
    Ini.WriteInteger(Name, 'Top', LWindowPlacement.rcNormalPosition.Top);
    Ini.WriteInteger(Name, 'Left', LWindowPlacement.rcNormalPosition.Left);
    Ini.WriteInteger(Name, 'Height',
      LWindowPlacement.rcNormalPosition.Bottom - LWindowPlacement.rcNormalPosition.Top);
    Ini.WriteInteger(Name, 'Width',
      LWindowPlacement.rcNormalPosition.Right - LWindowPlacement.rcNormalPosition.Left);
  end;
  Ini.UpdateFile;
end;
Hope this helps.
  Mit Zitat antworten Zitat
generic

Registriert seit: 24. Mär 2004
Ort: bei Hannover
2.415 Beiträge
 
Delphi XE5 Professional
 
#6

Re: How to handle window move?

  Alt 31. Mai 2010, 13:24
I'm using GetWindowPlacement and SetWindowPlacement, too.
The difference is, i'm storing the record "TWindowPlacement" to registry as binary stream.
This saves some keys.

There is a small pitfall. If the monitor configuration changes by removing a second monitor, then the windows will still restore on the old position (on that not available monitor).
The cause that the user isn't able to see or move the window.
Coding BOTT - Video Tutorials rund um das Programmieren - https://www.youtube.com/@codingbott
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#7

Re: How to handle window move?

  Alt 31. Mai 2010, 13:57
Method with GetWindowPlacement() is exactly what I need - thanks!
I also tried with WM_MOVE, but above solution is the best.

Thanks guys

-- Added ---

@generic, how to fix problem you talking about? I have one monitor, so I can't de facto test it
  Mit Zitat antworten Zitat
Benutzerbild von ChrisE
ChrisE

Registriert seit: 15. Feb 2006
Ort: Hechingen
504 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#8

Re: How to handle window move?

  Alt 31. Mai 2010, 14:23
Hello WojTec,

I think you test this with screen-resolutions. Because it's also possible that the resolution is changed. For example you stored your values at a resolution 1600x1200 and the program restarts at an resolution 1024x768.

I think you may check the values. If they are valid for the actual resolution / desctopssize you can set them. Otherwise you may set the position and size to default values.

Chris
Christian E.
Es gibt 10 Arten von Menschen, die die Binär lesen können und die die es nicht können

Delphi programming rules
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#9

Re: How to handle window move?

  Alt 31. Mai 2010, 15:42
Just check if the coordinates are out of bound and reset them to a default value if so. Storing the desktop resolution is overkill imo.
  Mit Zitat antworten Zitat
Antwort Antwort


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 16:52 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