Einzelnen Beitrag anzeigen

Assertor

Registriert seit: 4. Feb 2006
Ort: Hamburg
1.296 Beiträge
 
Turbo C++
 
#15

Re: Vollständige Sichtbarkeit eines Forms

  Alt 8. Sep 2009, 10:22
Hi Himitsu,

Zitat von himitsu:
vorallem das rausbekommen wäre für mich interessant,

obwohl mir da grad ein Gedankenblitz gekommen ist
- bei Beenden Form ausblenden (Hide), wiederherstellen (demaximieren ) und dann die Werte auslesen.
Lol, ja das wäre auch ein Lösung. Nicht geeignet für Epileptiker

Hier aus meinem Nähkästchen:
Delphi-Quellcode:
procedure SaveWindowState(AConfigFile: TXMLConfig;
  AForm: TForm; const Section: UnicodeString;
  const AllowMinimize: Boolean = False;
  const AdjustNonClientHeight: Integer = 0);
var
  p: TWindowPlacement;
  r: TRect;
begin
  Assert(AConfigFile <> nil);
  Assert(AForm <> nil);
  with AConfigFile do begin
    if (AForm.WindowState <> wsMinimized) or (AllowMinimize) then
    begin
      {
        calculate window's normal size and position using Windows API call -
        the form's Width, Height, Top and Left properties will give maximized
        window size if form is maximized, which is not what we want here.

        AdjustNonClientHeight is used to support libraries like DevExpress
        Ribbon components which adjust the form size after loading to support
        drawing in glass/nonclient area under Vista.
      }

      p.length := SizeOf(TWindowPlacement);
      if not (GetWindowPlacement(AForm.Handle, @p)) then
      begin
        AppLog.Log(evtError, {$IFDEF UNICODE}Format{$ELSE}UnicodeFormat{$ENDIF}(
          SWindowPositionGetError, [SysErrorMessage(GetLastError)]));
      end
      else
      begin
        r := p.rcNormalPosition;
        WriteInteger(Section, 'Left', r.Left);
        WriteInteger(Section, 'Top', r.Top);
        WriteInteger(Section, 'Width', r.Right - r.Left);
        if AdjustNonClientHeight = 0 then
          WriteInteger(Section, 'Height', r.Bottom - r.Top)
        else
          WriteInteger(Section, 'Height', r.Bottom - r.Top +
            AdjustNonClientHeight);
      end;
    end;
    case AForm.WindowState of
      wsMinimized: if AllowMinimize then
                      WriteString(Section, 'WindowState', 'Minimized');
      wsMaximized: WriteString(Section, 'WindowState', 'Maximized');
    else
      WriteString(Section, 'WindowState', 'Normal'); // wsNormal
    end;
  end;
end;
Ist so aus einer meiner Units und wird so nicht kompilieren, aber die Idee sollte rüberkommen: TWindowPlacement.rcNormalPosition ist die einfachste Lösung dafür.

Beim Laden dann umgekehrt:
Delphi-Quellcode:
[Pseudocode]
    // try to load saved window positions (even if maximized to preserve size)
    if ValueExists(Section, 'Left') or ValueExists(Section, 'Top') or
       ValueExists(Section, 'Width') or ValueExists(Section, 'Height') then
    begin
      // all values or at least one of them
      x1 := ReadInteger(Section, 'Left', AForm.Left);
      y1 := ReadInteger(Section, 'Top', AForm.Top);
      x2 := ReadInteger(Section, 'Width', AForm.Width);
      y2 := ReadInteger(Section, 'Height', AForm.Height);
      // do the positions differ from current position?
      if (x1 <> AForm.Left) or (x2 <> AForm.Width) or
         (y1 <> AForm.Top) or (y2 <> AForm.Height) then
      begin
        AForm.SetBounds(x1, y1, x2, y2);
      end;
    end
    else
    begin
      // center form (with default size e.g. 80%) if values are not found
      CenterFormToMonitor(AForm);
    end;

    // always check if the current form fits into monitor/desktop area
    FitFormFullInView(AForm);

    // load window state
    // Setzte AForm.WindowState auf wsMaximized, wsNormal
    // (oder wsMinimized wenn wir das erlauben wollen)
Gruß Assertor
Frederik
  Mit Zitat antworten Zitat