EMF file operation with GDI [8]: Change the paint brush and paint brush when drawing the Metafile

Source: Internet
Author: User
In this example:


Code file:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) colorbox1: tcolorbox; colorbox2: tcolorbox; outputs: outputs; Procedure formcreate (Sender: tobject); Procedure formdestroy (Sender: tobject); Procedure outputs (Sender: tobject); Procedure colorbox1change (Sender: tobject ); procedure colorbox2change (Sender: tobject); Procedure combobox1change (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} var hmetafile: henhmetafile; {EMF file handle} p: tpen; B: tbrush; // callback function of enumenhmetafile myenhmetafunc (displaysurface: HDC; var metafiletable: thandletable; vaR metafilerecord: tenhmetarecord; objectcount: integer; var data: longint): integer; stdcall; begin case metafilerecord. itype of emr_createpen: SelectObject (displaysurface, P. handle); emr_createbrushindirect: SelectObject (displaysurface, B. handle); else playenhmetafilerecord (displaysurface, metafiletable, metafilerecord, objectcount); Result: = 1; end; Procedure tform1.formcreate (Sender: tobject); var metafiledc: HDC; begin {file established in memory} metafiledc: = createenhmetafile (0, nil); P: = tpen. create; B: = tbrush. create; p. color: = clred; B. style: = bscross; B. color: = clsilver; SelectObject (metafiledc, P. handle); SelectObject (metafiledc, B. handle); movetoex (metafiledc, 0, 0, nil); lineto (metafiledc, 80, 80); {rectangle} rectangle (metafiledc, 10, 10, 30, 50 ); {elliptical} ellipse (metafiledc, 30, 30, 50, 70); hmetafile: = closeenhmetafile (metafiledc); deleteobject (metafiledc); combobox1.items. commatext: = 'bssolid, bsclear, regression, bsvertical, bsfdiagonal, bsbdiagonal, bscross, bsdiagcross'; end; Procedure outcome (Sender: tobject); begin enumenhmetafile (canvas. handle, hmetafile, @ myenhmetafunc, nil, clientrect); end; Procedure tform1.colorbox1change (Sender: tobject); begin p. color: = colorbox1.selected; repaint; end; Procedure tform1.colorbox2change (Sender: tobject); begin B. color: = colorbox2.selected; repaint; end; Procedure tform1.combobox1change (Sender: tobject); begin B. color: = colorbox2.selected; Case combobox1.itemindex of 0: B. style: = bssolid; 1: B. style: = bsclear; 2: B. style: = bshorizontal; 3: B. style: = bsvertical; 4: B. style: = bsfdiagonal; 5: B. style: = bsbdiagonal; 6: B. style: = bscross; 7: B. style: = bsdiagcross; end; repaint; end; Procedure tform1.formdestroy (Sender: tobject); begin p. free; B. free; deleteenhmetafile (hmetafile); end.
 

Form file:

object Form1: TForm1  Left = 0  Top = 0  Caption = 'Form1'  ClientHeight = 197  ClientWidth = 324  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  Position = poDesktopCenter  OnCreate = FormCreate  OnDestroy = FormDestroy  OnPaint = FormPaint  PixelsPerInch = 96  TextHeight = 13  object ColorBox1: TColorBox    Left = 200    Top = 16    Width = 116    Height = 22    ItemHeight = 16    TabOrder = 0    OnChange = ColorBox1Change  end  object ColorBox2: TColorBox    Left = 200    Top = 44    Width = 116    Height = 22    ItemHeight = 16    TabOrder = 1    OnChange = ColorBox2Change  end  object ComboBox1: TComboBox    Left = 200    Top = 72    Width = 116    Height = 21    ItemHeight = 13    TabOrder = 2    Text = 'ComboBox1'    OnChange = ComboBox1Change  endend
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.