delphi 异形窗体可半透明

摘要:
unitxDrawForm;界面Windows、消息、系统工具、类、控件、窗体、菜单、图形、GDIPOBJ、GDIPAPI、GDIPUIL;typeTwwGDIImage=classpublicn_Pos_X:整数;n_Pos_Y:整数;n_宽度:整数;n_高度:
unit xDrawForm;

interface
  uses Windows, Messages, SysUtils, Classes, Controls, Forms, Menus,
  Graphics,GDIPOBJ,GDIPAPI,GDIPUTIL;


type

  TwwGDIImage = class
  public
    n_Pos_X : Integer;
    n_Pos_Y : Integer;
    n_Width : Integer;
    n_Height : Integer;
    GPImageNormal : TGPImage;

    procedure CreateImageNormal(wsFileName: WideString;nPosX,nPosY,nW,nH:Integer);
  end;

  TwwGDIButton = class(TwwGDIImage)
  public
    GPImageHot : TGPImage;
    GPImageDown : TGPImage;
  end;


  TwwCanvas = class(TObject)
  private
    m_hdcMemory: HDC;
    hdcScreen: HDC;
    hBMP: HBITMAP;
    m_Blend: BLENDFUNCTION;
    // 事件
    FGPGraph: TGPGraphics;
    FOnDrawImage: TNotifyEvent;

    procedure BeginDraw(); // 绘图前置工作
    procedure EndDraw(Handle:THandle);   // 绘图收尾工作
   public
    sizeWindow: SIZE;
    ptSrc: TPOINT;
    n_Handle : THandle;
    procedure RePaint(h:THandle);
    procedure InitCanvas(nx,ny:Integer);
    procedure wwDrawImage(wwGDIImage :TwwGDIImage);
    property GPGraph: TGPGraphics read FGPGraph write FGPGraph;
    property OnDrawImage: TNotifyEvent read FOnDrawImage write FOnDrawImage;
  end;


implementation

{ TwwCanvas }

procedure TwwCanvas.BeginDraw;
begin
  // 获取桌面屏幕设备
  hdcScreen := GetDC(0);
  // 创建一个与指定设备兼容的内存设备上下文环境(DC)
  m_hdcMemory := CreateCompatibleDC(hdcScreen);
  // 创建与指定的设备环境相关的设备兼容的位图
  hBMP := CreateCompatibleBitmap(hdcScreen, sizeWindow.cx, sizeWindow.cy );
  // 选择一对象到指定的设备上下文环境中,该新对象替换先前的相同类型的对象
  SelectObject(m_hdcMemory, hBMP);
  // 创建画布
  GPGraph := TGPGraphics.Create(m_hdcMemory);
end;

procedure TwwCanvas.wwDrawImage(wwGDIImage: TwwGDIImage);
begin
  GPGraph.DrawImage(
  wwGDIImage.GPImageNormal,
  wwGDIImage.n_Pos_X,
  wwGDIImage.n_Pos_Y,
  wwGDIImage.n_Width,
  wwGDIImage.n_Height)
end;

procedure TwwCanvas.EndDraw(Handle:THandle);
begin
  //  设置窗体风格
  SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
  //  执行透明混合
  UpdateLayeredWindow(Handle, hdcScreen, nil,@sizeWindow, m_hdcMemory, @ptSrc, 0, @m_Blend, ULW_ALPHA);
  //  设置窗体位置
  SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);

  // 各种释放就对了.. 不然画起来会糊
  GPGraph.ReleaseHDC(m_hdcMemory);
  ReleaseDC(0, hdcScreen);
  hdcScreen := 0;
  DeleteObject(hBMP);
  DeleteDC(m_hdcMemory);
  m_hdcMemory := 0;
  GPGraph.Free;
end;

procedure TwwCanvas.RePaint(h:THandle);
begin
  if Assigned(FOnDrawImage) then
  begin
    BeginDraw();
    FOnDrawImage(Self);
    EndDraw(h);
  end;
end;

procedure TwwCanvas.InitCanvas(nx, ny: Integer);
begin
  m_Blend.BlendOp := AC_SRC_OVER; //   the   only   BlendOp   defined   in   Windows   2000
  m_Blend.BlendFlags := 0; //   Must   be   zero
  m_Blend.AlphaFormat := AC_SRC_ALPHA; //This   flag   is   set   when   the   bitmap   has   an   Alpha   channel
  m_Blend.SourceConstantAlpha := 255;

  sizeWindow.cx := nx;
  sizeWindow.cy := ny;
  ptSrc := Point(0,0);
end;

{ TwwGDIImage }

procedure TwwGDIImage.CreateImageNormal(wsFileName: WideString;nPosX,nPosY,nW,nH:Integer);
begin
  Self.GPImageNormal := TGPImage.Create(wsFileName);
  Self.n_Pos_X := nPosX;
  Self.n_Pos_Y := nPosY;
  Self.n_Width := nW;
  Self.n_Height:= nH;
end;

end.





unit uMainForm;


interface


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


type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);


  private
    { Private declarations }
  public
    procedure DrawImage(Sender: TObject);
    { Public declarations }
  end;


var
  Form1: TForm1;


implementation
uses xDrawForm;
var
  wwCanvas : TwwCanvas = nil;
  img_BackGround:   TwwGDIImage= nil;       // 背景图
//  img_ProgressBar1:  TwwGDIImage= nil;      // 上滚动条
//  img_ProgressBar2:  TwwGDIImage= nil;      // 下滚动条
//  img_Lighting:     TwwGDIImage= nil;       // 闪光点


{$R *.dfm}


procedure TForm1.DrawImage(Sender: TObject);
begin
   TwwCanvas(Sender).wwDrawImage(img_BackGround);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  DoubleBuffered := True;
  BorderStyle := bsNone;
  wwCanvas := TwwCanvas.Create();
  wwCanvas.InitCanvas(872,690);
  wwCanvas.OnDrawImage := Self.DrawImage;




  img_BackGround := TwwGDIImage.Create();
  img_BackGround.CreateImageNormal('BackGround.png',0,0,872,690);


end;


procedure TForm1.FormShow(Sender: TObject);
begin
  wwCanvas.RePaint(Self.Handle);
end;


end.

免责声明:文章转载自《delphi 异形窗体可半透明》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇django-Ajax发送POST请求-csrf跨站请求的三种方式SqlServer Alwayson主副本图标显示问号的原因下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Delphi指针的定义和取值

效果图如下: 要点: 1.指针的2中定义方法 PInteger 和 ^Integer 2.取地址符号 @ 和 Addr函数 3.取内容符号 ^ ,比如MyPointInt1^则是取MyPointInt1指针所指向的内容了。 program MyPoint; //指针详解 {$APPTYPE CONSOLE} usesSysUtils,windows,G...

Delphi Application.MessageBox详解

引数:1. Text:要显示的讯息2. Caption:讯息视窗的标题列文字3. Flags:讯息旗标3.1. 可指定讯息视窗上的图示3.2. 可指定讯息视窗出现的按钮3.3. 可指定预设Focus在哪一个按钮3.4. 可指定是否 Modal3.5. 其他引数说明:Text、Caption 引数为 PCahr 型态,字串型态的变数可用 PChar()转换,...

Delphi源程序格式书写规范

Delphi源程序格式书写规范     1,规范简介   本规范主要规定Delphi源程序在书写过程中所应遵循的规则及注意事项。编写该规范的目的是使公司软件开发人员的源代码书写习惯保持一致。这样做可以使每一个组员都可以理解其它组员的代码,以便于源代码的二次开发记忆系统的维护。 2,一般格式规范 2.1 缩进   缩进就是在当源程序的级改变时为增加可读性而露...

delphi PDF控件介绍

PDF控件介绍 llPDFLib 概述 llPDFLib 是用于创建 PDF 文档的纯 Object Pascal 库。 该库不使用任何 DLL 或外部第三方软件来生成 PDF 文件。 库包括具有属性和方法的 TPDFDocument 组件,如 Delphi 的 TPrinter,但旨在生成 PDF 文件。 特征 真正的 Canvas.Handle (H...

delphi 数组类型

数组类型 数组类型定义了一组指定类型的元素序列,在方括号中填入下标值就可访问数组中的元素。定义数组时,方括号也用来指定可能的下标值。例如,下面的代码中定义了一个有 24 个整数的数组:type    DayTemperatures = array [1..24] of Integer;在数组定义时,你需要在方括号中填入一个子界类型的值,或者用两个有序类型的...

DeWeb进阶 :控件开发 --- 2 改造成DeWeb控件

2、根据纯html,改造成DeWeb控件 如何生成DeWeb支持的控件?其实不难,也就是编译一个符合DeWeb规范的动态链接库DLL即可。DeWeb规范有2点:(1)命名,命名必须是“dw”+“Delphi中相应控件的类名”,如“dwTButton”,“dwTComboBox”,也可以是第三方的控件类名,如“dwTRzPageControl”有时,一个De...