Recent

Author Topic: Message CM_ShowingChanged arrives not always?  (Read 371 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2725
    • UVviewsoft
Message CM_ShowingChanged arrives not always?
« on: June 12, 2026, 09:11:53 pm »
Here is demo project. Attached.
When I click all 3 buttons, my TCustomControl shows/hides. And Listbox1 log must show that my control got the CM_SHOWINGCHANGED. It shows it only on the 1st showing of control. I expected that event is got on every toggling, ie also when I click buttons many times: 1 2 3 1 2 3 1 2 3 etc.

It's on all widgetsets: win64 gtk2 qt5 qt6.

How TCustomControl can get the event of parent's showing/hiding?

LeP

  • Sr. Member
  • ****
  • Posts: 441
Re: Message CM_ShowingChanged arrives not always?
« Reply #1 on: June 13, 2026, 12:11:44 am »
It's simple: My1, My2, My3 changed only 1 time. After that they don't change anymore ... parents change but not My1, etc ... They stay always showed (but not visible 'cause parents).

Try insert where Panel1.Hide and Show are  My1 too.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Panel1.Show;
  4.   My1.Show;
  5.   Panel2.Hide;
  6.   Panel3.Hide;
  7. end;
  8.  
  9. procedure TForm1.Button2Click(Sender: TObject);
  10. begin
  11.   Panel1.Hide;
  12.   My1.Hide;
  13.   Panel2.Show;
  14.   Panel3.Hide;
  15. end;
  16.  
  17. procedure TForm1.Button3Click(Sender: TObject);
  18. begin
  19.   Panel1.Hide;
  20.   My1.Hide;
  21.   Panel2.Hide;
  22.   Panel3.Show;
  23. end;
  24.  
« Last Edit: June 13, 2026, 12:16:03 am by LeP »
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

LeP

  • Sr. Member
  • ****
  • Posts: 441
Re: Message CM_ShowingChanged arrives not always?
« Reply #2 on: June 13, 2026, 01:03:07 am »
How TCustomControl can get the event of parent's showing/hiding?

In Delphi you must change your procedure, intercept this message:

Code: Pascal  [Select][+][-]
  1.   TMy = class(TPanel)
  2.   protected
  3.     procedure CMParentVisibleChanged(var Message: TMessage); message CM_PARENTVISIBLECHANGED;
  4.   end;
  5.  

But in Lazarus that message non exists ...  %)
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

jamie

  • Hero Member
  • *****
  • Posts: 7852
Re: Message CM_ShowingChanged arrives not always?
« Reply #3 on: June 13, 2026, 01:31:17 am »
Here is demo project. Attached.
When I click all 3 buttons, my TCustomControl shows/hides. And Listbox1 log must show that my control got the CM_SHOWINGCHANGED. It shows it only on the 1st showing of control. I expected that event is got on every toggling, ie also when I click buttons many times: 1 2 3 1 2 3 1 2 3 etc.

It's on all widgetsets: win64 gtk2 qt5 qt6.

How TCustomControl can get the event of parent's showing/hiding?

 You could process the "LM_SHOWWINDOW" message. That can report if the parent is changing etc.

Jamie
The only true wisdom is knowing you know nothing

LeP

  • Sr. Member
  • ****
  • Posts: 441
Re: Message CM_ShowingChanged arrives not always?
« Reply #4 on: June 13, 2026, 01:37:39 am »
You could process the "LM_SHOWWINDOW" message. That can report if the parent is changing etc.
Jamie

I tried with LM_SHOWWINDOW but it's never sended to child (even if its visibility changes).
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

jamie

  • Hero Member
  • *****
  • Posts: 7852
Re: Message CM_ShowingChanged arrives not always?
« Reply #5 on: June 13, 2026, 01:42:49 am »
You could process the "LM_SHOWWINDOW" message. That can report if the parent is changing etc.
Jamie

I tried with LM_SHOWWINDOW but it's never sended to child (even if its visibility changes).

Did you override the WndPrc to do that?

I know many messags are blocked in the LCL but lots of them get through using the WndProc

Jamie
The only true wisdom is knowing you know nothing

LeP

  • Sr. Member
  • ****
  • Posts: 441
Re: Message CM_ShowingChanged arrives not always?
« Reply #6 on: June 13, 2026, 02:13:51 am »
You could process the "LM_SHOWWINDOW" message. That can report if the parent is changing etc.
Jamie
I tried with LM_SHOWWINDOW but it's never sended to child (even if its visibility changes).
Did you override the WndPrc to do that?
I know many messags are blocked in the LCL but lots of them get through using the WndProc
Jamie

I tried, and the only time that message is sent is when I close the application (also tested with the debugger).
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

AlexTP

  • Hero Member
  • *****
  • Posts: 2725
    • UVviewsoft
Re: Message CM_ShowingChanged arrives not always?
« Reply #7 on: June 15, 2026, 01:21:03 pm »
Lazarus was improved today (Git main). Now CM_ShowingChanged works like in Delphi. Thanks to Zeljko.

 

TinyPortal © 2005-2018