Avatar billede athlon-pascal Juniormester
26. juli 2003 - 12:58 Der er 7 kommentarer og
1 løsning

Brug af WM_SETFONT

I Win32.hlp har jeg fundet følgende:
"An application sends a WM_SETFONT message to specify the font that a control is to use when drawing text.

WM_SETFONT 
wParam = (WPARAM) hfont;            // handle of font
lParam = MAKELPARAM(fRedraw, 0);    // redraw flag


Parameters

hfont

Value of wParam. Identifies the font. If this parameter is NULL, the control uses the default system font to draw text.

fRedraw

Value of lParam. Specifies whether the control should be redrawn immediately upon setting the font. Setting the fRedraw parameter to TRUE causes the control to redraw itself.



Return Values

This message does not return a value.

Remarks

The WM_SETFONT message applies to all controls, not just those in dialog boxes.
The best time for the owner of a dialog box control to set the font of the control is when it receives the WM_INITDIALOG message. The application should call the DeleteObject function to delete the font when it is no longer needed; for example, after it destroys the control.
The size of the control does not change as a result of receiving this message. To avoid clipping text that does not fit within the boundaries of the control, the application should correct the size of the control window before it sets the font.

When a dialog box uses the DS_SETFONT style to set the text in its controls, Windows sends the WM_SETFONT message to the dialog box procedure before it creates the controls. An application can create a dialog box that contains the DS_SETFONT style by calling any of the following functions:

·    CreateDialogIndirect
·    CreateDialogIndirectParam
·    DialogBoxIndirect
·    DialogBoxIndirectParam



See Also

CreateDialogIndirect, CreateDialogIndirectParam, DeleteObject, DialogBoxIndirect, DialogBoxIndirectParam, WM_INITDIALOG, DLGTEMPLATE "

Hvordan bruger jeg det i mit program? Er det muligt at tilføje events til alle komponenter i mit program, så jeg kan bruge det? I så fald, hvordan tilføjer jeg bedst disse events?
Avatar billede athlon-pascal Juniormester
26. juli 2003 - 12:58 #1
Jeg bruger Delphi4.
Avatar billede borrisholt Novice
26. juli 2003 - 18:21 #2
hvad skal du bruge det til ?
Avatar billede athlon-pascal Juniormester
26. juli 2003 - 18:23 #3
"The WM_SETFONT message applies to all controls, not just those in dialog boxes."
Såvidt jeg kan se, kan det bruges til alle standardkomponenter, til at finde den systemfont (brugervalgt?) der passer.
Måske tager jeg fejl?
Avatar billede stoney Nybegynder
26. juli 2003 - 18:27 #4
Nedenståend"kopiere" font "indstillinger" fra button1 til button2

procedure TForm1.Button1Click(Sender: TObject);
var
  h:HFONT;
  redraw:LongBool;

begin
  h := SendMessage(Button1.Handle, WM_GETFONT, 0, 0);
  redraw := TRUE;
  SendMessage(button2.Handle, WM_SETFONT, WPARAM(h), LPARAM(redraw));
end;

Stoney
Avatar billede athlon-pascal Juniormester
26. juli 2003 - 18:39 #5
Stoney -> Den brokker sig over at den ikke kender WM_SETFONT. Hvad skal jeg tilføje til uses?
Avatar billede athlon-pascal Juniormester
26. juli 2003 - 18:40 #6
Je bruger følgende kode, frit efter dit eksempel:
SendMessage(Form1.Handle, WM_SETFONT, WPARAM(nil), LPARAM(true));
Avatar billede stoney Nybegynder
26. juli 2003 - 18:58 #7
Det er godt nok lavet i D6

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  h:HFONT;
  redraw:LongBool;

begin
  h := SendMessage(Button1.Handle, WM_GETFONT, 0, 0);
  redraw := TRUE;
  SendMessage(button2.Handle, WM_SETFONT, WPARAM(h), LPARAM(redraw));
end;


end.

Stoney
Avatar billede athlon-pascal Juniormester
26. juli 2003 - 19:09 #8
uses Messages; :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester