Can't set title and PreviewText in FontDialog lazarus / 21-General ---------------------------------------------------------------------- HexLaden · 2023-02-06 12:00 Hello! 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 ...dlgfont: TFontDialog;... procedure Tfrorm.btnFontClick(Sender: TObject);begin  dlgFont.Title:= 'Select font';  dlgFont.PreviewText:= 'The quick brown fox jumps';  dlgFont.Options:= dlgFont.Options + [fdEffects, fdApplyButton];  if not dlgFont.Execute then Exit;  ...end; I'm using Lazarus 2.2.4 in Win 10. Font dialog remains with standard title caption and standard 'Abcd' as preview text. Tried to set them in object inspector's properties also, but had the same result. Are these properties managed by the operating system only? Thank you! ---------------------------------------------------------------------- KodeZwerg · 2023-02-06 12:39 For the property PreviewText QuotePlease note that use of PreviewText is dependent on platform / widgetset support. For instance, Windows does render PreviewText. It uses its own "Sample", and renders the font name in the selection list using the typeface. QT and QT5 have the same behavior as Windows. It is implemented for the GTK, GTK2 and MUI widgetsets. ---------------------------------------------------------------------- KodeZwerg · 2023-02-06 12:42 For the property Title It is defined in commondialog.inc as 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 constructor TCommonDialog.Create (TheOwner: TComponent);begin  inherited Create(TheOwner);  FTitle := DefaultTitle;end; ---------------------------------------------------------------------- balazsszekely · 2023-02-06 14:04 Quote from: HexLaden on February 06, 2023, 01:00:28 pmHello! 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 ...dlgfont: TFontDialog;... procedure Tfrorm.btnFontClick(Sender: TObject);begin  dlgFont.Title:= 'Select font';  dlgFont.PreviewText:= 'The quick brown fox jumps';  dlgFont.Options:= dlgFont.Options + [fdEffects, fdApplyButton];  if not dlgFont.Execute then Exit;  ...end; I'm using Lazarus 2.2.4 in Win 10. Font dialog remains with standard title caption and standard 'Abcd' as preview text. Tried to set them in object inspector's properties also, but had the same result. Are these properties managed by the operating system only? Thank you! Welcome to the forum! I hope you're not a spammer or even worse a lurker.  Almost everything is possible on windows. Please test attached project. ---------------------------------------------------------------------- HexLaden · 2023-02-06 16:25 @KodeZwerg. Thank you, I searched in the forum and over the net for the PreviewText information you provided now, but could't find it. @GetMem: Thank you for the warm welcome. The forum community has nothing to worry about: I'm neither a spammer nor a lurker. I've been clarifying my doubts reading lots of excelent forum contributions on the past year and a half, or so. They are so good that I never needed to post any question, till now. Your handler works perfectly. Very clever and elegant solution. Thank you! ---------------------------------------------------------------------- balazsszekely · 2023-02-06 17:08 @HexLaden QuoteI'm neither a spammer nor a lurker. I've been clarifying my doubts reading lots of excelent forum contributions on the past year and a half, or so. They are so good that I never needed to post any question, till now. OK then, I owe you an apology. Unfortunately there are a lot of annoying spammers lately(the lurker part was a joke). QuoteYour handler works perfectly. Very clever and elegant solution. Thank you!I'm glad it's working, you're more then welcome! ---------------------------------------------------------------------- KodeZwerg · 2023-02-06 17:12 You can turn on the hints/informations inside the IDE to see what I copy/paste for you. Look on my attached image, the pop-up menu. On second there the text I copied. ---------------------------------------------------------------------- HexLaden · 2023-02-06 19:30 QuoteYou can turn on the hints/informations inside the IDE to see what I copy/paste for you. My mistake. I haven't read them carefully when I first consulted the object inspector's property tips. They usually point out relevant information. QuoteOK then, I owe you an apology. Unfortunately there are a lot of annoying spammers lately(the lurker part was a joke).You were correct: I lurked your code  and I played with 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     SetDlgItemTextW(dlgFontHandle,    1, PWideChar('That''s ok'   ));  // Ok btn    SetDlgItemTextW(dlgFontHandle,    2, PWideChar('Cancel this'  ));  // Cancel btn    SetDlgItemTextW(dlgFontHandle, 1026, PWideChar('Apply this'   ));  // Apply btn    SetDlgItemTextW(dlgFontHandle, 1040, PWideChar('Strike it'    ));  // Strikeout    SetDlgItemTextW(dlgFontHandle, 1041, PWideChar('Line under'   ));  // Underline    SetDlgItemTextW(dlgFontHandle, 1072, PWideChar('What about...'));  // Efects    SetDlgItemTextW(dlgFontHandle, 1073, PWideChar('Final effect' ));  // Sample    SetDlgItemTextW(dlgFontHandle, 1088, PWideChar('Choose font'  ));  // Font    SetDlgItemTextW(dlgFontHandle, 1089, PWideChar('Style it!'    ));  // Style    SetDlgItemTextW(dlgFontHandle, 1090, PWideChar('How big?'     ));  // Size    SetDlgItemTextW(dlgFontHandle, 1091, PWideChar('Colorize'     ));  // Color    SetDlgItemTextW(dlgFontHandle, 1093, PWideChar('Footnote comment'));  Still didn't find how to reach sample 'AaBbCc...' text, thoug. ---------------------------------------------------------------------- KodeZwerg · 2023-02-06 19:55 On Window OS machines you can EnumWindow the PID to compare found HWNDs Text property for "AaBbCc", exemplary as shown with a spy app. ---------------------------------------------------------------------- balazsszekely · 2023-02-06 20:05 @HexLaden @KodeZwerg QuoteOn Window OS machines you can EnumWindow the PID to compare found HWNDs Text property for "AaBbCc", exemplary as shown with a spy app.You can easily replace the preview text, but then when the font type, size, etc changes, the font dialog redraws the original text, so you have to change it again. I attach a demo application which replace the text after the font dialog is shown. I did not go further because honestly it's not worth the effort(at least for me). ---------------------------------------------------------------------- Bogen85 · 2023-02-06 20:21 Quote from: GetMem on February 06, 2023, 03:04:57 pm... or even worse a lurker.  Heh, good one. Hah! ---------------------------------------------------------------------- HexLaden · 2023-02-06 21:41 I intended to understand if and how it would be possible to implement both properties. In the context of the program I'm working on, implementing font prediction would add a small layer of comfort to the user, though it's neither fundamental nor imperative. I agree that the OS solution seems disproportionate. From the example you proposed, I now understood how to reach and replace the text. Thank you very much! ---------------------------------------------------------------------- KodeZwerg · 2023-02-06 22:15 @GetMem, nice, but I am not interested in such @HexLaden, if the systems Dialog ain't fit your needs, you can simple create your own, to start with: 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 ListBox1.Items.AddStrings(Screen.Fonts); ---------------------------------------------------------------------- jamie · 2023-02-06 23:03 The Title issue can be fixed. The Dialog Initiate message can set the title at that point if the given property isn't empty, otherwise it will use the default one.  Also, I believe one can use the SetWindowText API to also do this at some point.  But for the Preview/Sample text, that is another story. ---------------------------------------------------------------------- wp · 2023-02-06 23:25 jamie, you once submitted a patch for the same Title issue with TColorDialog (https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39155). Could you try to do the same for TFontDialog? ---------------------------------------------------------------------- jamie · 2023-02-06 23:56 Yeah, its the same thing. The Dialog callback is structured the same way. Its in the win32WSDialogs. "FontDialogCallBack" to be exact. ---------------------------------------------------------------------- jamie · 2023-02-07 00:29 This is the problem here. at some point in history, someone decided the callback feature causes issues and the callback is only enabled when the ApplyButton is selected in the options. 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  //setting CF_ENABLEHOOK shows an oldstyle dialog, unless lpTemplateName is set    //and a template is linked in as a resource,      //this also requires additional flas set:      //https://msdn.microsoft.com/en- us/library/windows/desktop/ms646832(v=vs.85).aspx      if (fdApplyButton in Options) then      begin        Flags := Flags or CF_ENABLEHOOK;        lpfnHook := @FontDialogCallBack;        lCustData := PtrInt(@ACommonDialog);      end;                                            The fix I have can only work if this hook is enabled all the time, not just the applyBUtton. Tell me what you think, if you enable the applybutton, does it change the view as it claims? does not here. --  In the fontDialogCallBack, this is changed; 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   case uMsg of    WM_INITDIALOG:    begin      //debugln(['FontDialogCallBack: WM_INITDIALOG']);      //debugln(['  PChooseFontW(LParam)^.lCustData=' ,IntToHex(PChooseFontW(LParam)^.lCustData,8)]);      PtrInt(Dlg) := PChooseFontW(LParam)^.lCustData;      If (Dlg <> Nil)and (Dlg^.Title <> '') THen SetWindowText(Wnd,Pchar(Dlg^.Title));//jp    end;    WM_COMMAND:             The line where my john handcock is! ---------------------------------------------------------------------- jamie · 2023-02-07 01:21 I now see the difference between them, it shortens the dialog and doesn't give you the extra options to select more fonts.  This is very strange indeed. You would of thought MS would get their act together by now. ---------------------------------------------------------------------- HexLaden · 2023-02-07 10:48 Thanks, KodeZwerg for the suggestion and tip. For this project in particular I'll probably follow that way. For a general purpose, system's dialog is the adequate choice. Jamie's patch would be welcome. ---------------------------------------------------------------------- jamie · 2023-02-08 02:19 it appears it is possible to define the Sample window along with the Caption of the dialog. But as indicated before, doing so takes on older version of the Dialog box. In any case, I was able to use FindWindowEx within the initiation of the dialog box to locate the control that houses the sample text and it happens to be a "STATIC" text box.  I don't know how reliable this would be however.... But you can redefine the text contents at that point. EDIT:   I think this is a moot point because although i got the sample window to show the preview text it seems when you click around in the box the static text gets replaced with the original text and what this means you would have to answer to the BN_CLICKS, to keep refreshing it.   It can be done but really.   The Caption/Title seems to be ok however. but still, only shows in the old style viewing. ---------------------------------------------------------------------- balazsszekely · 2023-02-08 05:34 @jamie It's not worth the effort, I came to the same conclusion in post 9. If somebody really wants a custom FondDialog, better build one from scratch. It shouldn't take longer then 20-30 minutes. ---------------------------------------------------------------------- KodeZwerg · 2023-02-08 14:11 I put something together, ready to use but currently not as a drop-in replacement. Feel free to use it as a starting point and modify however you like.