From 6ea14fac7760b6cf996a5b4d82fe12c505524817 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Tue, 31 Aug 2004 09:12:50 +0000 Subject: [PATCH] Added: OS.ComCtlVersion and OS.XPManifest properties --- Test/Forms/FMain.dfm | 43 +++++++++++++++++++------ Test/Forms/FMain.pas | 23 +++++++++++--- Test/X2UtilsTest.cfg | 5 ++- Test/X2UtilsTest.dof | 22 +++---------- Test/X2UtilsTest.dpr | 2 -- X2UtOS.pas | 75 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 132 insertions(+), 38 deletions(-) diff --git a/Test/Forms/FMain.dfm b/Test/Forms/FMain.dfm index ef2f343..9f5963b 100644 --- a/Test/Forms/FMain.dfm +++ b/Test/Forms/FMain.dfm @@ -1,10 +1,10 @@ object frmMain: TfrmMain - Left = 199 - Top = 107 + Left = 339 + Top = 239 BorderIcons = [biSystemMenu] BorderStyle = bsDialog Caption = 'X'#178'Utils Test' - ClientHeight = 206 + ClientHeight = 245 ClientWidth = 455 Color = clBtnFace Font.Charset = DEFAULT_CHARSET @@ -65,29 +65,44 @@ object frmMain: TfrmMain end object lblInstances: TLabel Left = 8 - Top = 84 + Top = 128 Width = 49 Height = 13 Caption = 'Instances:' end object lblFormatSize: TLabel Left = 8 - Top = 160 + Top = 204 Width = 56 Height = 13 Caption = 'Format size:' end object lblFormatSizeValue: TLabel Left = 244 - Top = 160 + Top = 204 Width = 205 Height = 13 AutoSize = False Caption = '' end - object lstInstances: TListBox + object lblComCtlVersionValue: TLabel Left = 112 Top = 84 + Width = 333 + Height = 13 + AutoSize = False + Caption = '' + end + object lblComCtlVersion: TLabel + Left = 8 + Top = 84 + Width = 73 + Height = 13 + Caption = 'ComCtl version:' + end + object lstInstances: TListBox + Left = 112 + Top = 128 Width = 337 Height = 65 ItemHeight = 13 @@ -95,7 +110,7 @@ object frmMain: TfrmMain end object txtSize: TEdit Left = 112 - Top = 156 + Top = 200 Width = 121 Height = 21 TabOrder = 1 @@ -103,11 +118,21 @@ object frmMain: TfrmMain end object chkBytes: TCheckBox Left = 112 - Top = 180 + Top = 224 Width = 97 Height = 17 Caption = '&Keep bytes' TabOrder = 2 OnClick = txtSizeChange end + object chkXPManifest: TCheckBox + Left = 112 + Top = 104 + Width = 337 + Height = 17 + Caption = 'XP Manifest' + Checked = True + State = cbChecked + TabOrder = 3 + end end diff --git a/Test/Forms/FMain.pas b/Test/Forms/FMain.pas index d7a3d59..efabbde 100644 --- a/Test/Forms/FMain.pas +++ b/Test/Forms/FMain.pas @@ -12,10 +12,13 @@ uses type TfrmMain = class(TForm, IX2InstanceNotifier) chkBytes: TCheckBox; + chkXPManifest: TCheckBox; lblAppPath: TLabel; lblAppPathValue: TLabel; lblAppVersion: TLabel; lblAppVersionValue: TLabel; + lblComCtlVersion: TLabel; + lblComCtlVersionValue: TLabel; lblFormatSize: TLabel; lblFormatSizeValue: TLabel; lblInstances: TLabel; @@ -40,17 +43,27 @@ uses {$R *.dfm} +// If you have a WinXP.RES which holds the XP manifest, you will +// notice that the Common Controls version changes to 6 instead of 5. +{.$R WinXP.RES} + {=============================== TfrmMain Initialization ========================================} procedure TfrmMain.FormCreate; begin Randomize(); - - lblAppPathValue.Caption := App.Path; - lblAppVersionValue.Caption := App.FormatVersion(); - lblOSVersionValue.Caption := OS.FormatVersion(); - txtSize.Text := IntToStr(Random(MaxInt)); + + lblAppPathValue.Caption := App.Path; + lblAppVersionValue.Caption := App.FormatVersion(); + lblOSVersionValue.Caption := OS.FormatVersion(); + + with OS.ComCtlVersion do + lblComCtlVersionValue.Caption := Format('%d.%d build %d', [Major, Minor, + Build]); + + chkXPManifest.Checked := OS.XPManifest; + txtSize.Text := IntToStr(Random(MaxInt)); RegisterInstance(Self); end; diff --git a/Test/X2UtilsTest.cfg b/Test/X2UtilsTest.cfg index 17482c8..d55d496 100644 --- a/Test/X2UtilsTest.cfg +++ b/Test/X2UtilsTest.cfg @@ -32,6 +32,5 @@ -M -$M16384,1048576 -K$00400000 --LE"c:\program files\borland\delphi6\Projects\Bpl" --LN"c:\program files\borland\delphi6\Projects\Bpl" --DmadExcept +-LE"c:\delphi6\Projects\Bpl" +-LN"c:\delphi6\Projects\Bpl" diff --git a/Test/X2UtilsTest.dof b/Test/X2UtilsTest.dof index 2578dc0..6c2bc26 100644 --- a/Test/X2UtilsTest.dof +++ b/Test/X2UtilsTest.dof @@ -47,7 +47,7 @@ PackageDLLOutputDir= PackageDCPOutputDir= SearchPath= Packages=vcl;rtl;vclx;Indy60;madBasic_;madDisAsm_;dsnap;dbrtl;xmlrtl;inet;soaprtl -Conditionals=madExcept +Conditionals= DebugSourceDirs= UsePackages=0 [Parameters] @@ -56,6 +56,10 @@ HostApplication= Launcher= UseLauncher=0 DebugCWD= +[Language] +ActiveLang= +ProjectLang= +RootDir= [Version Info] IncludeVerInfo=1 AutoIncBuild=1 @@ -148,19 +152,3 @@ Item0=madExcept [HistoryLists\hlUnitAliases] Count=1 Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; -[Included Packages] -C:\Program Files\Borland\Delphi6\Bin\dclstd60.bpl=Borland Standard Components -c:\program files\borland\delphi6\Bin\dclsmpedit60.bpl=Borland Editor Script Enhancements -F:\Delphi\Components\madCollection\madBasic\Delphi 6\madBasic_.bpl=madBasic 1.1f · www.madshi.net -F:\Delphi\Components\madCollection\madDisAsm\Delphi 6\madDisAsm_.bpl=madDisAsm 2.0a · www.madshi.net -F:\Delphi\Components\madCollection\madExcept\Delphi 6\madExcept_.bpl=madExcept 2.6a · www.madshi.net -F:\Delphi\Components\madCollection\madExcept\Delphi 6\madExceptIde_.bpl=madExceptIde 1.0b · www.madshi.net -F:\Delphi\Components\madCollection\madExcept\Delphi 6\madExceptWizard_.bpl=madExceptWizard 2.6 · www.madshi.net -C:\Program Files\Borland\Delphi6\Bin\dcldb60.bpl=Borland Database Components -c:\program files\borland\delphi6\Bin\dclnet60.bpl=Borland Internet Components -c:\program files\borland\delphi6\Bin\dclsoap60.bpl=Borland SOAP Components -c:\program files\borland\delphi6\Projects\Bpl\ColorPickerButtonD6.bpl=ColorPickerButton -C:\Program Files\Borland\Delphi6\Bin\dclact60.bpl=Borland ActionBar Components -c:\program files\borland\delphi6\Projects\Bpl\SysILS.bpl=(untitled) -c:\program files\borland\delphi6\Projects\Bpl\videocap5.bpl=(untitled) -c:\program files\borland\delphi6\Projects\Bpl\DragDropD6.bpl=Drag and Drop Component Suite diff --git a/Test/X2UtilsTest.dpr b/Test/X2UtilsTest.dpr index b970416..e7de1ed 100644 --- a/Test/X2UtilsTest.dpr +++ b/Test/X2UtilsTest.dpr @@ -1,8 +1,6 @@ program X2UtilsTest; uses - madExcept, - madLinkDisAsm, Forms, X2UtOS in '..\X2UtOS.pas', X2UtApp in '..\X2UtApp.pas', diff --git a/X2UtOS.pas b/X2UtOS.pas index 9955e5f..5b3eaba 100644 --- a/X2UtOS.pas +++ b/X2UtOS.pas @@ -18,6 +18,13 @@ type TX2OSVersion = (osWin95, osWin98, osWinME, osWinNT3, osWinNT4, osWin2K, osWinXP, osWin2003, osUnknown); + //:$ Record to hold the Common Controls version + TX2CCVersion = record + Major: Cardinal; + Minor: Cardinal; + Build: Cardinal; + end; + { :$ Contains extended version information for the Operating System } @@ -46,10 +53,14 @@ type } TX2OS = class(TObject) private + FCCVersion: TX2CCVersion; FVersion: TX2OSVersion; FVersionEx: TX2OSVersionEx; + + function GetXPManifest(): Boolean; protected procedure GetVersion(); virtual; + procedure GetCCVersion(); virtual; public constructor Create(); destructor Destroy(); override; @@ -59,6 +70,13 @@ type //:: OS' Build number. function FormatVersion(Build: Boolean = True): String; + //:$ Contains the Common Controls version + property ComCtlVersion: TX2CCVersion read FCCVersion; + + //:$ Checks if the application uses an XP manifest + //:: If present, Common Controls version 6 or higher is available. + property XPManifest: Boolean read GetXPManifest; + //:$ Contains the detected OS version property Version: TX2OSVersion read FVersion; @@ -71,7 +89,22 @@ type implementation uses SysUtils; - + +const + ComCtl32 = 'comctl32.dll'; + +type + PDllVersionInfo = ^TDllVersionInfo; + TDllVersionInfo = record + cbSize: DWORD; + dwMajorVersion: DWORD; + dwMinorVersion: DWORD; + dwBuildNumber: DWORD; + dwPlatformID: DWORD; + end; + + TDllGetVersion = function(pdvi: PDllVersionInfo): HRESULT; stdcall; + var GOS: TX2OS; @@ -97,6 +130,7 @@ begin FVersionEx := TX2OSVersionEx.Create(); GetVersion(); + GetCCVersion(); end; destructor TX2OS.Destroy; @@ -180,6 +214,43 @@ begin end; end; +procedure TX2OS.GetCCVersion; +var + DllGetVersion: TDllGetVersion; + hLib: THandle; + viVersion: TDllVersionInfo; + +begin + FillChar(FCCVersion, SizeOf(FCCVersion), #0); + hLib := LoadLibrary(ComCtl32); + + if hLib <> 0 then + begin + @DllGetVersion := GetProcAddress(hLib, 'DllGetVersion'); + if Assigned(DllGetVersion) then + begin + FillChar(viVersion, SizeOf(viVersion), #0); + viVersion.cbSize := SizeOf(viVersion); + + DllGetVersion(@viVersion); + + with FCCVersion do + begin + Major := viVersion.dwMajorVersion; + Minor := viVersion.dwMinorVersion; + Build := viVersion.dwBuildNumber; + end; + end; + + FreeLibrary(hLib); + end; +end; + +function TX2OS.GetXPManifest; +begin + Result := (FCCVersion.Major >= 6); +end; + function TX2OS.FormatVersion; var @@ -199,5 +270,5 @@ end; initialization finalization FreeAndNil(GOS); - + end.