Recent

Author Topic: Disable theming for a TPageControl  (Read 1407 times)

Bart

  • Hero Member
  • *****
  • Posts: 4938
    • Bart en Mariska's Webstek
Disable theming for a TPageControl
« on: January 28, 2023, 06:12:28 pm »
Hi,

On Windows (10) a TTabSheet of a TPageControl looks hideous (its white on my default (not dark) theme).
I have one application where I diable theming for a specific TPageControl using this code in the form's OnCreate
Code: Pascal  [Select][+][-]
  1.   UxTheme.SetWindowTheme(NoteBook.Handle, nil, '');  //NoteBook is a TPageControl
This works like I want it to be: the TTabSheets have the same color as the form they reside on (standard clForm color).

Now: in another application I wanted to do the same:
I have a NoteBook: TPageControl on a Form.
I run the same code ase above in the form's OnCreate.
But to no effect: the TTabSheet remains white (not clForm).
I tried setting the TTabSheet.Color to clForm: to no avail.
I tried to disable theming on the TTabSheet, but the effect was that no text was shown anywhere on the form anymore in any control (outside the TPageControl).

I rebuild the application where it worked (thinking either something changed in Lazarus, or in Windows), and that application still works as I want (theming on the TPageControl is disabled).

The only difference between these 2 situations is that in the application where it works, the form is the main form.
In the application where it does not work, the form is a dialog (not the main form).

So, I put a TPageControl on the main form of the application where it did not work, disabled theming for it, and lo and behold: it worked.

After some testing I found out that the "problem" is that I use  ShowModal to show the dialog form in question.
If I do a simple Show then the theming of the TPageControl is disabled, the TTabSheets have the clForm color.

Does anyone know why this is the case?
Do I use the wrong parameters for SetWindowTheme()?
Note: it returns S_OK, I checked.

Bart

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1221
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Disable theming for a TPageControl
« Reply #1 on: January 28, 2023, 07:47:57 pm »
This is how I mostly did the job with Delphi to de-/activate a window theme for a particular control (and have the manifest included to use themes)
Code: Pascal  [Select][+][-]
  1. H:=ListBox1.Handle;
  2. T:=GetWindowTheme(H);
  3. E:=SetWindowTheme(H,NIL,'');
  4. ListBox1.Enabled:=False;
  5. ListBox1.Enabled:=True;
  6. T:=GetWindowTheme(H);

Does that help you? (I tested each times the T E H values...)
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Bart

  • Hero Member
  • *****
  • Posts: 4938
    • Bart en Mariska's Webstek
Re: Disable theming for a TPageControl
« Reply #2 on: January 28, 2023, 10:14:09 pm »
This is how I mostly did the job with Delphi to de-/activate a window theme for a particular control (and have the manifest included to use themes)
Does that help you? (I tested each times the T E H values...)

No, all returned values are zero.
Note: in the main form, where this does work as expected, all returned values are zero as well.

Bart

GetMem

  • Hero Member
  • *****
  • Posts: 4030
Re: Disable theming for a TPageControl
« Reply #3 on: January 29, 2023, 05:43:41 pm »
@Bart

This works for me(modal form OnShow event, Lazarus Trunk/FPC 3.2.2):
Code: Pascal  [Select][+][-]
  1. uses UxTheme, LCLIntf;
  2.  
  3. procedure TForm2.FormShow(Sender: TObject);
  4. begin
  5.   UxTheme.SetWindowTheme(PageControl1.Handle, nil, '');
  6.   PageControl1.Invalidate;
  7. end;
  8.  

Bart

  • Hero Member
  • *****
  • Posts: 4938
    • Bart en Mariska's Webstek
Re: Disable theming for a TPageControl
« Reply #4 on: January 29, 2023, 10:05:52 pm »
Thank you very much: that works.
The Invalidate does not seem to be necessary.

(You earned credentials in the code for that, as well as in the commit message  :D )

Bart
« Last Edit: January 29, 2023, 10:08:30 pm by Bart »

GetMem

  • Hero Member
  • *****
  • Posts: 4030
Re: Disable theming for a TPageControl
« Reply #5 on: January 30, 2023, 07:49:41 am »
@Bart
Quote
Thank you very much: that works.
You're welcome! I'm glad it's working.

Quote
The Invalidate does not seem to be necessary.
Without invalidate I see a white artefact from the original theme. It does goes away after one click though.
« Last Edit: January 30, 2023, 10:02:47 am by GetMem »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1221
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Disable theming for a TPageControl
« Reply #6 on: January 30, 2023, 10:54:28 am »
In my tries with "Enabled" False/True, it does do the same, just saying  :D
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

GetMem

  • Hero Member
  • *****
  • Posts: 4030
Re: Disable theming for a TPageControl
« Reply #7 on: January 30, 2023, 11:23:38 am »
@KodeZwerg

Quote
In my tries with "Enabled" False/True, it does do the same, just saying  :D
What do you mean? If you enable then disable TPageControl the white theme is back, or I misunderstood something?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1221
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Disable theming for a TPageControl
« Reply #8 on: January 30, 2023, 11:39:37 am »
@KodeZwerg

Quote
In my tries with "Enabled" False/True, it does do the same, just saying  :D
What do you mean? If you enable then disable TPageControl the white theme is back, or I misunderstood something?
Like I wrote earlier.
Code: Pascal  [Select][+][-]
  1. SetWindowTheme(PageControl1.Handle, NIL, '');
  2. PageControl1.Enabled := False;
  3. PageControl1.Enabled := True;
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

GetMem

  • Hero Member
  • *****
  • Posts: 4030
Re: Disable theming for a TPageControl
« Reply #9 on: January 30, 2023, 12:05:00 pm »
Quote from: KodeZwerg
Like I wrote earlier.
Code: Pascal  [Select][+][-]
  1. SetWindowTheme(PageControl1.Handle, NIL, '');
  2. PageControl1.Enabled := False;
  3. PageControl1.Enabled := True;
Yes your code works too, just tested.
The important thing is to move SetWindowTheme from FormCreate to FormActivate/FormShow when working with ModalForms.
So credits goes to KodeZwerg, he was the one who come up with a valid solution first.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1221
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Disable theming for a TPageControl
« Reply #10 on: January 30, 2023, 12:17:08 pm »
So credits goes to KodeZwerg, he was the one who come up with a valid solution first.
Everything is fine my friend, just wanted to say that there is another way :)
What really confused me was:
No, all returned values are zero.
Note: in the main form, where this does work as expected, all returned values are zero as well.
That did made absolute no sense to me, when a handle is 0 than something very strange is going on  :P

I agree, I just tested with ListBox and was not concerned about to put the real needed control in.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Bart

  • Hero Member
  • *****
  • Posts: 4938
    • Bart en Mariska's Webstek
Re: Disable theming for a TPageControl
« Reply #11 on: January 30, 2023, 02:42:14 pm »
What really confused me was:
No, all returned values are zero.
Note: in the main form, where this does work as expected, all returned values are zero as well.
That did made absolute no sense to me, when a handle is 0 than something very strange is going on  :P

The returnvalue of SetWindowTheme must be zero (S_OK) to indicate success.
Why GetWindoTheme returns zero, IDK. It functions nevertheless.

Bart

 

TinyPortal © 2005-2018