Noch schnell eine vorweihnachtliche Funktion, die ich selbst zu brauchen glaubte:
[autoit]Func _GetOSVersionNumber()
; GetVersionEx function -> http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
; Operation system versions -> http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
; Operating system Version number
; Windows 7 6.1
; Windows Server 2008 R2 6.1
; Windows Server 2008 6.0
; Windows Vista 6.0
; Windows Server 2003 R2 5.2
; Windows Server 2003 5.2
; Windows XP 64-Bit Edition 5.2
; Windows XP 5.1
; Windows 2000 5.0
Local $OSVERSIONINFO = DllStructCreate("DWORD [5];WCHAR [128]")
DllStructSetData($OSVERSIONINFO, 1, DllStructGetSize($OSVERSIONINFO), 1)
Local $aResult = DllCall("Kernel32.dll", "BOOL", "GetVersionExW", "PTR", DllStructGetPtr($OSVERSIONINFO))
If Not $aResult[0] Then Return SetError(@error, @extended, 0)
Return Number(DllStructGetData($OSVERSIONINFO, 1, 2) & "." & DllStructGetData($OSVERSIONINFO, 1, 3))
EndFunc ;==>_GetOSVersionNumber
Man kann den Rückgabewert direkt numerisch vergleichen. Ein praktisches Beispiel für einen ListView-Headerstyle, der ab Vista die Veränderung der Spaltenbreite per Maus verhindert:
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <HeaderConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
MsgBox(0, "OS Version", _GetOSVersionNumber())
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1)
#include <GUIConstantsEx.au3>
$hGUI = GUICreate("ListView")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$idLV = GUICtrlCreateListView("Spalte 1|Spalte 2|Spalte 3", 0, 0, 400, 400)
If _GetOSVersionNumber() > 5.2 Then ; Win Vista +
$hLVHeader = GUICtrlSendMsg($idLV, $LVM_GETHEADER, 0, 0)
_SetStyle($hLVHeader, BitOR(_GetStyle($hLVHeader), $HDS_NOSIZING))
EndIf
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _GetOSVersionNumber()
; GetVersionEx function -> http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
; Operation system versions -> http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
; Operating system Version number
; Windows 7 6.1
; Windows Server 2008 R2 6.1
; Windows Server 2008 6.0
; Windows Vista 6.0
; Windows Server 2003 R2 5.2
; Windows Server 2003 5.2
; Windows XP 64-Bit Edition 5.2
; Windows XP 5.1
; Windows 2000 5.0
Local $OSVERSIONINFO = DllStructCreate("DWORD [5];WCHAR [128]")
DllStructSetData($OSVERSIONINFO, 1, DllStructGetSize($OSVERSIONINFO), 1)
Local $aResult = DllCall("Kernel32.dll", "BOOL", "GetVersionExW", "PTR", DllStructGetPtr($OSVERSIONINFO))
If Not $aResult[0] Then Return SetError(@error, @extended, 0)
Return Number(DllStructGetData($OSVERSIONINFO, 1, 2) & "." & DllStructGetData($OSVERSIONINFO, 1, 3))
EndFunc ;==>_GetOSVersionNumber
Func _GetStyle($hWnd)
; Ausgeliehen aus der WinAPI.au3
Local Const $GWL_STYLE = 0xFFFFFFF0
Local $sFuncName = "GetWindowLongW"
If @AutoItX64 Then $sFuncName = "GetWindowLongPtrW"
Local $aStyle = DllCall("User32.dll", "LONG_PTR", $sFuncName, "HWND", $hWnd, "INT", $GWL_STYLE)
Return $aStyle[0]
EndFunc ;==>_GetStyle
Func _SetStyle($hWnd, $iValue)
; Ausgeliehen aus der WinAPI.au3
Local Const $GWL_STYLE = 0xFFFFFFF0
Local $sFuncName = "SetWindowLongW"
If @AutoItX64 Then $sFuncName = "SetWindowLongPtrW"
Local $aExStyle = DllCall("User32.dll", "LONG_PTR", $sFuncName, "HWND", $hWnd, "INT", $GWL_STYLE, "LONG_PTR", $iValue)
Return $aExStyle[0]
EndFunc ;==>_SetStyle