NO

Author Topic: GroupBox title text color  (Read 903 times)

Offline John Z

  • Member
  • *
  • Posts: 796
GroupBox title text color
« on: January 13, 2024, 03:51:04 AM »
Hi Experts!

Is is possible to set the color of the title for a GroupBox without doing something like 'owner draw?  Been wracking my brain and burning up the keyboard trying things.

See circled item in the attachment.  I can change the font and language, no problem, but can't seem to change the color for this box's title.  In my dark mode one can't read it  :(

Any help appreciated ...even if it is "no it can't be done"  :)

Thanks,
John Z 

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: GroupBox title text color
« Reply #1 on: January 13, 2024, 09:58:22 AM »
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 796
Re: GroupBox title text color
« Reply #2 on: January 13, 2024, 01:00:33 PM »
Thanks TimoVJL,

Maybe so but I can set font, text and size, just not color. That site is blocked for me at the present time, I might try a VPN to it later.

John Z

Offline John Z

  • Member
  • *
  • Posts: 796
Re: GroupBox title text color
« Reply #3 on: January 13, 2024, 01:21:38 PM »
Thanks TimoVJL

So same problem as here:
How do I set the font and color for a group box caption using Win32

I finally got in! Yes, looks like my issue and a possible way to solve it without owner draw but not mentioned directly. I’ll let you know.

Appreciate the help!

John Z

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 176
    • Bcx Basic to C/C++ Translator
Re: GroupBox title text color
« Reply #4 on: January 13, 2024, 04:03:29 PM »
It is possible to change the background of the Group text but changing its text color eludes me.

Here is the BCX code that produces the app in the screenshot.

If you want the generated C/C++ code, download the translator:
https://bcxbasiccoders.com/smf/index.php?topic=990.0

Code: [Select]
GUI "Form1", PIXELS

CONST Grp1_Style    = WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_GROUPBOX
CONST Grp1_ExtStyle = 0

ENUM
    ID_Grp1
END ENUM

GLOBAL Form1 AS HWND
GLOBAL hGrp1 AS CONTROL

SUB FORMLOAD()
    Form1 = BCX_FORM("Form1", 0, 0, 463, 316)
    hGrp1 = BCX_GROUP("Group", Form1, ID_Grp1, 22, 25, 281, 190, Grp1_Style, Grp1_ExtStyle)
    CENTER(Form1)
    SHOW(Form1)
END SUB



BEGIN EVENTS
    SELECT CASE CBMSG
        '***********************************************************************
    CASE WM_CTLCOLORSTATIC
        '***********************************************************************
        SELECT CASE (HWND) CBLPARAM
        CASE hGrp1 : FUNCTION = BCX_SETCOLOR(RGB(255, 0, 0), RGB(200, 255, 200))
        END SELECT
    END SELECT
END EVENTS

Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline John Z

  • Member
  • *
  • Posts: 796
Re: GroupBox title text color
« Reply #5 on: January 13, 2024, 09:00:57 PM »
Thanks MrBcx for looking into this.  I've downloaded your incredible program twice now hopefully soon I'll actually use it.  I'll have to shift my brain though out of Quick Basic and MS VB versions 0-5  ;D

Thanks TimoVJL for the article link. it help lead me to this 1 second fix....which was not in the article but I recall using elsewhere.
Code: [Select]
SetWindowTheme(GetDlgItem(gHWND, OptionBox1), L"", L"");// override manifest themeDoes not affect other controls so no loss of anything else.

John Z

Offline WiiLF23

  • Member
  • *
  • Posts: 66
Re: GroupBox title text color
« Reply #6 on: January 16, 2024, 11:23:19 PM »
Code: [Select]
SetWindowTheme(GetDlgItem(gHWND, OptionBox1), L"", NULL);
This disables Visual Theme support for the specified handle since Windows XP. You might want to pass NULL to the last parameter if using a empty string to disable visual styles.



Offline John Z

  • Member
  • *
  • Posts: 796
Re: GroupBox title text color
« Reply #7 on: January 16, 2024, 11:38:14 PM »
Hi WiiLF23,

Yes, it then allows one to set the text color...without needing owner draw.
No major change to the group box appearance so still looks the same.

proto is -
HRESULT SetWindowTheme(
  [in] HWND    hwnd,
  [in] LPCWSTR pszSubAppName,
  [in] LPCWSTR pszSubIdList
);

From MS:
Quote
When pszSubAppName and pszSubIdList are NULL, the theme manager removes the previously applied associations. You can prevent visual styles from being applied to a specified window by specifying an empty string, (L" "), which does not match any section entries.

So NULL removes while L"" inhibits application as I read it.  In my case both would be OK, maybe NULL is preferred in some situations though.

John Z

Offline WiiLF23

  • Member
  • *
  • Posts: 66
Re: GroupBox title text color
« Reply #8 on: January 18, 2024, 02:08:01 AM »
Hi WiiLF23,

Yes, it then allows one to set the text color...without needing owner draw.
No major change to the group box appearance so still looks the same.

proto is -
HRESULT SetWindowTheme(
  [in] HWND    hwnd,
  [in] LPCWSTR pszSubAppName,
  [in] LPCWSTR pszSubIdList
);

From MS:
Quote
When pszSubAppName and pszSubIdList are NULL, the theme manager removes the previously applied associations. You can prevent visual styles from being applied to a specified window by specifying an empty string, (L" "), which does not match any section entries.

So NULL removes while L"" inhibits application as I read it.  In my case both would be OK, maybe NULL is preferred in some situations though.

John Z

Interesting. I never located that documentation but it is all confirmed. I think NULL is just "best practice", same way I assign all static non-numeric primitives to NULL. I dont think it is necessary, but more preferred means of initialization. It's become a habit indeed.

Offline John Z

  • Member
  • *
  • Posts: 796
Re: GroupBox title text color
« Reply #9 on: January 26, 2024, 10:26:11 PM »
In my case both would be OK, maybe NULL is preferred in some situations though.

Turns out NULL was not OK and it didn't work, just to be correcting myself.

Also in an offline Controls API help file I created,  I found:
Quote
Turning Off Visual Styles
You can turn off visual styles for a control or for all controls in a window by calling the **SetWindowTheme** function as follows:

SetWindowTheme(hwnd, L" ", L" "); In the previous example, hwnd is the handle of the window in which to disable visual styles. After the call, the control renders without visual styles.

The controls api file is from on-line GitHub documentation but converted to html and converted to controls.chm for offline (mostly) access.  The 'mostly' is because the GitHub docs were not complete.

Here is the link if you want to grab it:
https://sourceforge.net/projects/windows-controls-api-docs/

John Z