Programmatically change System Colors

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Is there a way to change the colors of the menu, status bar, listview headers, etc. programmatically. I can go to the desktop and change the appearance there but I want to do it from my program

Thank you
Joe
 
Joe,

I'm not sure if there's a method in .NET Framework that does this, but you
can always use pinvoke to call the Win32 system API's. Take a look at the
GetSysColor and SetSysColors API functions.

http://support.microsoft.com/defaul...pport/kb/articles/Q82/1/58.ASP&NoWebContent=1

Eric



Joe Thompson said:
Hi,

Is there a way to change the colors of the menu, status bar, listview
headers, etc. programmatically. I can go to the desktop and change the
appearance there but I want to do it from my program.
 
Hi Eric

Thanks for the reply. I've been trying now for a while to get the hang of this p/invoke stuff with not much luck. I tried adding this to my code
using namespace System::Runtime::InteropServices

typedef int INT
typedef unsigned long COLORREF
typedef int BOOL
[DllImport("user32", CharSet=CharSet::Auto)
extern "C" BOOL SetSysColor(int cElements
const INT* lpaElements
const COLORREF* lpaRgbValues)

but now I get errors in winNT.h (error C2061: syntax error : identifier 'DWORD'

I don't get it - do I need to include something, set a compiler option

Thank you
Joe
 
Joe,

You can't use the sample code from the KB article directly. That code is in
C for unmanged compilations. In order to do pinvoke in your .NET code, you
will need to convert the function signature to the proper .NET version.

The first thing you need todo is to create the function in a class, then add
the DllImportAttribute attribute to that function. Then finally convert the
C types in the function signature to the proper .NET equivalents. For
example "int" becomes "System.Int32". If you look at the .NET Framework
documentation here

http://msdn.microsoft.com/library/d...consumingunmanageddllfunctions.asp?frame=true

there's more detailed info than what I gave. Good luck.

Eric



Joe Thompson said:
Hi Eric,

Thanks for the reply. I've been trying now for a while to get the hang of
this p/invoke stuff with not much luck. I tried adding this to my code:
using namespace System::Runtime::InteropServices;

typedef int INT;
typedef unsigned long COLORREF;
typedef int BOOL;
[DllImport("user32", CharSet=CharSet::Auto)]
extern "C" BOOL SetSysColor(int cElements,
const INT* lpaElements,
const COLORREF* lpaRgbValues);

but now I get errors in winNT.h (error C2061: syntax error : identifier 'DWORD')

I don't get it - do I need to include something, set a compiler option?

Thank you,
Joe
 
Back
Top