delphi的属性语句可以直接用在函数中吗?wParam和iParam可以直接用delphi的语句吗?比如
Form1.AlphaBlend:=True;
Form1.AlphaBlendValue:=100;可以在SetWindowLong里直接用或改成WS_AlphaBlend就可以了nIndex就是这样用吗?

解决方案 »

  1.   

    我也没有听懂楼主问什么问题/
    “delphi的属性语句可以直接用在函数中吗?”
    那要视场合而定
      

  2.   

    Form1.AlphaBlend:=True;
    Form1.AlphaBlendValue:=100属性,可以在SetWindowLong里直接用AlphaBlend取代wParam和iParam,或改成WS_AlphaBlend就可以通过了,nIndex就是这样用吗?
      

  3.   

    unit SGlass;
    {*******************************************************
     *          TStainedGlass version 14.06.99             *
     *            written by Grigoriev Anton               *
     *                                                     *
     *******************************************************} interface  uses Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,Math;   type TTransparencyStyle=(tsConstant,tsHorGradient,tsVertGradient,tsCustom);
            TBackgroundStyle=(bsSimple,bsMosaic,bsCentered,bsStretched,bsCustom);
            TTransparency=0..100;        TGetTransparencyEvent=procedure(Sender:TObject;X,Y,Width,Height:Integer;var Transparency:TTransparency) of object;
            TCreateBackgroundEvent=procedure(Sender:TObject;Back:TBitmap) of object;        TStainedGlass=class(TComponent)
                           private
                            FGlyph,ScrImage,Back:TBitmap;
                            FTranspStyle:TTransparencyStyle;
                            FBackStyle:TBackgroundStyle;
                            OldWidth,OldHeight:Integer;
                            FTransparency,FAltTransparency:TTransparency;
                            FDrawOnDesigning:Boolean;
                            OldWndProc:TFarProc;
                            NewWndProc:Pointer;
                            NeedRefresh,Moving:Boolean;
                            FDelayTime:Cardinal;
                            FOnGetTransparency:TGetTransparencyEvent;
                            FOnCreateBackground:TCreateBackgroundEvent;
                            procedure HookOwner;
                            procedure UnhookOwner;
                            procedure SetAltTransparency(Value:TTransparency);
                            procedure SetBackStyle(Value:TBackgroundStyle);
                            procedure SetDrawOnDesigning(Value:Boolean);
                            procedure SetGlyph(Value:TBitmap);
                            procedure SetTransparency(Value:TTransparency);
                            procedure SetTranspStyle(Value:TTransparencyStyle);
                            function ConstantTransparency(X,Y,W,H:Integer):TTransparency;
                            function HGTransparency(X,Y,W,H:Integer):TTransparency;
                            function VGTransparency(X,Y,W,H:Integer):TTransparency;
                            function CustomTransparency(X,Y,W,H:Integer):TTransparency;
                            procedure GlyphChanged(Sender:TObject);
                           protected
                            procedure CreateBack(W,H:Integer);
                            procedure CallDefault(var Msg:TMessage);
                            procedure HookWndProc(var Msg:TMessage);virtual;
                           public
                            constructor Create(AOwner:TComponent);override;
                            destructor Destroy;override;
                            procedure Refresh;
                           published
                            property AltTransparency:TTransparency read FAltTransparency write SetAltTransparency default 100;
                            property BackStyle:TBackgroundStyle read FBackStyle write SetBackStyle default bsSimple;
                            property DelayTime:Cardinal read FDelayTime write FDelayTime default 400;
                            property DrawOnDesigning:Boolean read FDrawOnDesigning write SetDrawOnDesigning default False;
                            property Glyph:TBitmap read FGlyph write SetGlyph;
                            property Transparency:TTransparency read FTransparency write SetTransparency default 40;
                            property TranspStyle:TTransparencyStyle read FTranspStyle write SetTranspStyle default tsConstant;
                            property OnCreateBackground:TCreateBackgroundEvent read FOnCreateBackground write FOnCreateBackground default nil;
                            property OnGetTransparency:TGetTransparencyEvent read FOnGetTransparency write FOnGetTransparency default nil;
                          end;    procedure Register; implementation  type TTransparencyFunc=function(X,Y,W,H:Integer):TTransparency of object;       PRGBArray=^TRGBArray;
           TRGBArray=array[0..1000000] of TRGBTriple;   constructor TStainedGlass.Create;
        var I:Integer;
         begin
          if not (AOwner is TForm) then
           raise EInvalidCast.Create('TStainedGlass can be put on TForm or its destendant only');
          with AOwner do
           for I:=0 to ComponentCount-1 do
            if (Components[I] is TStainedGlass) and (Components[I]<>Self) then
             raise EComponentError.Create('Only one TStainedGlass component on a form is allowed');
          inherited Create(AOwner);
          FGlyph:=TBitmap.Create;
          FGlyph.OnChange:=GlyphChanged;
          ScrImage:=TBitmap.Create;
          ScrImage.Width:=GetSystemMetrics(SM_CXScreen);
          ScrImage.Height:=GetSystemMetrics(SM_CYScreen);
          ScrImage.PixelFormat:=pf24Bit;
          Back:=TBitmap.Create;
          Back.PixelFormat:=pf24Bit;
          OldWidth:=-1;
          OldHeight:=-1;
          NeedRefresh:=True;
          FAltTransparency:=100;
          FBackStyle:=bsSimple;
          FTransparency:=40;
          FTranspStyle:=tsConstant;
          FDelayTime:=400;
          Moving:=False;
          FOnCreateBackground:=nil;
          FOnGetTransparency:=nil;
          HookOwner
         end;   destructor TStainedGlass.Destroy;
        begin
         UnhookOwner;
         ScrImage.Free;
         FGlyph.Free;
         Back.Free;
         inherited Destroy
        end;   procedure TStainedGlass.HookOwner;
        begin
         if not Assigned(Owner) then
          Exit;
         OldWndProc:=TFarProc(GetWindowLong(TForm(Owner).Handle,GWL_WndProc));
         NewWndProc:=MakeObjectInstance(HookWndProc);
         SetWindowLong(TForm(Owner).Handle,GWL_WndProc,LongInt(NewWndProc))
        end;   procedure TStainedGlass.UnhookOwner;
        begin
         if Assigned(Owner) and Assigned(OldWndProc) then
          SetWindowLong(TForm(Owner).Handle,GWL_WndProc,LongInt(OldWndProc));
         if Assigned(NewWndProc) then
          FreeObjectInstance(NewWndProc);
         NewWndProc:=nil;
         OldWndProc:=nil
        end;
      

  4.   

    procedure TStainedGlass.CallDefault;
        begin
         Msg.Result:=CallWindowProc(OldWndProc,TForm(Owner).Handle,Msg.Msg,Msg.wParam,Msg.lParam)
        end;   procedure TStainedGlass.HookWndProc;
        var DC:HDC;
            PS:TPaintStruct;
            CW,CH,CX,CY:Integer;
            SL,BL:PRGBArray;
            X,Y,T:Integer;
            TicksNow:Integer;
            BM2:TBitmap;
            TranspFunc:TTransparencyFunc;
         begin
          case Msg.Msg of
           WM_Paint:if (csDesigning in ComponentState) and not FDrawOnDesigning then
                     CallDefault(Msg)
                    else
                     with Owner as TForm do
                      begin
                       if Msg.WParam<>0 then
                        raise EComponentError.Create('TStainedGlass: incompatibilities were detected. See ReadMe file');
                       CW:=ClientWidth;
                       CH:=ClientHeight;
                       CX:=ClientOrigin.X;
                       CY:=ClientOrigin.Y;
                       if not Moving then
                        begin
                         ShowWindow(Handle,SW_Hide);
                         SetActiveWindow(0);
                         TicksNow:=GetTickCount;
                         repeat
                          Application.ProcessMessages
                         until GetTickCount-TicksNow>=DelayTime;
                         DC:=GetDC(0);
                         BitBlt(ScrImage.Canvas.Handle,0,0,ScrImage.Width,ScrImage.Height,DC,0,0,SrcCopy);
                         ReleaseDC(0,DC)
                        end;
                       BM2:=TBitmap.Create;
                       BM2.Width:=CW+1;
                       BM2.Height:=CH+1;
                       BM2.PixelFormat:=pf24bit;
                       BM2.Canvas.Draw(-CX,-CY,ScrImage);
                       if NeedRefresh or (CW<>OldWidth) or (CH<>OldHeight) then
                        CreateBack(CW,CH);
                       case FTranspStyle of
                        tsConstant:TranspFunc:=ConstantTransparency;
                        tsHorGradient:TranspFunc:=HGTransparency;
                        tsVertGradient:TranspFunc:=VGTransparency;
                        tsCustom:if Assigned(FOnGetTransparency) then
                                  TranspFunc:=CustomTransparency
                                 else
                                  TranspFunc:=ConstantTransparency
                       end;
                       for Y:=0 to CH do
                        begin
                         SL:=BM2.ScanLine[Y];
                         BL:=Back.ScanLine[Y];
                         for X:=0 to CW do
                          begin
                           T:=TranspFunc(X,Y,CW,CH);
                           SL[X].rgbtRed:=(T*SL[X].rgbtRed+(100-T)*BL[X].rgbtRed) div 100;
                           SL[X].rgbtGreen:=(T*SL[X].rgbtGreen+(100-T)*BL[X].rgbtGreen) div 100;
                           SL[X].rgbtBlue:=(T*SL[X].rgbtBlue+(100-T)*BL[X].rgbtBlue) div 100
                          end
                        end;
                       ShowWindow(Handle,SW_Show);
                       Msg.WParam:=BeginPaint(Handle,PS);
                       BitBlt(Msg.WParam,0,0,BM2.Width,BM2.Height,BM2.Canvas.Handle,0,0,SrcCopy);
                       BM2.Free;
                       CallDefault(Msg);
                       EndPaint(Handle,PS)
                      end;
           WM_EraseBkgnd:if (csDesigning in ComponentState) and not FDrawOnDesigning then
                          CallDefault(Msg)
                         else
                          Msg.Result:=1;
           WM_WindowPosChanged:begin
                                CallDefault(Msg);
                                if not (csDesigning in ComponentState) or FDrawOnDesigning then
                                 TForm(Owner).Invalidate
                               end;
           WM_EnterSizeMove:begin
                             Moving:=True;
                             CallDefault(Msg)
                            end;
           WM_ExitSizeMove:begin
                            CallDefault(Msg);
                            Moving:=False
                           end;
           WM_DisplayChange:begin
                             CallDefault(Msg);
                             ScrImage.Width:=Msg.LParamLo;
                             ScrImage.Height:=Msg.LParamHi;
                             Refresh
                            end
          else
           CallDefault(Msg)
          end
         end;   procedure TStainedGlass.CreateBack;
        var WX,W1,HX,H1,FY,FX:Integer;
         begin
          NeedRefresh:=False;
          OldWidth:=W;
          OldHeight:=H;
          Back.Width:=W+1;
          Back.Height:=H+1;
          with Back.Canvas do
           begin
            Pen.Style:=psClear;
            Brush.Style:=bsSolid;
            Brush.Color:=TForm(Owner).Color;
            Rectangle(0,0,W+1,H+1);
            case FBackStyle of
             bsMosaic:if not FGlyph.Empty then
                       begin
                        WX:=FGlyph.Width;
                        HX:=FGlyph.Height;
                        FY:=0;
                        while FY<H do
                         begin
                          H1:=MinIntValue([H-FY,HX]);
                          FX:=0;
                          while FX<W do
                           begin
                            W1:=MinIntValue([W-FX,WX]);
                            Draw(FX,FY,FGlyph);
                            Inc(FX,W1)
                           end;
                          Inc(FY,H1)
                         end
                       end;
             bsCentered:if not FGlyph.Empty then
                         Draw((W-FGlyph.Width) div 2,(H-FGlyph.Height) div 2,FGlyph);
             bsStretched:if not FGlyph.Empty then
                          StretchDraw(Rect(0,0,W,H),FGlyph);
             bsCustom:if Assigned(FOnCreateBackground) then
                       FOnCreateBackground(Self,Back)
            end
           end
         end;   procedure TStainedGlass.Refresh;
        begin
         NeedRefresh:=True;
         TForm(Owner).Invalidate
        end;   procedure TStainedGlass.SetAltTransparency;
        begin
         if Value<>FAltTransparency then
          begin
           FAltTransparency:=Value;
           if FTranspStyle<>tsConstant then
            TForm(Owner).Invalidate
          end
        end;   procedure TStainedGlass.SetBackStyle;
        begin
         if Value<>FBackStyle then
          begin
           FBackStyle:=Value;
           Refresh
          end
        end;   procedure TStainedGlass.SetDrawOnDesigning;
        begin
         FDrawOnDesigning:=Value;
         if csDesigning in ComponentState then
          TForm(Owner).Invalidate
        end;   procedure TStainedGlass.SetGlyph;
        begin
         FGlyph.Assign(Value);
         Refresh
        end;   procedure TStainedGlass.SetTransparency;
        begin
         if Value<>FTransparency then
          begin
           FTransparency:=Value;
           TForm(Owner).Invalidate
          end
        end;   procedure TStainedGlass.SetTranspStyle;
        begin
         if Value<>FTranspStyle then
          begin
           FTranspStyle:=Value;
           TForm(Owner).Invalidate
          end
        end;   function TStainedGlass.ConstantTransparency;
        begin
         Result:=FTransparency
        end;   function TStainedGlass.HGTransparency;
        begin
         Result:=Transparency+Round((AltTransparency-Transparency)/W*X)
        end;   function TStainedGlass.VGTransparency;
        begin
         Result:=Transparency+Round((AltTransparency-Transparency)/H*Y)
        end;   function TStainedGlass.CustomTransparency;
        begin
         FOnGetTransparency(Self,X,Y,W,H,Result)
        end;   procedure TStainedGlass.GlyphChanged;
        begin
         TForm(Owner).Invalidate
        end;   procedure Register;
        begin
         RegisterComponents('SGlass', [TStainedGlass])
        end; end.这些代码分开2次来发
    以前一位朋友提供的使用控件方法,这个例子如何按以下的方法使用阿
    创建单元文件Unit2
    把上面的单元复制到Unit2中,unit WinLayer改为unit Unit2
    你要设置透明的窗体包含unit2单元
    设置按钮事件
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      SetWindowTransparency(Form1.Handle,40);在这样的例子里如何设置这一句阿
    end;