程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> WinAPI: DrawFrameControl - 繪制控件

WinAPI: DrawFrameControl - 繪制控件

編輯:Delphi

//聲明:  
DrawFrameControl( 
 DC: HDC;      {設備環境句柄} 
 const Rect: TRect; {矩形} 
 uType, uState: UINT {控件類型與控件狀態} 
): BOOL; 
 
 
//控件類型 uType 參數可選值: 
DFC_CAPTION  = 1; {標題按鈕} 
DFC_MENU   = 2; {菜單} 
DFC_SCROLL  = 3; {滾動條按鈕} 
DFC_BUTTON  = 4; {標准按鈕} 
DFC_POPUPMENU = 5; {彈出菜單} 
 
 
//控件狀態 uState 參數可選值: 
 
{針對 DFC_CAPTION} 
DFCS_CAPTIONCLOSE  = 0; 
DFCS_CAPTIONMIN   = 1; 
DFCS_CAPTIONMAX   = 2; 
DFCS_CAPTIONRESTORE = 3; 
DFCS_CAPTIONHELP  = 4; 
 
{針對 DFC_MENU} 
DFCS_MENUARROW   = 0; 
DFCS_MENUCHECK   = 1; 
DFCS_MENUBULLET   = 2; 
DFCS_MENUARROWRIGHT = 4; 
 
{針對 DFC_SCROLL} 
DFCS_SCROLLUP      = 0; 
DFCS_SCROLLDOWN     = 1; 
DFCS_SCROLLLEFT     = 2; 
DFCS_SCROLLRIGHT     = 3; 
DFCS_SCROLLCOMBOBOX   = 5; 
DFCS_SCROLLSIZEGRIP   = 8; 
DFCS_SCROLLSIZEGRIPRIGHT = $10; 
 
{針對 DFC_BUTTON} 
DFCS_BUTTONCHECK   = 0; 
DFCS_BUTTONRADIOIMAGE = 1; 
DFCS_BUTTONRADIOMASK = 2; 
DFCS_BUTTONRADIO   = 4; 
DFCS_BUTTON3STATE   = 8; 
DFCS_BUTTONPUSH    = $10; 
 
{通用狀態} 
DFCS_INACTIVE  = $100; 
DFCS_PUSHED   = $200; 
DFCS_CHECKED   = $400; 
DFCS_TRANSPARENT = $800; 
DFCS_HOT     = $1000; 
DFCS_ADJUSTRECT = $2000; 
DFCS_FLAT    = $4000; 
DFCS_MONO    = $8000; 
 
 
//舉例: 
unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, StdCtrls, ExtCtrls; 
 
type 
 TForm1 = class(TForm) 
  RadioGroup1: TRadioGroup; 
  RadioGroup2: TRadioGroup; 
  RadioGroup3: TRadioGroup; 
  RadioGroup4: TRadioGroup; 
  RadioGroup5: TRadioGroup; 
  RadioGroup6: TRadioGroup; 
  Panel1: TPanel; 
  procedure RadioGroup1Click(Sender: TObject); 
  procedure RadioGroup2Click(Sender: TObject); 
  procedure RadioGroup3Click(Sender: TObject); 
  procedure RadioGroup4Click(Sender: TObject); 
  procedure RadioGroup5Click(Sender: TObject); 
  procedure RadioGroup6Click(Sender: TObject); 
  procedure Draw; 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
var 
 DFC : Integer = 0; 
 DFCS1: Integer = 0; 
 DFCS2: Integer = 0; 
 
procedure TForm1.Draw; 
begin 
 Panel1.Refresh; 
 DrawFrameControl(GetDC(Panel1.Handle), Rect(10,10,100,50), DFC, DFCS1 or DFCS2); 
end; 
 
procedure TForm1.RadioGroup1Click(Sender: TObject); 
begin 
 Panel1.Refresh; 
 case RadioGroup1.ItemIndex of 
  0: begin 
   DFC := DFC_CAPTION; 
   RadioGroup3.Enabled := True; 
   RadioGroup4.Enabled := False; 
   RadioGroup5.Enabled := False; 
   RadioGroup6.Enabled := False; 
  end; 
  1: begin 
   DFC := DFC_MENU; 
   RadioGroup3.Enabled := False; 
   RadioGroup4.Enabled := True; 
   RadioGroup5.Enabled := False; 
   RadioGroup6.Enabled := False; 
  end; 
  2: begin 
   DFC := DFC_SCROLL; 
   RadioGroup3.Enabled := False; 
   RadioGroup4.Enabled := False; 
   RadioGroup5.Enabled := True; 
   RadioGroup6.Enabled := False; 
  end; 
  3: begin 
   DFC := DFC_BUTTON; 
   RadioGroup3.Enabled := False; 
   RadioGroup4.Enabled := False; 
   RadioGroup5.Enabled := False; 
   RadioGroup6.Enabled := True; 
  end; 
  4: begin 
   DFC := DFC_POPUPMENU; 
   RadioGroup3.Enabled := False; 
   RadioGroup4.Enabled := True; 
   RadioGroup5.Enabled := False; 
   RadioGroup6.Enabled := False; 
  end; 
 end; 
end; 
 
procedure TForm1.RadioGroup2Click(Sender: TObject); 
begin 
 case RadioGroup2.ItemIndex of 
  0: DFCS1 := DFCS_INACTIVE; 
  1: DFCS1 := DFCS_PUSHED; 
  2: DFCS1 := DFCS_CHECKED; 
  3: DFCS1 := DFCS_TRANSPARENT; 
  4: DFCS1 := DFCS_HOT; 
  5: DFCS1 := DFCS_ADJUSTRECT; 
  6: DFCS1 := DFCS_FLAT; 
  7: DFCS1 := DFCS_MONO; 
 end; 
 Draw; 
end; 
 
procedure TForm1.RadioGroup3Click(Sender: TObject); 
begin 
 case RadioGroup3.ItemIndex of 
  0: DFCS2 := DFCS_CAPTIONCLOSE; 
  1: DFCS2 := DFCS_CAPTIONMIN; 
  2: DFCS2 := DFCS_CAPTIONMAX; 
  3: DFCS2 := DFCS_CAPTIONRESTORE; 
  4: DFCS2 := DFCS_CAPTIONHELP; 
 end; 
 Draw; 
end; 
 
procedure TForm1.RadioGroup4Click(Sender: TObject); 
begin 
 case RadioGroup4.ItemIndex of 
  0: DFCS2 := DFCS_MENUARROW; 
  1: DFCS2 := DFCS_MENUCHECK; 
  2: DFCS2 := DFCS_MENUBULLET; 
  3: DFCS2 := DFCS_MENUARROWRIGHT; 
 end; 
 Draw; 
end; 
 
procedure TForm1.RadioGroup5Click(Sender: TObject); 
begin 
 case RadioGroup5.ItemIndex of 
  0: DFCS2 := DFCS_SCROLLUP; 
  1: DFCS2 := DFCS_SCROLLDOWN; 
  2: DFCS2 := DFCS_SCROLLLEFT; 
  3: DFCS2 := DFCS_SCROLLRIGHT; 
  4: DFCS2 := DFCS_SCROLLCOMBOBOX; 
  5: DFCS2 := DFCS_SCROLLSIZEGRIP; 
  6: DFCS2 := DFCS_SCROLLSIZEGRIPRIGHT; 
 end; 
 Draw; 
end; 
 
procedure TForm1.RadioGroup6Click(Sender: TObject); 
begin 
 case RadioGroup6.ItemIndex of 
  0: DFCS2 := DFCS_BUTTONCHECK; 
  1: DFCS2 := DFCS_BUTTONRADIOIMAGE; 
  2: DFCS2 := DFCS_BUTTONRADIOMASK; 
  3: DFCS2 := DFCS_BUTTONRADIO; 
  4: DFCS2 := DFCS_BUTTON3STATE; 
  5: DFCS2 := DFCS_BUTTONPUSH; 
 end; 
 Draw; 
end; 
 
end. 
 
 
//效果圖: 

WinAPI: DrawFrameControl - 繪制控件

  附上窗體結構代碼:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClIEntHeight = 386
  ClIEntWidth = 499
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object RadioGroup1: TRadioGroup
    Left = 0
    Top = 8
    Width = 137
    Height = 129
    Caption = 'RadioGroup1'
    Items.Strings = (
      'DFC_CAPTION   '
      'DFC_MENU      '
      'DFC_SCROLL    '
      'DFC_BUTTON    '
      'DFC_POPUPMENU ')
    TabOrder = 0
    OnClick = RadioGroup1Click
  end
  object RadioGroup2: TRadioGroup
    Left = 0
    Top = 143
    Width = 137
    Height = 170
    Caption = 'RadioGroup2'
    Items.Strings = (
      'DFCS_INACTIVE'
      'DFCS_PUSHED'
      'DFCS_CHECKED'
      'DFCS_TRANSPARENT'
      'DFCS_HOT'
      'DFCS_ADJUSTRECT'
      'DFCS_FLAT'
      'DFCS_MONO')
    TabOrder = 1
    OnClick = RadioGroup2Click
  end
  object RadioGroup3: TRadioGroup
    Left = 143
    Top = 8
    Width = 178
    Height = 129
    Caption = 'RadioGroup3'
    Items.Strings = (
      'DFCS_CAPTIONCLOSE   '
      'DFCS_CAPTIONMIN'
      'DFCS_CAPTIONMAX'
      'DFCS_CAPTIONRESTORE'
      'DFCS_CAPTIONHELP')
    TabOrder = 2
    OnClick = RadioGroup3Click
  end
  object RadioGroup4: TRadioGroup
    Left = 327
    Top = 8
    Width = 170
    Height = 129
    Caption = 'RadioGroup4'
    Items.Strings = (
      'DFCS_MENUARROW'
      'DFCS_MENUCHECK'
      'DFCS_MENUBULLET'
      'DFCS_MENUARROWRIGHT')
    TabOrder = 3
    OnClick = RadioGroup4Click
  end
  object RadioGroup5: TRadioGroup
    Left = 143
    Top = 143
    Width = 178
    Height = 170
    Caption = 'RadioGroup5'
    Items.Strings = (
      'DFCS_SCROLLUP'
      'DFCS_SCROLLDOWN'
      'DFCS_SCROLLLEFT'
      'DFCS_SCROLLRIGHT'
      'DFCS_SCROLLCOMBOBOX'
      'DFCS_SCROLLSIZEGRIP'
      'DFCS_SCROLLSIZEGRIPRIGHT')
    TabOrder = 4
    OnClick = RadioGroup5Click
  end
  object RadioGroup6: TRadioGroup
    Left = 327
    Top = 143
    Width = 170
    Height = 170
    Caption = 'RadioGroup6'
    Items.Strings = (
      'DFCS_BUTTONCHECK'
      'DFCS_BUTTONRADIOIMAGE'
      'DFCS_BUTTONRADIOMASK'
      'DFCS_BUTTONRADIO'
      'DFCS_BUTTON3STATE'
      'DFCS_BUTTONPUSH')
    TabOrder = 5
    OnClick = RadioGroup6Click
  end
  object Panel1: TPanel
    Left = 0
    Top = 319
    Width = 499
    Height = 67
    Align = alBottom
    Caption = 'Panel1'
    TabOrder = 6
  end
end



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved