Hi,
I've been trying use the GetThemeColor function from the uxTheme.dll in a C#
app...but i can't seen to get a valid result? Could someone tell me what I'm
doing wrong here??
[DllImport("uxTheme.dll", EntryPoint="GetThemeColor", SetLastError=true,
CharSet = CharSet.Auto, ExactSpelling = true,
CallingConvention = CallingConvention.Winapi)]
private extern static System.IntPtr getThemeColor ( System.IntPtr hTheme,
int partID,
int stateID,
int propID,
out int color);
public Drawing.Color GetThemeColor ( IntPtr hTheme, int partID, int stateID,
int propID )
{
int color;
IntPtr retVal;
retVal = VisualStyles.getThemeColor ( hTheme, partID, stateID, propID, out
color );
if ( System.Runtime.InteropServices.Marshal.GetLastWin32Error () > 0 )
throw new Exception(
System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString() );
if ( retVal.ToInt32() > 0 )
{
return Drawing.ColorTranslator.FromWin32 ( color );
}
else
return Drawing.Color.Empty;
}
Thanks for the assist!
Kieron
Mattias Sj?gren - 23 Aug 2003 16:57 GMT
Kieron,
>I've been trying use the GetThemeColor function from the uxTheme.dll in a C#
>app...but i can't seen to get a valid result? Could someone tell me what I'm
[quoted text clipped - 3 lines]
> CharSet = CharSet.Auto, ExactSpelling = true,
> CallingConvention = CallingConvention.Winapi)]
GetThemeColor doesn't use SetLastError to ste the error value, so
using SetLastError=true and GetLastWin32Error will not work. I'd
declare it like this instead
[DllImport("uxTheme.dll", EntryPoint="GetThemeColor",
ExactSpelling=true, PreserveSig=false)]
private extern static void getThemeColor ( ...
You will then get an exception if the function fails, so your calling
code could look like this
try {
VisualStyles.getThemeColor ( hTheme, partID, stateID, propID, out
color );
return Drawing.ColorTranslator.FromWin32 ( color );
}
catch (ExternalException ex) {
return Drawing.Color.Empty;
}
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Kieron Lanning - 23 Aug 2003 18:31 GMT
Excellent, works a treat. Thanks Mattias.
> Kieron,
>
[quoted text clipped - 27 lines]
>
> Mattias