不知各位有没有用过“笨笨钟”,我觉得其中的鼠标穿透功能非常离奇,而且实用至极
一个半透明的窗口显示在桌面最上面,象个影子一样,完全不影响其它窗口的操作,如同这个窗口不存在一样,只是看到它的一个“影子”。
试问各位高手,如何实现这种功能

解决方案 »

  1.   

    这个不是我想找的那篇,不过你先看看吧
    http://community.csdn.net/Expert/topic/3235/3235878.xml?temp=7.049197E-02
      

  2.   

    应该就是这种效果的!
      SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or
                                         WS_EX_TRANSPARENT or //忽略一切消息(WM_PAINT除外)
                                         WS_EX_LAYERED);      //层风格,有他才能支持半透明
      

  3.   

    procedure CreateWnd;override;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.CreateWnd;
    begin
      inherited CreateWnd;
      SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or
        WS_EX_LTRREADING or
        WS_EX_TRANSPARENT or
        WS_EX_TOPMOST or
        WS_EX_TOOLWINDOW or
        WS_EX_LAYERED);
      SetLayeredWindowAttributes(Handle, Color, 150, LWA_ALPHA or LWA_COLORKEY);
    end;
    end.
      

  4.   

    //做成控件了,支持透明度,支持鼠标穿透。
    unit TransForm; {DragonPC 2001.2.21 }interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms ;type
      TTranForm = class(TComponent)
        private
          FAlphaValue: integer ;
          FTransMouse: Boolean;
          FParentFormHandle: HWND ;
          procedure SetFAlphaValue(Alpha:integer);
          procedure SetTransMouse(value: Boolean);
        protected
          procedure UpdateDisplay;
        public
          constructor Create(AOwner: TComponent); override;
        published
          property AlphaValue: integer read FAlphaValue write SetFAlphaValue ;
          property TransMouse: Boolean read FTransMouse write SetTransMouse;
        end;procedure Register;function SetLayeredWindowAttributes(Handle: HWND; COLORKEY: COLORREF;
      Alpha: BYTE; Flags: DWORD): Boolean; stdcall; external 'USER32.DLL';implementationprocedure Register;
    begin
      RegisterComponents('Standard', [TTranForm]);
    end;procedure TTranForm.SetFAlphaValue(Alpha: integer);
      begin
       if (Alpha >= 0) and (Alpha < 256) then begin
       FAlphaValue := Alpha ;
       UpdateDisplay() ;
      end;
    end;procedure TTranForm.UpdateDisplay;
    begin
     if (csDesigning in ComponentState) then Exit ;
       SetLayeredWindowAttributes(FParentFormHandle, 0, FAlphaValue, 2);
    end;constructor TTranForm.Create(AOwner: TComponent);
    begin
      inherited;
      if (csDesigning in ComponentState) then
        Exit;
      FAlphaValue := 255 ;
      FParentFormHandle := TForm(AOwner).Handle ;
      SetWindowLong(FParentFormHandle, GWL_EXSTYLE,
             GetWindowLong(FParentFormHandle, GWL_EXSTYLE) or $80000);
    end;procedure TTranForm.SetTransMouse(value: Boolean);
    begin
      if FTransMouse <> value then
      begin
        FTransMouse := value;
        if value then
          SetWindowLong(FParentFormHandle, GWL_EXSTYLE,
                 GetWindowLong(FParentFormHandle, GWL_EXSTYLE) or WS_EX_TRANSPARENT)
        else
          SetWindowLong(FParentFormHandle, GWL_EXSTYLE,
                 GetWindowLong(FParentFormHandle, GWL_EXSTYLE) and not WS_EX_TRANSPARENT);
      end;
    end;end.