Changing Highlight color

Ramseem A 46 Reputation points
2021-03-23T10:58:58.503+00:00

Hi team,

We need to change selected text background color in Windows Edit control. We found below options to change the same.

  1. Update the registry [HKEY_CURRENT_USER\Control Panel\Colors\Hilight]
  2. Using SetSysColors() API

In above cases changes are made in OS level.

But we have a requirement to change the selected text background color only for an application [Not entire system]. Is there any option for this?

Also identified below thread, that describe about OS level update.
https://answers.microsoft.com/en-us/windows/forum/windows_10-start-win_general/how-to-change-the-highlight-color-properly/b720d88a-8ff6-4ca3-8815-c66e2d9f2c29

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,774 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,356 Reputation points
    2021-03-23T13:48:10.603+00:00

    You can override Paint (WM_PAINT) event but it is complex because there are many messages to handle (mouse, keyboard, focus, ...)

    A simpler way is to host a WPF TextBox with ElementHost Class

    A quick test with 2 TextBoxes and SelectionBrush Property =>

    80752-textboxselectioncolor1.jpg 80625-textboxselectioncolor2.jpg

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ramseem A 46 Reputation points
    2021-03-23T17:12:29.283+00:00

    Thanks for your reply,

    You can override Paint (WM_PAINT) event but it is complex because there are many messages to handle (mouse, keyboard, focus, ...)

    We tried the WM_PAINT message to handle the issue and we noticed that WM_PAINT message is not received while editing and selecting the text.

    A simpler way is to host a WPF TextBox with ElementHost Class

    We are using CPP application so WPF solution is not able to using in our scenario.

    Is there any other solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.