I want to take advantage of the new Windows 7 taskbar functionality in a .NET application and would like to know what people think is the best way to check for Windows 7 features in .NET. My aim is to have distinct code for Windows XP and Windows 7.
I’m not overally keen on:
- just wrapping the Windows 7 code in a try catch
- if OS = “Windows 7” Then…
Unless of course this is what most are doing. I really have hunted everywhere for a good approach but without success. The Microsoft unmanaged code wrapper library seems to just assume it’s running on Windows 7…
I think there’s nothing wrong with
if OS = "Windows 7“. Of course,if OS >= "Windows 7"(so that it doesn’t break in Windows 7.1 or whatever will be the successor) andIf you don’t want to clutter your code with
if (isWindows7) {...}, you might want to put the platform-specific code into a separate class. For example, you could create an interfaceand two implementations of this class, one for >= Win 7 and one for others (which does different things or nothing at all). When your application starts, you instantiate some global variable of type
IOSSpecificwith either one of the two implementations.