[FIXED] Win. dark themes, modal dialog box's icon when control shows hints lazarus / 31-LCL ---------------------------------------------------------------------- d7_2_laz · 2024-10-13 16:30 This is a relict of: https://forum.lazarus.freepascal.org/index.php/topic,68765.0.html Windows 64 bits, Laz. 3.6.: - Have a modal dialog box = without icon (wanted here), but preserving the dialog's cancel button in the upper right corner of the dialog. - Have a ShellTreeView or TreeView or virtualstringtree or listview or ... with some long item captions -> where Hints will appear (via ShowHint) when they are hovered. - This works fine in light theme. With metadarkstyle files the following does happen:   when the mouse is hovering a long item so that the hint appears, the dialog box now will show up the application's icon.   This should not be. I checked against these gitlab issues about required Win64 changes ("hopeing" somehow that the theme code is not up-to-date): https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/19321 https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/19439 dealing with (Get/Set)ClassLong vs. (Get/Set)ClassLongPtr. But nothing suspicious could be found. - I tried it now with older dark mode files as derived from doublecommander in the early days of the discussions about windows dark mode in this forum (approx. begin 2023).   They behave just the same (-> test project attached). So it's not mainly related to metadarkstyle's files itself. ==> How might it come that the painting of a hint manipulates the parent's dialog form's style so that an icon does appear? Incorrect subclassing of form's window procedures, deficits in parameter passing so that return values are falsified or unintendedly defaults returned? Any idea from specialists would be welcome ... ---------------------------------------------------------------------- d7_2_laz · 2024-10-15 07:34 I noticed that when the hint is shown, "TCustomForm.IconChanged" is called (customform.inc). So i inspected the call stack (see image), going, from that, back until i found: THintWindow.CalcHintRect (hintwindow.inc). This CalcHintRect triggers some "if HandleNeeded", "CreateHandle", "CreateWnd" etc.pp. until i could locate what probably causes the icon's revival (with impact not on the light theme, but, yes, on the dark theme): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomForm.CreateWnd;begin  .............   // update icon  Perform(CM_ICONCHANGED, 0, 0);    // <<<<============================= here   ............. end; If i look - after the hint is shown - onto the form directly before and after execution of this line, in fact it is responsible for to make the icon to appear. "cm_iconchanged" sounds harmless (just as a notification that something happened), but in fact it forces here that it happenns. Unclear, why only for the dark theme. But the question is, is it possible and how to make it more robust .... ? ---------------------------------------------------------------------- d7_2_laz · 2024-10-15 12:39 Yes it does, resp. is expected to do (to be more than a pure information): https://lazarus- ccr.sourceforge.io/docs/lcl/forms/tcustomform.createwnd.html QuoteThe CM_ICONCHANGED control message is performed to (re-)create handles for menu glyphs, and to post the changes to the widgetset class. Unfortunately i see nowhere within the Lazarus code, where - except doing Perform(CM_ICONCHANGED, 0, 0)  -  the message CM_ICONCHANGED itself is processed ....... Correction: The latter is wrong of course. The connector is here: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     procedure CMIconChanged(var Message: TLMessage); message CM_ICONCHANGED;Sorry for that! ---------------------------------------------------------------------- d7_2_laz · 2024-10-15 13:29 Nevertheless. The following idea: In my test scenario (project files attached above) i have the line in question executed 3 times: 1. for the main form     -->  property Name is "Form1" 2. for the opened modal dialog  -->  property Name is "DlgTest" 3. when the hint for the embedded treeview is shown  -->  property Name here is "" resp. nil So, now, why not benefit from this ??   (customform.inc) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   // update icon  if Name <> '' then       //  Exclude unintended icon handling   Perform(CM_ICONCHANGED, 0, 0); Works! I recompiled my main app, having different scenarios (simple modal dialogs without icon; more complex modal dialogs with intendedly having an own icon). Works! Retested with light theme (regression?); works. Retested with the metadarkstyle files; works. Does it help for hints on other embedded controls too? Chcked for VirtualTreeView -> yes, ok (btw. my original pointer to the listview was by mistake. Hints herein don't span outside the control or the dialog box or the main form) -> Are there any opinions about? ---------------------------------------------------------------------- d7_2_laz · 2024-10-15 18:53 In case anyone is wondering what I'm even talking about, I've attached a short video. ---------------------------------------------------------------------- d7_2_laz · 2024-10-16 11:45 Interesting too: Caseof appearing Hint, the "Sender" is THintWindow. It's BorderStyle is bsNone. As bsNone is "<> bsDialog", it runs through the branch to create the icon (using SmallIconHandle, BigIconHandle) instead of removing it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomForm.IconChanged(Sender: TObject);  // Sender is THintWindow case of the appearing Hint. It's Borderstyle is bsNonebegin  if HandleAllocated then  begin    FreeIconHandles;    if BorderStyle <> bsDialog then      TWSCustomFormClass(WidgetSetClass).SetIcon(Self, SmallIconHandle, BigIconHandle)    else      TWSCustomFormClass(WidgetSetClass).SetIcon(Self, 0, 0);  end;end; That would lead us to a possible alternative fix: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomForm.IconChanged(Sender: TObject);begin  if HandleAllocated then  begin    FreeIconHandles;    if BorderStyle = bsNone then       // Or: Sender is THintWindow    //if Sender Is THintWindow then    // Works too, but is very specific      TWSCustomFormClass(WidgetSetClass).SetIcon(Self, 0, 0)    else    if BorderStyle <> bsDialog then      TWSCustomFormClass(WidgetSetClass).SetIcon(Self, SmallIconHandle, BigIconHandle)    else      TWSCustomFormClass(WidgetSetClass).SetIcon(Self, 0, 0);  end;end; Or simply: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if Sender Is THintWindow then    // Very specific solution     exit; ---------------------------------------------------------------------- Zoran · 2024-10-16 12:16 There is a forum topic which describes the behaviour probably related to this. It's about icon appearing on modal form when DateTimePicker opens calendar (the calendar is actually on its own form, which is borderless, so it seems similar to creating the "hint window"). It does not mention dark theme, though. See the topic: https://forum.lazarus.freepascal.org/index.php/topic,66751.0.html ---------------------------------------------------------------------- d7_2_laz · 2024-10-16 12:32 Yes Zoran, but that had been from the just opposite perspective (to preserve a desired icon for the modal dialog, ie. for more complex dialogs) - right, that was not related to the dark mode at all -, and a solution(workaround) on app level was shown. This one here is about to preserve an icon-less very simple and small dialog box. It's not solvable on app level imo, and not within the dark mode code. The underlying problem though may point in a similar direction, right (i was reminded to that too); note by ASerge: QuoteTDateTimePicker uses a nested form for the calendar. The problem is that in Lazarus changes to the border style of a nested form are reflected on the parent form. There is no such thing in Delphi. ---------------------------------------------------------------------- d7_2_laz · 2024-10-16 20:58 QuoteThe problem is that in Lazarus changes to the border style of a nested form are reflected on the parent form. Oh yes. Just did this little test: - Use a modal dialog box without Icon, with a button on it that opens another Form XY - Assign an Icon to this form XY - Open Form XY via button click. --> The modal dialog box now will have the Icon from Form XY.  // -> And, here,  this all is regardless dark theme or not. Side note: this will happen also if Form XY is defined with BorderStyle bsNone - and. crazy! (afais a Form with BorderStyle bsNone does not show the icon) an Icon is defined. When thiis subform is opend from the modal dialog, this one will show the icon now. ---------------------------------------------------------------------- d7_2_laz · 2024-10-17 17:51 But back now to the original specific topic (problem with the hint -> dialog box' icon appears). For this phenomenon, fix/workaround had been committed (thanks @wp !); details here: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41189