Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / August 2003

Tip: Looking for answers? Try searching our database.

using GetThemeColor from C#...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kieron Lanning - 23 Aug 2003 14:28 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.