Jump to content

Get the active window title bar color win8


nend
 Share

Go to solution Solved by nend,

Recommended Posts

How can you get the active window title bar color from win8 so I can use it as a gui background.

I tryd it with _WinAPI_GetSysColor but I just can get it to work.

I found this script here on this form but it wont work for me.

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Color.au3>

GUICreate("My GUI", 300, 200)

$button = GUICtrlCreateButton("Test", 50, 50, 75, 23)

$BGR = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION);Active caption is blue

GUICtrlCreateLabel("", 50, 100, 100, 20)
GUICtrlSetBkColor(-1, _ColorBGRToRGB($BGR))

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _ColorBGRToRGB($BGR)
    Local $RGB = BitShift($BGR, -16)
    $RGB += BitAND($BGR, 0xff00)
    $RGB += BitShift($BGR, 16)
    Return BitAND($RGB, 0xffffff)
EndFunc

Is there someone know how to do this?

Edited by nend
Link to comment
Share on other sites

Metro is Direct3D based, so except for the top level window, there aren't any HWNDs involved there

However maybe with below you can resolve your question

You can find out the process ID of an app, using EnumProcesses. After that FindWindowEx needs to be used in a particular manner as shown below to find the window. 

HWND GetProcessWindow( DWORD processId )
{
    // Now need to run a loop to get the correct window for process.
    bool bFound = false;
    HWND prevWindow = 0;

    while ( ! bFound ) {
        HWND desktopWindow = GetDesktopWindow();
        if ( ! desktopWindow )
            break;

        HWND nextWindow = FindWindowEx( desktopWindow, prevWindow, NULL, NULL );
        if ( ! nextWindow )
            break;

        // Check whether window belongs to the correct process.
        DWORD procId = -1;
        GetWindowThreadProcessId( nextWindow, &procId );

        if ( procId == processId ) {
            // Add additional checks. In my case, I had to bring the window to front so these checks were necessary.
            wchar_t windowText[ 1024 ];
            if ( IsWindowVisible( nextWindow ) && ! IsIconic( nextWindow ) && GetWindowText( nextWindow, ( LPWSTR )windowText, sizeof( windowText ) / sizeof( wchar_t ) )
                && ! GetParent( nextWindow ) )
                return nextWindow;
        }

        prevWindow = nextWindow;
    }

    return 0;
}

link

Link to comment
Share on other sites

Metro is Direct3D based, so except for the top level window, there aren't any HWNDs involved there

However maybe with below you can resolve your question

You can find out the process ID of an app, using EnumProcesses. After that FindWindowEx needs to be used in a particular manner as shown below to find the window. 

HWND GetProcessWindow( DWORD processId )
{
    // Now need to run a loop to get the correct window for process.
    bool bFound = false;
    HWND prevWindow = 0;

    while ( ! bFound ) {
        HWND desktopWindow = GetDesktopWindow();
        if ( ! desktopWindow )
            break;

        HWND nextWindow = FindWindowEx( desktopWindow, prevWindow, NULL, NULL );
        if ( ! nextWindow )
            break;

        // Check whether window belongs to the correct process.
        DWORD procId = -1;
        GetWindowThreadProcessId( nextWindow, &procId );

        if ( procId == processId ) {
            // Add additional checks. In my case, I had to bring the window to front so these checks were necessary.
            wchar_t windowText[ 1024 ];
            if ( IsWindowVisible( nextWindow ) && ! IsIconic( nextWindow ) && GetWindowText( nextWindow, ( LPWSTR )windowText, sizeof( windowText ) / sizeof( wchar_t ) )
                && ! GetParent( nextWindow ) )
                return nextWindow;
        }

        prevWindow = nextWindow;
    }

    return 0;
}

link

Thanks for your anwser.

But I don't need the metro interface but the normal windows interface.

I just need the title bar background from a window, even if there are no windows open.

I thought it's mabey a registry key wich I can read out?

For now I use pixelgetcolor and take the color from the taskbar but this is'nt the right way to do this.

When there is a transparantie used for the taskbar the color is'nt right.

Edited by nend
Link to comment
Share on other sites

Go to HKCUControl PanelColors, ActiveTitle and GradientActiveTitle are the keys you want, at least in XP/Vista/7, not sure about 8, but it's a place to look.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Solution

You probably need this function 

DwmGetColorizationColor

 

Not sure if its defined in AutoIT api but that should not be that hard

After longtime searching even on the registry at the key you sugested (those are not working at win8) I found the registry key.

HKEY_CURRENT_USERSoftwareMicrosoftWindowsDWM", "ColorizationColor"

This one works fine for me.

Thanks for your help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...