zoukankan      html  css  js  c++  java
  • 关于显示透空歌词的思路 回复 "zhaoboaidelphi" 的问题


    问题来源: http://www.cnblogs.com/del/archive/2009/12/22/1629717.html#2096734

    1、使用 TransparentColor、TransparentColorValue 给窗体指定透明色;

    2、绘制非透明色的文本, 用 TLabel 呈现文本也可;

    3、处理 WM_NCHITTEST 消息使窗体能够被拖动;

    4、用 Esc 键退出.

    测试代码:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Timer1: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure FormKeyPress(Sender: TObject; var Key: Char);
      private
      protected
        procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
      public
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      FormStyle := fsStayOnTop;
      BorderStyle := bsNone;
      TransparentColor := True;
      TransparentColorValue := Color;
    
      Font.Size := 72;
      Font.Name := 'Arial Black';
    //  DoubleBuffered := True;
    end;
    
    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = Chr(27) then Close;
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      str: string;
    begin
      str := TimeToStr(Now);
      ClientWidth := Canvas.TextWidth(str);
      ClientHeight := Canvas.TextHeight(str);
    
      Canvas.Lock;
      Canvas.Brush.Color := Color;
      Canvas.FillRect(ClientRect);
      Canvas.Brush.Style := bsClear;
      Canvas.Font.Color := clBlack;
      Canvas.TextOut(1, 1, str);
      Canvas.Font.Color := clRed;
      Canvas.TextOut(0, 0, str);
      Canvas.Brush.Style := bsSolid;
      Canvas.Unlock;
    end;
    
    procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
    begin
      Message.Result := HTCAPTION;
    end;
    
    end.
    

  • 相关阅读:
    BDB c++例子,从源码编译到运行
    Linux的nm查看动态和静态库中的符号
    转:js包装DOM对象
    svn笔记4属性Properties
    c++ 友元函数
    转:js包装DOM对象
    整除规则(原理,性质)
    回溯法求幂集
    转:Javascript继承机制的设计思想
    javascript prototype __proto__区别
  • 原文地址:https://www.cnblogs.com/del/p/2046374.html
Copyright © 2011-2022 走看看