Recent

Author Topic: Can the standard displayed font be changed?  (Read 4852 times)

WickedDum

  • Full Member
  • ***
  • Posts: 211
Can the standard displayed font be changed?
« on: December 03, 2016, 09:25:54 pm »
Good afternoon!

I am using ShowMessage() and would like to change its font.  I have a procedure that modifies the message before it is sent to ShowMessage().  I can add whatever I need to that routine...I think.

Code: Pascal  [Select][+][-]
  1. {****************  Center Message  ****************}
  2. Procedure CenterMsg(OrigMsg:string);
  3. var
  4.   padding,
  5.   LenOrigMsg : double;
  6.  
  7. begin
  8.   Padding := (80-length(OrigMsg));
  9.   LenOrigMsg := round(padding/2);
  10. //
  11. //  Font modification can be done here.  :)
  12. //
  13.   While LenOrigMsg > 0 do
  14.     begin
  15.       OrigMsg := ' ' + OrigMsg;
  16.       LenOrigMsg := LenOrigMsg - 1;
  17.     end;
  18.   ShowMessage(OrigMsg);              //  Centered message
  19. end;

Any suggestions?

Thank, in advance!!!
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Can the standard displayed font be changed?
« Reply #1 on: December 03, 2016, 09:49:41 pm »
I don't know but maybe is easier to create your own form as a dialog, that then you can pack into a simple procedure like ShowMessage, with an extra parameter of settings you wish to change. Or better, create an entire class with properties that are applied when you show your custom dialog form.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Can the standard displayed font be changed?
« Reply #2 on: December 03, 2016, 10:03:07 pm »
AFAIK the LCL maps  ShowMessage() to an OS dialog. So customising the font is possible only through changing your OS theme (unless you resort to hacks).

BTW have you considered what will happen in your routine if you pass (perhaps inadvertently) a string longer than 80 to be shown?

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Can the standard displayed font be changed?
« Reply #3 on: December 04, 2016, 06:06:14 am »
Thanks for your replies!

:-[

@lainz - You're talking above my level of expertise... 

@howardpc - How would I change my OS theme?  If I understand you correctly, that would change everything.  Right?

As for an 80+ string...yep.  It doesn't center the whole thing the way I would prefer...  :(


Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

derek.john.evans

  • Guest
Re: Can the standard displayed font be changed?
« Reply #4 on: December 04, 2016, 06:35:55 am »
ShowMessage() does a lot of jumping around, but, it seems to finnally end up at CreateMessageDialog() which returns a TForm, but is actually a TPromptDialog.

Unfortunately, TPromptDialog is private, but all the functionality you want is there. ie: There are these fields.
Code: Pascal  [Select][+][-]
  1.     TextBox : TRect;
  2.     TextStyle : TTextStyle;  
  3.  

One idea is use CreateMessageDialog(), then add a OnPaint event. You can use Abort to bypass the default drawing. Its messy stuff.

Or you can try this:

Code: Pascal  [Select][+][-]
  1. procedure ShowMessageEx(const AMessage: string);
  2. var
  3.   LForm: TForm;
  4. begin
  5.   LForm := CreateMessageDialog(AMessage, mtCustom, [mbOK]);
  6.   try
  7.     with TLabel.Create(LForm) do begin
  8.       ParentColor := True;
  9.       AutoSize := False;
  10.       Alignment := taCenter;
  11.       Layout := tlCenter;
  12.       WordWrap := True;
  13.       SetBounds(0, 0, LForm.Width, (LForm.Components[0] as TControl).Top);
  14.       Caption := AMessage;
  15.       Parent := LForm;
  16.     end;
  17.     LForm.ShowModal;
  18.   finally
  19.     FreeAndNil(LForm);
  20.   end;
  21. end;  
  22.  

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Can the standard displayed font be changed?
« Reply #5 on: December 04, 2016, 07:08:42 am »
Thanks, Geepster.  I figured I would take the least messy option...

Thanks for the code.  But...it didn't compile.  My guess is that I need to add something in "uses".  The error:  "Debugger Exception Notification.  Failed to create win32 control.  Cannot find window class.  In file 'win32\win32wscontrols.pp' at line 244."

Your thoughts?

In troubleshooting, I selected the option "Ignore this error."  That was the wrong thing to do.  How do I deselect it?   %)

Thanks!
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Can the standard displayed font be changed?
« Reply #6 on: January 19, 2017, 08:50:11 am »
Geepster?  Anyone?

Thanks!
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Can the standard displayed font be changed?
« Reply #7 on: January 19, 2017, 09:22:15 am »
@WickedDum
A struggle it seems ?

What i did, is creating a new application. Then put a button on it, added the onclick event for the button with the project inspector. In the event (between begin ... end) i added the line:
Code: [Select]
ShowMessageEx('Hello world');

Then i literally copied over Geepster's code as being generic function in the implementation section of the form (not part of the form itself, but you can also do that if you want) so that my final form unit looked like:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.     { private declarations }
  19.   public
  20.     { public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure ShowMessageEx(const AMessage: string);
  33. var
  34.   LForm: TForm;
  35. begin
  36.   LForm := CreateMessageDialog(AMessage, mtCustom, [mbOK]);
  37.   try
  38.     with TLabel.Create(LForm) do begin
  39.       ParentColor := True;
  40.       AutoSize := False;
  41.       Alignment := taCenter;
  42.       Layout := tlCenter;
  43.       WordWrap := True;
  44.       SetBounds(0, 0, LForm.Width, (LForm.Components[0] as TControl).Top);
  45.       Caption := AMessage;
  46.       Parent := LForm;
  47.     end;
  48.     LForm.ShowModal;
  49.   finally
  50.     FreeAndNil(LForm);
  51.   end;
  52. end;
  53.  
  54. procedure TForm1.Button1Click(Sender: TObject);
  55. begin
  56.   ShowMessageEx('Hello world');
  57. end;
  58.  
  59. end.
  60.  

Then i compiled the application, and ran it from inside the ide, pressed the button et voila the dialog appeared.

Perhaps following the same procedure/steps is able to aid you ?

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Can the standard displayed font be changed?
« Reply #8 on: January 20, 2017, 07:27:30 am »
Thanks, Molly!

Please give me a few days to check it out.

Thanks!   :D
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

 

TinyPortal © 2005-2018