We have a legacy WinForms app written at the times of .NET 1.x and may need to change the code that checks whether the app is rendered with the OS visual styles for the reason described below. The current function that does this work looks like this:
private bool IsComCtl6
{
get
{
if (!fIsComCtl6Initialized)
{
IntPtr hMod = NativeMethods.LoadLibrary("comctl32.dll");
if (hMod != IntPtr.Zero)
{
IntPtr lptrDLLVersion = NativeMethods.GetProcAddress(hMod, "DllGetVersion");
if (lptrDLLVersion != IntPtr.Zero)
{
hMod = NativeMethods.LoadLibrary("uxtheme.dll");
if (hMod != IntPtr.Zero)
{
NativeMethods.DllVersionInfo dvi = new NativeMethods.DllVersionInfo();
dvi.cbSize = Marshal.SizeOf(typeof(NativeMethods.DllVersionInfo));
if (NativeMethods.DllGetVersion(ref dvi) == NativeMethods.S_OK)
fIsComCtl6 = (!fCheckAppThemed || dvi.dwMajorVersion >= 6) && NativeMethods.IsThemeActive() && NativeMethods.IsAppThemed();
}
}
}
fIsComCtl6Initialized = true;
}
return fIsComCtl6;
}
}
NativeMethods in this code is a class that contains P-Invoke declarations for all referenced WinAPI functions and constants.
We want to avoid platform-independent calls in this code as, it seems, they are not compatible with the latest releases of the Mono platform. Is there a better and shorter way to check what we need without OS native calls? It would be nice if we can do that solely with native .NET classes. The minimal version of supported .NET should be 2.0 or even 3.5.