最近為了要兼容XP系統(守舊的市場),又需要做出產品的特效,不得不從頭學習一下這門 “聰明的語言” 。
開發環境: win10 Delphi 10.2 Version 25.0.26309.314
產品環境:最低xp系統
使用 http://www.bilsen.com/gdiplus/index.shtml 網站下載中的 Gdi+ 1.0
1. 項目dpr文件中引用即可:
uses GdiPlus in '..\PublicLib\GdiPlus\GdiPlus.pas', (本機電腦的存放目錄)
2. 新建Vcl 窗體
3. 來一波代碼(繪制不規則窗體,當然是在窗體創建的時候調用)
TFormPrimary 自建窗體 IrregularInterface 自定義函數(ImageFile 為不規則圖片的路徑)
1 procedure TFormPrimary.IrregularInterface(ImageFile: string); 2 var 3 Bitmap: IGPBitMap; 4 BlendFunc: TBlendFunction; 5 Sz : TSize; 6 Dc : HDC; 7 Bmp,BmpOld : HBITMAP; 8 PtDst, PtSrc : TPoint; 9 begin 10 Bitmap := TGPBitmap.Create(ImageFile); 11 12 Sz.cx := Bitmap.Width; 13 Sz.cy := Bitmap.Height; 14 15 PtDst := TPoint.Create(left,top); 16 PtSrc := TPoint.Create(0, 0); 17 18 BlendFunc.BlendOp := AC_SRC_OVER; 19 BlendFunc.BlendFlags := 0; 20 BlendFunc.AlphaFormat := AC_SRC_ALPHA; 21 BlendFunc.SourceConstantAlpha := 255; 22 23 Bmp := Bitmap.GetHBitmap(0); 24 Dc:= CreateCompatibleDC(Canvas.Handle); 25 BmpOld := SelectObject(Dc,Bmp); 26 27 SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED); 28 UpdateLayeredWindow(Handle, Canvas.Handle , @PtDst, @Sz, Dc, @PtSrc,0,@BlendFunc,ULW_ALPHA); 29 30 SelectObject(Dc,BmpOld); 31 DeleteObject(Bmp); 32 DeleteDC(Dc); 33 end;
4.再來一波 (窗體隨着鼠標拖動)
1 procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 2 Shift: TShiftState; X, Y: Integer); 3 procedure FormMouseUp(Sender: TObject; Button: TMouseButton; 4 Shift: TShiftState; X, Y: Integer); 5 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 6 private 7 { Private declarations } 8 OldPos:TPoint; 9 Move:Boolean;
5.最后一波 (窗體拖動的實現)
1 procedure TFormPrimary.FormMouseDown(Sender: TObject; Button: TMouseButton; 2 Shift: TShiftState; X, Y: Integer); 3 begin 4 Move := True; 5 GetCursorPos(OldPos); 6 end; 7 8 procedure TFormPrimary.FormMouseMove(Sender: TObject; Shift: TShiftState; X, 9 Y: Integer); 10 var 11 NewPos: TPoint; 12 begin 13 if not Move then Exit; 14 GetCursorPos(NewPos); 15 Left := Left + (NewPos.X - OldPos.X); 16 Top := Top + (NewPos.Y - OldPos.Y); 17 GetCursorPos(OldPos); 18 end; 19 20 procedure TFormPrimary.FormMouseUp(Sender: TObject; Button: TMouseButton; 21 Shift: TShiftState; X, Y: Integer); 22 begin 23 Move := False; 24 end;
6.最后的是vcl窗體的Style
7.效果 (箭頭指向處)
Ps:Delphi初學,敬請見諒(邊學邊做,大概花了5天時間)