如何把一个窗体做成透明窗体?谢谢!在线等!

解决方案 »

  1.   

    设置Form的AlphaBlend为True设置AlphaBlendValue 为150,半透明效果,透明度可使用该值设置。
      

  2.   

    Form1.brush.style:=bsclear;
      Form1.borderstyle:=bsnone;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls;type
      TLoves = class(TForm)
        Image1: TImage;    
        procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        procedure CreateParams(Var Params:TCreateParams);override;
        function CreateRegion(wMask: TBitmap; wColor: TColor;hControl: THandle): HRGN;
      public
        { Public declarations }
      end;var
      Loves: TLoves;implementation
    {$R *.DFM}procedure TLoves.Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      ReleaseCapture;
      SendMessage(Handle, WM_SYSCOMMAND, $F012, 0);
    end;
    procedure tloves.CreateParams(var Params:TCreateParams);
    begin
      inherited;
      With Params do
      begin
        wndParent:=GetDesktopwindow;
        ExStyle:=ExStyle or WS_EX_TOPMOST;
      end;
    end;
    procedure TLoves.FormCreate(Sender: TObject);
    var
      w1:TBitmap;
      w2:TColor; 
      rgn: HRGN;
    begin
      ShowWindow(Application.handle,sw_hide);
      SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
      w1:=TBitmap.Create; 
      w1.Assign(image1.Picture.Bitmap); 
      w2:=w1.Canvas.Pixels[0,0];
      rgn := CreateRegion(w1,w2,Handle); 
      if rgn<>0 then
      begin
         SetWindowRgn(Handle, rgn, true); 
      end; 
      w1.Free; 
    end;
    function TLoves.CreateRegion(wMask: TBitmap; wColor: TColor;
      hControl: THandle): HRGN;
    var 
      dc, dc_c: HDC; 
      rgn: HRGN; 
      x, y: integer; 
      coord: TPoint;
      line: boolean; 
      color: TColor; 
    begin 
      dc := GetWindowDC(hControl); 
      dc_c := CreateCompatibleDC(dc); 
      SelectObject(dc_c, wMask.Handle); 
      BeginPath(dc); 
      for x:=0 to wMask.Width-1 do 
      begin 
        line := false;
        for y:=0 to wMask.Height-1 do 
        begin 
          color := GetPixel(dc_c, x, y); 
          if not (color = wColor) then 
          begin 
            if not line then 
            begin 
              line := true; 
              coord.x := x; 
              coord.y := y; 
            end; 
          end; 
          if (color = wColor) or (y=wMask.Height-1) then 
          begin 
            if line then 
            begin 
              line := false; 
              MoveToEx(dc, coord.x, coord.y, nil); 
              LineTo(dc, coord.x, y); 
              LineTo(dc, coord.x + 1, y); 
              LineTo(dc, coord.x + 1, coord.y);
              CloseFigure(dc);
            end; 
          end;
        end; 
      end;
      EndPath(dc);
      rgn := PathToRegion(dc);
      ReleaseDC(hControl, dc);
      Result := rgn;
    end;end.
      

  4.   

    function SetLayeredWindowAttributes(hwnd:HWND; crKey:Longint; bAlpha:byte; dwFlags:longint ):longint; stdcall; external user32;
    //////////
    procedure TFGateControl.FormShow(Sender: TObject);
    begin
    //  设置透明窗体
      SetWindowLong(self.Handle, GWL_EXSTYLE, GetWindowLong(self.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
      SetLayeredWindowAttributes(handle, 0, 180, lwa_alpha);end;