Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Change title bar color (or menu)

Change title bar color (or menu)

Scheduled Pinned Locked Moved C#
jsonquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mirano
    wrote on last edited by
    #1

    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. .

    C 1 Reply Last reply
    0
    • M mirano

      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. .

      C Offline
      C Offline
      Chris Jobson
      wrote on last edited by
      #2

      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 to int iElement = 4; int iColor = 13160660; iRes = SetSysColors(1, ref iElement, ref iColor); should make things work. Chris Jobson

      M 1 Reply Last reply
      0
      • C 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 to int iElement = 4; int iColor = 13160660; iRes = SetSysColors(1, ref iElement, ref iColor); should make things work. Chris Jobson

        M Offline
        M Offline
        mirano
        wrote on last edited by
        #3

        Yes, that worked, the problem was in passing the parameters. Thanks man. .

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups