Zero code save window running status

zhaozj2021-02-11  163

Zero code save window running status

Some professional software have functions of automatically saving the window running status, and the specific methods are saved in the registry before the window is closed or in the INI file, which is generally the same, so they can Concentrated together, reuse. This article implements the corresponding code with a control tposition. As long as you put this control on the corresponding FORM, you don't need to add any code, thereby implementing the "zero" code saving window running status. Below is the content of this control main implementation file Position.PAS, including the corresponding annotation. In order to keep the registry neat, save the information into the INI file. unit Position; interface uses Forms, Classes, SysUtils, Windows, IniFiles; type // TPosition is not a visual control by TComponent inherited TPosition = class (TComponent) private // Use this variable holds the parent window OnDestroy event FOnDestroy: TNotifyEvent; / / replace the parent window with this function OnDestroy event procedure FormDestroy (Sender: TObject); protected // restore state procedure loaded parent window when the control is loaded; override; end; // window position restoration function procedure ReadFormPos (Form: TForm); / / Save Window Location Function Procedure SaveFormpos (Form: TForm); // Control Registration Function Procedure Register; IMPLEMentation // Connect the icon of this control {$ R position.dcr} // Restore window location function, window status is stored in the INI file in.

Procedure ReadFormpos (form: tform); Var Regfile: Tinifile; SectName: String; Segment name name of FORM information in the Begin // INI file SectName: = form.name 'Position'; // Open the same name INI file regfile: = tinifile.create (CHANGEFILEXENAME, '. INI')); // Restore Window State with form do begin left: = regfile.readinteger (SectName, 'Left', Left); top: = RegFile.ReadInteger (SectName, 'Top', Top); Width: = RegFile.ReadInteger (SectName, 'Width', Width); Height: = RegFile.ReadInteger (SectName, 'Height', Height); WindowState: = TWindowState ( Regfile.readinteger (SECTNAME, 'WindowsTate', 0)); END; // Turns off INI file regfile.free; end; // Save window location function Procedure SaveFormPos (Form: TForm); Var Reglet: tinifile; SECTNAME: STRING; begin SectName: = Form.Name 'Position'; RegFile: = TIniFile.Create (ChangeFileExt (Application.ExeName,) 'ini.'); with Form do begin RegFile.WriteInteger (SectName, 'WindowState', integer (WindowState) ); // When maximizing, the window position IF windowState <> wsmaximized the beginning is reguous.writeinteger (SectName, 'L) EFT ', LEFT); Regfile.WriteInteger (SectName,' TOP ', TOP); Regfile.WriteInteger (SectName,' Width ', Width); Regfile.WriteInteger (SectName,' Height ', Height); End; // The window to be saved is to handle when the window is a program owner window. Because the main window receives the minimum message, just turn this message to the Application process, it is not minimized. So we want to judge the status of Application.

转载请注明原文地址:https://www.9cbs.com/read-5474.html

New Post(0)