From 810bf694b3bfe5624c9ed94d43f00d4cba81c5cc Mon Sep 17 00:00:00 2001 From: Nikolaos Georgiou Date: Mon, 5 Sep 2022 22:06:21 +0200 Subject: [PATCH] refactor: Hide implementation details of StrConsts --- .editorconfig | 2 +- .gitignore | 1 + Chameleon.lpi | 113 +++++++++++++++++++++++++------------------------- Chameleon.res | Bin 2428 -> 2472 bytes StrConsts.pas | 31 +++++++++++++- frmMain.lfm | 13 ++---- frmMain.pas | 62 ++++++++++++++++++++------- 7 files changed, 140 insertions(+), 82 deletions(-) diff --git a/.editorconfig b/.editorconfig index fc0c23f..0424b4f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ root = true [*] charset = utf-8 indent_style = space -indent_size = 4 +indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true max_line_length = 120 diff --git a/.gitignore b/.gitignore index fe50c4d..4a993a0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ *.compiled *.bak *.lps +backup/ diff --git a/Chameleon.lpi b/Chameleon.lpi index 7f51ee9..b722d2a 100644 --- a/Chameleon.lpi +++ b/Chameleon.lpi @@ -1,124 +1,125 @@ - - + + - - - + + + + - - - - <UseAppBundle Value="False" /> - <ResourceType Value="res" /> - <UseXPManifest Value="True" /> + <SessionStorage Value="InProjectDir"/> + <Title Value="Chameleon"/> + <UseAppBundle Value="False"/> + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> <XPManifest> - <DpiAware Value="True" /> + <DpiAware Value="True"/> </XPManifest> </General> <i18n> - <EnableI18N LFM="False" /> + <EnableI18N LFM="False"/> </i18n> <VersionInfo> - <UseVersionInfo Value="True" /> - <AutoIncrementBuild Value="True" /> - <RevisionNr Value="0" /> - <BuildNr Value="2" /> - <MajorVersionNr Value="0" /> - <MinorVersionNr Value="1" /> + <UseVersionInfo Value="True"/> + <AutoIncrementBuild Value="True"/> + <MinorVersionNr Value="1"/> + <BuildNr Value="2"/> </VersionInfo> <BuildModes Count="1"> - <Item1 Name="Default" Default="True" /> + <Item1 Name="Default" Default="True"/> </BuildModes> <PublishOptions> - <Version Value="2" /> + <Version Value="2"/> </PublishOptions> <RunParams> - <FormatVersion Value="2" /> + <FormatVersion Value="2"/> <Modes Count="1"> - <Mode0 Name="default" /> + <Mode0 Name="default"/> </Modes> </RunParams> <RequiredPackages Count="1"> <Item1> - <PackageName Value="LCL" /> + <PackageName Value="LCL"/> </Item1> </RequiredPackages> <Units Count="7"> <Unit0> - <Filename Value="Chameleon.lpr" /> - <IsPartOfProject Value="True" /> + <Filename Value="Chameleon.lpr"/> + <IsPartOfProject Value="True"/> </Unit0> <Unit1> - <Filename Value="frmMain.pas" /> - <IsPartOfProject Value="True" /> - <ComponentName Value="MainForm" /> - <HasResources Value="True" /> - <ResourceBaseClass Value="Form" /> + <Filename Value="frmMain.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="MainForm"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> </Unit1> <Unit2> - <Filename Value="frmResults.pas" /> - <IsPartOfProject Value="True" /> - <ComponentName Value="Results" /> - <HasResources Value="True" /> - <ResourceBaseClass Value="Form" /> + <Filename Value="frmResults.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Results"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> </Unit2> <Unit3> - <Filename Value="Writers.pas" /> - <IsPartOfProject Value="True" /> + <Filename Value="Writers.pas"/> + <IsPartOfProject Value="True"/> </Unit3> <Unit4> - <Filename Value="DfmEngine.pas" /> - <IsPartOfProject Value="True" /> + <Filename Value="DfmEngine.pas"/> + <IsPartOfProject Value="True"/> </Unit4> <Unit5> - <Filename Value="StrConsts.pas" /> - <IsPartOfProject Value="True" /> + <Filename Value="StrConsts.pas"/> + <IsPartOfProject Value="True"/> </Unit5> <Unit6> - <Filename Value="about1.pas" /> - <IsPartOfProject Value="True" /> - <ComponentName Value="AboutBox" /> - <HasResources Value="True" /> - <ResourceBaseClass Value="Form" /> + <Filename Value="about1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="AboutBox"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> </Unit6> </Units> </ProjectOptions> <CompilerOptions> - <Version Value="11" /> - <PathDelim Value="\" /> + <Version Value="11"/> + <PathDelim Value="\"/> <SearchPaths> - <IncludeFiles Value="$(ProjOutDir)" /> + <IncludeFiles Value="$(ProjOutDir)"/> </SearchPaths> <Parsing> <SyntaxOptions> - <SyntaxMode Value="Delphi" /> + <SyntaxMode Value="Delphi"/> </SyntaxOptions> </Parsing> <Linking> + <Debugging> + <DebugInfoType Value="dsDwarf2Set"/> + </Debugging> <Options> <Win32> - <GraphicApplication Value="True" /> + <GraphicApplication Value="True"/> </Win32> </Options> </Linking> <Other> - <CustomOptions Value="-dBorland -dVer150 -dDelphi7 -dCompiler6_Up -dPUREPASCAL" /> + <CustomOptions Value="-dBorland -dVer150 -dDelphi7 -dCompiler6_Up -dPUREPASCAL"/> </Other> </CompilerOptions> <Debugging> <Exceptions Count="3"> <Item1> - <Name Value="EAbort" /> + <Name Value="EAbort"/> </Item1> <Item2> - <Name Value="ECodetoolError" /> + <Name Value="ECodetoolError"/> </Item2> <Item3> - <Name Value="EFOpenError" /> + <Name Value="EFOpenError"/> </Item3> </Exceptions> </Debugging> diff --git a/Chameleon.res b/Chameleon.res index 0d06996e1b386690e8d9dcafccc36ec6dc0031a9..a0c2e16f2399e07a76336c19016a61a4959c4a7a 100644 GIT binary patch delta 80 zcmew(v_g1-0^@^?ic{HC6l`+x^U?znOEMhG6N^&q(h_ruQ*HE71ShXybDR8yEr6Yo Zfq{XEfnl;Y`$two20aFY&5j(_i~xj-8EOCk delta 46 zcmZ1>{6}bl0^_EQic{GpKVh?BVqlo8z#hQP00c}7Oq0vmKe8Gy=rI^=&gHOX1OPWH B3uOQR diff --git a/StrConsts.pas b/StrConsts.pas index e34fef1..f1301f3 100644 --- a/StrConsts.pas +++ b/StrConsts.pas @@ -4,6 +4,13 @@ unit StrConsts; interface +uses Classes; + +function GetWindowStyleNames(style: Integer): TStringList; +function GetExtendedWindowStyleNames(style: Integer): TStringList; + +implementation + uses Windows; const @@ -101,6 +108,28 @@ const 'Transparent', 'Raised edge'); -implementation +function GetWindowStyleNames(style: Integer): TStringList; +var + list: TStringList; + i: Integer; +begin + list := TStringList.Create(); + for i := Low(WindowStyle) to High(WindowStyle) do + if ((style and WindowStyle[i]) = WindowStyle[i]) then + list.Add(WindowStyleName[i]); + Result := list; +end; + +function GetExtendedWindowStyleNames(style: Integer): TStringList; +var + list: TStringList; + i: Integer; +begin + list := TStringList.Create(); + for i := Low(ExtendedWindowStyle) to High(ExtendedWindowStyle) do + if ((style and ExtendedWindowStyle[i]) = ExtendedWindowStyle[i]) then + list.Add(ExtendedWindowStyleName[i]); + Result := list; +end; end. diff --git a/frmMain.lfm b/frmMain.lfm index a056717..c44b773 100644 --- a/frmMain.lfm +++ b/frmMain.lfm @@ -11,14 +11,13 @@ object MainForm: TMainForm Font.Color = clWindowText Font.Height = -14 Font.Name = 'Tahoma' - LCLVersion = '2.0.6.0' + LCLVersion = '2.2.0.4' object lblDelayTime: TLabel Left = 21 Height = 17 Top = 11 Width = 168 Caption = 'Time until restoring control:' - ParentColor = False end object Label1: TLabel Left = 273 @@ -26,14 +25,12 @@ object MainForm: TMainForm Top = 11 Width = 32 Caption = 'msec' - ParentColor = False end object DelayTime: TSpinEdit Left = 206 Height = 25 Top = 11 Width = 63 - MaxValue = 0 TabOrder = 0 Value = 3000 end @@ -60,7 +57,6 @@ object MainForm: TMainForm Width = 78 Caption = 'HWND value' Enabled = False - ParentColor = False end object Information: TButton Left = 21 @@ -114,7 +110,6 @@ object MainForm: TMainForm Top = 11 Width = 81 Caption = 'Unit file name' - ParentColor = False end object Label4: TLabel Left = 21 @@ -122,7 +117,6 @@ object MainForm: TMainForm Top = 80 Width = 70 Caption = 'Form name' - ParentColor = False end object PasFileName: TEdit Left = 21 @@ -174,7 +168,6 @@ object MainForm: TMainForm Top = 11 Width = 75 Caption = 'RC file name' - ParentColor = False end object RCFileName: TEdit Left = 21 @@ -232,7 +225,7 @@ object MainForm: TMainForm end object SaveDialog1: TSaveDialog Options = [ofOverwritePrompt, ofHideReadOnly] - left = 366 - top = 240 + Left = 366 + Top = 240 end end diff --git a/frmMain.pas b/frmMain.pas index 3b4bee0..facb69f 100644 --- a/frmMain.pas +++ b/frmMain.pas @@ -52,6 +52,8 @@ type PasList: TStrings); procedure GeneratePasFile(const filename, frmname: string; PasList: TStrings); procedure GetWinInfo(wnd: HWND; ParentNode: TTreeNode); + procedure GetWinInfoStyle(wnd: HWND; ParentNode: TTreeNode); + procedure GetWinInfoExtendedStyle(wnd: HWND; ParentNode: TTreeNode); procedure EnableSavePas; procedure EnableWndInput; public @@ -76,7 +78,6 @@ var node1, node2: TTreeNode; childlist: TList; EnumParams: TEnumParams; - style, exstyle: integer; parentWnd: HWND; itemtext: array [0..300] of char; begin @@ -92,8 +93,6 @@ begin GetWindowRect(wnd, R1); Windows.GetClientRect(wnd, R2); GetClassName(wnd, class_name, 100); - style := GetWindowLong(wnd, GWL_STYLE); - exstyle := GetWindowLong(wnd, GWL_EXSTYLE); parentWnd := GetParent(wnd); EnumParams.List := childlist; EnumParams.ParentWnd := wnd; @@ -105,17 +104,8 @@ begin AddChild(ParentNode, 'Caption = ' + Text); AddChild(ParentNode, 'Class name = ' + class_name); AddChild(ParentNode, 'Parent Handle = ' + IntToStr(parentWnd)); - node1 := AddChild(ParentNode, 'Style'); - AddChild(node1, 'Value = ' + IntToStr(style)); - for i := Low(WindowStyle) to High(WindowStyle) do - if ((style and WindowStyle[i]) = WindowStyle[i]) then - AddChild(node1, WindowStyleName[i]); - - node1 := AddChild(ParentNode, 'Extended Style'); - AddChild(node1, 'Value = ' + IntToStr(exstyle)); - for i := Low(WindowStyle) to High(WindowStyle) do - if ((style and ExtendedWindowStyle[i]) = ExtendedWindowStyle[i]) then - AddChild(node1, ExtendedWindowStyleName[i]); + GetWinInfoStyle(wnd, ParentNode); + GetWinInfoExtendedStyle(wnd, ParentNode); node1 := AddChild(ParentNode, 'Placement'); AddChild(node1, 'Left = ' + IntToStr(R1.Left)); AddChild(node1, 'Top = ' + IntToStr(R1.Top)); @@ -150,6 +140,50 @@ begin childlist.Free; end; +procedure TMainForm.GetWinInfoStyle(wnd: HWND; ParentNode: TTreeNode); +var + style: Integer; + list: TStringList; + node1: TTreeNode; + i: Integer; +begin + style := GetWindowLong(wnd, GWL_STYLE); + list := GetWindowStyleNames(style); + + with Results.TreeView1.Items do + begin + node1 := AddChild(ParentNode, 'Style'); + AddChild(node1, 'Value = ' + IntToStr(style)); + + for i := 0 to list.Count - 1 do + AddChild(node1, list[i]); + end; + + list.Free(); +end; + +procedure TMainForm.GetWinInfoExtendedStyle(wnd: HWND; ParentNode: TTreeNode); +var + style: Integer; + list: TStringList; + node1: TTreeNode; + i: Integer; +begin + style := GetWindowLong(wnd, GWL_EXSTYLE); + list := GetExtendedWindowStyleNames(style); + + with Results.TreeView1.Items do + begin + node1 := AddChild(ParentNode, 'Extended Style'); + AddChild(node1, 'Value = ' + IntToStr(style)); + + for i := 0 to list.Count - 1 do + AddChild(node1, list[i]); + end; + + list.Free(); +end; + procedure TMainForm.InformationClick(Sender: TObject); var wnd: HWND;