Change title bar color (or menu)
-
Hi guys, I want to change title bar color, but I am doing something wrong. So please, if anybody knows what it is, it would be good to let me know. I declare: using System.Runtime.InteropServices; then I import API: [DllImport("user32.dll")] public static extern int SetSysColors(int nChanges, int lpSysColor, int lpColorValues); [DllImport("user32.dll")] public static extern int GetSysColor(int nIndex); and then I call it this way: int iRes = GetSysColor(4); MessageBox.Show("Result: " + iRes.ToString()); iRes = SetSysColors(0, 4, 14898176); MessageBox.Show("Result: " + iRes.ToString()); The first message box returns 16777215 which is a color of the menu (number 4 is the constant for menu), so it means GetSysColor function works, but the second function returns 0, which means it failed, and color of the menu does not change. Why is that? Am I missing something obvious? Thanks for your answers. .
-
Hi guys, I want to change title bar color, but I am doing something wrong. So please, if anybody knows what it is, it would be good to let me know. I declare: using System.Runtime.InteropServices; then I import API: [DllImport("user32.dll")] public static extern int SetSysColors(int nChanges, int lpSysColor, int lpColorValues); [DllImport("user32.dll")] public static extern int GetSysColor(int nIndex); and then I call it this way: int iRes = GetSysColor(4); MessageBox.Show("Result: " + iRes.ToString()); iRes = SetSysColors(0, 4, 14898176); MessageBox.Show("Result: " + iRes.ToString()); The first message box returns 16777215 which is a color of the menu (number 4 is the constant for menu), so it means GetSysColor function works, but the second function returns 0, which means it failed, and color of the menu does not change. Why is that? Am I missing something obvious? Thanks for your answers. .
You have two problems. Firstly, the first parameter to SetSysColors is the number of colours you are changing, so it should be 1 instead of 0. Secondly, the second and third parameters should be passed by reference rather than by value (they are actually both pointers to the first element of an array). Changing the declaration to
[DllImport("user32.dll")] public static extern int SetSysColors(int nChanges, ref int lpSysColor, ref int lpColorValues);
and the call toint iElement = 4; int iColor = 13160660; iRes = SetSysColors(1, ref iElement, ref iColor);
should make things work. Chris Jobson -
You have two problems. Firstly, the first parameter to SetSysColors is the number of colours you are changing, so it should be 1 instead of 0. Secondly, the second and third parameters should be passed by reference rather than by value (they are actually both pointers to the first element of an array). Changing the declaration to
[DllImport("user32.dll")] public static extern int SetSysColors(int nChanges, ref int lpSysColor, ref int lpColorValues);
and the call toint iElement = 4; int iColor = 13160660; iRes = SetSysColors(1, ref iElement, ref iColor);
should make things work. Chris Jobson