⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitperesourceexplorerproperties.pas

📁 學習資料網上下載
💻 PAS
字号:
unit unitPEResourceExplorerProperties;

interface

uses Windows, Messages, Classes, SysUtils, Forms;

const
  WM_PROPERTIES_CHANGED = WM_USER + $30E;

type
  TPropertyEnum = (peShowToolbar, peShowStatusbar, peShowCoffSections);

  TPropertyType = (ptInteger, ptBool, ptString);

  TPropertyValue = record
    case tp : TPropertyType of
      ptInteger : (intVal : Integer);
      ptBool : (boolVal : boolean);
      ptString : (stringVal : string [64]);
  end;

  TPropertyRec = record
    name : string;
    value : TPropertyValue
  end;

const
  Properties : array [TPropertyEnum] of TPropertyRec = (
    (name : 'Show Toolbar';       value : (tp : ptBool; boolVal : True)),
    (name : 'Show Statusbar';     value : (tp : ptBool; boolVal : True)),
    (name : 'Show COFF Sections'; value : (tp : ptBool; boolVal : True)));

type
TPEResourceExplorerProperties = class
private
  fNotifyWindow : TForm;
  fUpdating : boolean;
  fValues : array [TPropertyEnum] of TPropertyValue;
  procedure Load;
  procedure Notify;
  function GetBoolPropertyValue (idx : TPropertyEnum) : boolean;
  procedure SetBoolPropertyValue(idx : TPropertyEnum; const Value : boolean);
public
  constructor Create (ANotifyWindow : TForm);
  procedure Save;

  property ShowToolbar : boolean index peShowToolbar           read GetBoolPropertyValue write SetBoolPropertyValue;
  property ShowStatusBar : boolean index peShowStatusbar       read GetBoolPropertyValue write SetBoolPropertyValue;
  property ShowCOFFSections : boolean index peShowCOFFSections read GetBoolPropertyValue write SetBoolPropertyValue;

  procedure BeginUpdate;
  procedure EndUpdate;
end;

implementation

uses Registry;

{ TPEResourceExplorerProperties }

procedure TPEResourceExplorerProperties.BeginUpdate;
begin
  fUpdating := True;
end;

constructor TPEResourceExplorerProperties.Create (ANotifyWindow : TForm);
var
  i : TPropertyEnum;
begin
  fNotifyWindow := ANotifyWindow;

  for i := Low (TPropertyEnum) to High (TPropertyEnum) do
    fValues [i] := Properties [i].value;

  Load
end;

procedure TPEResourceExplorerProperties.EndUpdate;
begin
  if fUpdating then
  begin
    fUpdating := False;
    Notify
  end
end;

function TPEResourceExplorerProperties.GetBoolPropertyValue(
  idx: TPropertyEnum): boolean;
begin
  result := fValues [idx].boolVal
end;

procedure TPEResourceExplorerProperties.Load;
var
  reg : TRegistry;
  i : TPropertyEnum;
begin
  reg := TRegistry.Create (KEY_READ);
  try
    if reg.OpenKey ('Software\Woozle\' + Application.Title + '\Properties', False) then
    begin
      BeginUpdate;
      try
        for i := Low (TPropertyEnum) to High (TPropertyEnum) do
          if reg.ValueExists (Properties [i].Name) then
            case Properties [i].value.tp of
              ptBool : fValues [i].boolVal := reg.ReadBool (Properties [i].Name);
              ptInteger : fValues [i].intVal := reg.ReadInteger (Properties [i].Name);
              ptString : fValues [i].stringVal := reg.ReadString (Properties [i].Name)
            end
      finally
        EndUpdate
      end
    end
  finally
    reg.Free
  end
end;

procedure TPEResourceExplorerProperties.Notify;
begin
  if not fUpdating then
    PostMessage (fNotifyWindow.Handle, WM_PROPERTIES_CHANGED, 0, 0)
end;

procedure TPEResourceExplorerProperties.Save;
var
  reg : TRegistry;
  i : TPropertyEnum;
begin
  reg := TRegistry.Create (KEY_READ or KEY_WRITE);
  try
    if reg.OpenKey ('Software\Woozle\' + Application.Title + '\Properties', True) then
    begin
      for i := Low (TPropertyEnum) to High (TPropertyEnum) do
         case Properties [i].value.tp of
           ptBool : reg.WriteBool (Properties [i].Name, fValues [i].boolVal);
           ptInteger : reg.WriteInteger (Properties [i].Name, fValues [i].intVal);
           ptString : reg.WriteString (Properties [i].Name, fValues [i].stringVal)
         end
    end
  finally
    reg.Free
  end
end;

procedure TPEResourceExplorerProperties.SetBoolPropertyValue(
  idx: TPropertyEnum; const Value: boolean);
begin
  if value <> fValues [idx].boolVal then
  begin
    fValues [idx].boolVal := Value;
    Save;
    Notify
  end
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -