How i can add some values to color Box in the TFontDialog? Or please tell me about components that can select font with custom color? I use Delphi 7.
Thanks.
I found some way... But how i can show TColorDialog when color box changed on itemIndex = 0?
 procedure TForm1.FontDialog1Show(Sender: TObject);
const
 IDCOLORCMB = $473;
 SMyColorName: PChar = 'clMoneyGreen';
 CMyColor: TColor = clMoneyGreen;
begin
 SendDlgItemMessage(FontDialog1.Handle, IDCOLORCMB, CB_INSERTSTRING, 0,
 Integer(SMyColorName));
 SendDlgItemMessage(FontDialog1.Handle, IDCOLORCMB, CB_SETITEMDATA, 0,
   ColorToRGB(CMyColor));
end;
                I think this works:
interface
TFontDialog = class(Dialogs.TFontDialog)
const
  IDCOLORCMB = $473;
protected
  procedure WndProc(var Message: TMessage); override;
  procedure DoShow; override;
end;
...
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
  FontDialog1.Execute();
end;
{ TFontDialog }
procedure TFontDialog.DoShow;
const
  SMyColorName: PChar = 'Custom...';
  CMyColor: TColor = $0033ccff;
begin
  SendDlgItemMessage(Handle, IDCOLORCMB, CB_INSERTSTRING, 0, Integer(SMyColorName));
  SendDlgItemMessage(Handle, IDCOLORCMB, CB_SETITEMDATA, 0, ColorToRGB(CMyColor));
end;
procedure TFontDialog.WndProc(var Message: TMessage);
begin
  inherited;
  with Message do
    if (Msg = WM_COMMAND) and (WParamHi = CBN_SELENDOK) and (WParamLo = IDCOLORCMB) and (SendDlgItemMessage(Handle, IDCOLORCMB, CB_GETCURSEL, 0, 0) = 0) then
      with TColorDialog.Create(Self) do
        try
          Color := TColor(SendDlgItemMessage(Self.Handle, IDCOLORCMB, CB_GETITEMDATA, 0, 0));
          Options := [cdFullOpen];
          if Execute(Self.Handle) then
            SendDlgItemMessage(Self.Handle, IDCOLORCMB, CB_SETITEMDATA, 0, ColorToRGB(Color));
        finally
          Free;
        end;
end;
But notice, as David correctly argues in the comments below, that this code might fail if the dialog box should change (significantly enough) in a future version of Windows. That might or might not be a showstopper for the OP.
TFontDialog is a wrapper around the system's common dialog, ChooseFont.  The common dialog does not offer easy customisation of its colour drop-down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With