2011-11-11 14 views
3

私たちが取り組んでいるWindowsのバージョンを知る方法はありますか?Windows版を入手するにはVista版とDelphi版のXP版がありますか?

Windows XPではTBitButtonにイメージを設定し、Windows7ではイメージを設定する必要があります。それは自動的に行われるべきです。

+1

- ドロップでコンポーネントのオペレーティングシステムの情報を提供具体的には、GetVersionExを呼び出します。このチュートリアルでは、delphiからWindows APIを呼び出す方法について簡単に解説しています。http://www.blong.com/Conferences/BorConUK97/WinAPI/Api.htm – VoidStar

+1

@VoidStar:いいえ、そうではありません。 :) Delphiはこれを自動的に行います。バージョン番号のさまざまな部分について読むことができる 'SysUtils'ユニットにはいくつかの変数が設定されています。使用しているエディション(プロフェッショナル、ホーム、サーバーなど)のような詳細を探している場合は、 'GetVersionEx'だけが必要です。 –

+0

他の回答(Kenによる)では、Windows Vista以降とWindows 7の違いを知る方法を説明しています。Windowsのバージョンを正確に把握し、サーバーのバージョンとデスクトップのバージョンを区別するために、http: /stackoverflow.com/questions/57124/how-to-detect-true-windows-version –

答えて

10

SysUtils.Win32MajorVersion(Delphi 7では、uses句にはSysUtils句を追加する必要があります(あとで追加すると自動的に追加されます)。

if SysUtils.Win32MajorVersion >= 6 then // Windows Vista or higher 
    BitBtn1.Glyph := nil; 

特定のWindowsエディションとバージョンを検出すると詳細情報については、this postを参照してください:あなたはVista上で実行されている以上している場合、最も簡単な方法は、IDEでいつものようにGlyphを割り当て、それをクリアすることです。最新のWindowsのバージョンやエディションでは更新されていませんが、それはあなたを始めます。 SOを[delphi] GetVersionExに検索すると、他の例も見ることができます。

+3

これはVista/2008以降を検出する方法です。関連する関数CheckWin32Versionに注意してください。なぜなら、D6では少なくともそれは単に間違っていたからです。修正されましたが、D7についてはわかりません。 –

0

これは実際に私の小さなプロジェクトです - あなたがWindows API呼び出しを行う必要がありさえデザイン時にそれをプレビュー...

unit JDOSInfo; 

interface 

uses 
    Classes, Windows, SysUtils, StrUtils, Forms, Registry; 

type 
    TJDOSInfo = class(TComponent) 
    private 
    fReg: TRegistry; 
    fKey: String; 
    fMinor: Integer; 
    fMajor: Integer; 
    fBuild: Integer; 
    fPlatform: Integer; 
    fIsServer: Bool; 
    fIs64bit: Bool; 
    fProductName: String; 
    function GetProductName: String; 
    procedure SetProductName(Value: String); 
    procedure SetMajor(Value: Integer); 
    procedure SetMinor(Value: Integer); 
    procedure SetBuild(Value: Integer); 
    procedure SetPlatform(Value: Integer); 
    procedure SetIs64Bit(const Value: Bool); 
    procedure SetIsServer(const Value: Bool); 
    public 
    constructor Create(AOwner: TComponent); override; 
    destructor Destroy; override; 
    published 
    property Major: Integer read fMajor write SetMajor; 
    property Minor: Integer read fMinor write SetMinor; 
    property Build: Integer read fBuild write SetBuild; 
    property Platf: Integer read fPlatform write SetPlatform; 
    property ProductName: String read GetProductName write SetProductName; 
    property IsServer: Bool read fIsServer write SetIsServer; 
    property Is64Bit: Bool read fIs64bit write SetIs64Bit; 
    end; 

function IsWOW64: Boolean; 
function GetOSInfo: TOSVersionInfo; 


procedure Register; 

implementation 

procedure Register; 
begin 
    RegisterComponents('JD Custom', [TJDOSInfo]); 
end; 

function GetOSInfo: TOSVersionInfo; 
begin 
    FillChar(Result, SizeOf(Result), 0); 
    Result.dwOSVersionInfoSize := SizeOf(Result); 
    if not GetVersionEx(Result) then 
    raise Exception.Create('Error calling GetVersionEx'); 
end; 

function IsWOW64: Boolean; 
type 
    TIsWow64Process = function(// Type of IsWow64Process API fn 
    Handle: THandle; 
    var Res: BOOL): BOOL; stdcall; 
var 
    IsWow64Result: BOOL;    // result from IsWow64Process 
    IsWow64Process: TIsWow64Process; // IsWow64Process fn reference 
begin 
    // Try to load required function from kernel32 
    IsWow64Process:= GetProcAddress(GetModuleHandle('kernel32'),'IsWow64Process'); 
    if Assigned(IsWow64Process) then 
    begin 
    // Function is implemented: call it 
    if not IsWow64Process(GetCurrentProcess, IsWow64Result) then 
     raise Exception.Create('Bad process handle'); 
    // Return result of function 
    Result := IsWow64Result; 
    end else 
    // Function not implemented: can't be running on Wow64 
    Result:= False; 
end; 

constructor TJDOSInfo.Create(AOwner: TComponent); 
var 
    Info: TOSVersionInfo; 
    Str: String; 
begin 
    inherited Create(AOwner); 
    fReg:= TRegistry.Create(KEY_READ); 
    fReg.RootKey:= HKEY_LOCAL_MACHINE; 
    fKey:= 'Software\Microsoft\Windows NT\CurrentVersion'; 
    fReg.OpenKey(fKey, False); 
    Info:= GetOSInfo; 
    fMajor:= Info.dwMajorVersion; 
    fMinor:= Info.dwMinorVersion; 
    fBuild:= Info.dwBuildNumber; 
    fIsServer:= False; 
    fIs64bit:= False; 
    fPlatform:= Info.dwPlatformId; 
    if fMajor >= 5 then begin 
    //After 2000 
    if fReg.ValueExists('ProductName') then 
     Str:= fReg.ReadString('ProductName') 
    else begin 
     Str:= 'Unknown OS: '+IntToStr(fMajor)+'.'+IntToStr(fMinor)+'.'+ 
     IntToStr(fBuild)+'.'+IntToStr(fPlatform); 
    end;  
    if fReg.ValueExists('InstallationType') then begin 
     if UpperCase(fReg.ReadString('InstallationType')) = 'SERVER' then 
     fIsServer:= True; 
    end; 
    fIs64bit:= IsWOW64; 
    if fIs64bit then 
     Str:= Str + ' 64 Bit'; 
    end else begin 
    //Before 2000 
    case fMajor of 
     4: begin 
     case fMinor of 
      0: Str:= 'Windows 95'; 
      10: Str:= 'Windows 98'; 
      90: Str:= 'Windows ME'; 
     end; 
     end; 
     else begin 
     Str:= 'Older than 95'; 
     end; 
    end; 
    end; 
    Self.fProductName:= Str; 
end; 

destructor TJDOSInfo.Destroy; 
begin 
    if assigned(fReg) then begin 
    if fReg.Active then 
     fReg.CloseKey; 
    fReg.Free; 
    end; 
    inherited Destroy; 
end; 

function TJDOSInfo.GetProductName: String; 
begin 
    Result:= Self.fProductName; 
end; 

procedure TJDOSInfo.SetProductName(Value: String); 
begin 
    //Do Nothing Here! 
end; 

procedure TJDOSInfo.SetMinor(Value: Integer); 
begin 
    //Do Nothing Here! 
end; 

procedure TJDOSInfo.SetMajor(Value: Integer); 
begin 
    //Do Nothing Here! 
end; 

procedure TJDOSInfo.SetBuild(Value: Integer); 
begin 
    //Do Nothing Here! 
end; 

procedure TJDOSInfo.SetPlatform(Value: Integer); 
begin 
    //Do Nothing Here! 
end; 

procedure TJDOSInfo.SetIs64Bit(const Value: Bool); 
begin 
    //Do Nothing Here! 
end; 

procedure TJDOSInfo.SetIsServer(const Value: Bool); 
begin 
    //Do Nothing Here! 
end; 

end. 
+3

NTの検出に失敗します。このコードは奇妙に感じます。割り当てられた場合は無料ですか?ちょうどフリーを呼び出してください。空のプロパティ設定ツールとは何ですか? –

+0

NTが検出されないことについてはわかりませんが、元のコードは見つかった他のコードの一部です。私はいつも、そして、私はいつも物事が解放される前に(単にアクセス違反を防ぐために)作成されているかどうかをチェックすることを意味します。空のプロパティ設定者は、デザイン時にプロパティを表示できるようにします。少なくともDelphi 7では、読み込み専用のプロパティを公開することはできません。私は他の後のバージョンでも可能だと信じていますが、これは読み取り専用のトリックです。 –

+0

さらに、私はそれを終えたこともなく、しばらくの間それを取り置きましたが、それはRakeshが何をする必要があるのか​​を十分に実行します。 –

関連する問題