⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 delphi中应用png,通过GDI+实现的根据png图建一个不规则窗体
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,GDIPAPI,GDIPOBJ, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    RadioButton1: TRadioButton;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    button:Tbutton;
      mycontrolcount:integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function UpdateLayeredWindow(hWnd: HWND; 
  hdcDst: HDC; Dst: PPoint; const size: PSize;
  hdcSrc: HDC; Src: PPoint;
  crKey: COLORREF;
  pblend: PBlendFunction;
  dwFlags: DWORD): BOOL; stdcall; external 'user32.dll';

procedure ColorUpdateLayeredWindow(Wnd: HWND; BMP: TBitmap; TransColor: TColor); 

var 
  R: TRect;
  S: TSize;
  P: TPoint;
begin
  GetWindowRect(Wnd, R);
 P := Point(0, 0);
  S.cx := Bmp.Width;
  S.cY := Bmp.Height;
  SetWindowLong(Wnd, GWL_EXSTYLE, GetWindowLong(Wnd, GWL_EXSTYLE) or WS_EX_LAYERED);
  UpdateLayeredWindow(Wnd, 0, @R.TopLeft, @S, Bmp.Canvas.Handle, @P, TransColor, 0, ULW_COLORKEY);
end;

  

procedure AlphaUpdateLayeredWindow(Wnd: HWND; Bmp: TBitmap; Alpha: Byte); 

var 
  P: TPoint;
  R: TRect;
  S: TSize;
  BF: _BLENDFUNCTION;
begin
  GetWindowRect(Wnd, R);
  P := Point(0, 0);
  S.cx := Bmp.Width;
  S.cY := Bmp.Height;
  bf.BlendOp := AC_SRC_OVER;
  bf.BlendFlags := 0;
  bf.SourceConstantAlpha := Alpha;
  bf.AlphaFormat := AC_SRC_ALPHA;
  SetWindowLong(wnd, GWL_EXSTYLE, GetWindowLong(wnd, GWL_EXSTYLE) or WS_EX_LAYERED);
  UpdateLayeredWindow(wnd, 0, @R.TopLeft, @S, Bmp.Canvas.Handle, @P, 0, @BF, ULW_ALPHA);
end;

procedure TForm1.FormCreate(Sender: TObject);
//begin
//Color := clWhite;
//TransparentColor := True;
//TransparentColorValue := clWhite;
//end;
var
  BMP: TBitmap;
  GB: TGPBitmap;
  h: HBITMAP;


begin
  Bmp := TBitmap.Create;
  //Bmp.LoadFromFile('C:\Program Files\日程管理\Skins\bg2.bmp');
  GB := TGPBitmap.Create('C:\Program Files\日程管理\Skins\bg3.png');
  //GB := TGPBitmap.Create('C:\Documents and Settings\guo\桌面\png\2.png');
  GB.GetHBITMAP(0, h);
  Bmp.Handle := h;
  //Image1.Picture.Bitmap.Handle:=h;
 //AlphaUpdateLayeredWindow(Handle, Bmp, 200);
  ColorUpdateLayeredWindow(Handle, Bmp, Bmp.TransparentColor);
  Bmp.Free;
  GB.Free;
 // Color := clWhite;
 // TransparentColor := True;
  //TransparentColorValue := clWhite;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -