中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>系统函数>文章内容

delphi 切换界面的方法

来源:国外 关于:William Egge 发布时间:2007-07-03   [收藏] [推荐]
Problem/Question/Abstract:
Bored? Like playing tricks on your coworkers? I tested it out on my bosses secretary and it was fun, so I'll share it with you. BUT its just not fun, it also contains usefull classes.
Answer:
Fun program to trick your friends, secretary or anyone with a computer :-). The program flips your desktop upside down until you click on it.
BUT, this does have some interesting code.
It contains TDesktopCanvas where you can access your desktop through a TCanvas object.
It contains TQuickPixel which gives you high speed pixel access, btw - it caches the scan lines for even faster performance.
Download the source, it is fairly easy to follow. Compile it and stick it in your friends startup folder :-) or just run it and walk away.
To end the program just click the inverted screen.
Now for the usefull part as far as coding:
A class I made so I could have fast pixel access without fumbling with scan lines.  This class caches the scan lines for faster perfomance. One drawback of this class is that it sets your Bitmap to 24bit.  If you want me to build a class that supports all bit formats then please make a comment to do so and I can build one without causing a performance hit (use method pointers so there is no testing of bit format). I will also speed up the pixel setting to work without the shifts if anyone asks for the multiple format thing. As a side note I think it would be possible to include Line, arc and circle methods... but only if there is enough interest. Windows is really slow about drawing.
Here is the code for TQuickPixel. You can also go to my website for working EXE and download full source.
unit QuickPixel;
interface
uses
  Windows, Graphics;
type
  TQuickPixel = class
  private
    FBitmap: TBitmap;
    FScanLines: array of PRGBTriple;
    function GetPixel(X, Y: Integer): TColor;
    procedure SetPixel(X, Y: Integer; const Value: TColor);
    function GetHeight: Integer;
    function GetWidth: Integer;
  public
    constructor Create(const ABitmap: TBitmap);
    property Pixel[X, Y: Integer]: TColor read GetPixel write SetPixel;
    property Width: Integer read GetWidth;
    property Height: Integer read GetHeight;
  end;
implementation
{ TQuickPixel }
constructor TQuickPixel.Create(const ABitmap: TBitmap);
var
  I: Integer;
begin
  inherited Create;
  FBitmap := ABitmap;
  FBitmap.PixelFormat := pf24bit;
  SetLength(FScanLines, FBitmap.Height);
  for I := 0 to FBitmap.Height - 1 do
    FScanLines[I] := FBitmap.ScanLine[I];
end;
function TQuickPixel.GetHeight: Integer;
begin
  Result := FBitmap.Height;
end;
function TQuickPixel.GetPixel(X, Y: Integer): TColor;
var
  P: PRGBTriple;
begin
  P := FScanLines[Y];
  Inc(P, X);
  Result := (P^.rgbtBlue shl 16) or (P^.rgbtGreen shl 8) or P^.rgbtRed;
end;
function TQuickPixel.GetWidth: Integer;
begin
  Result := FBitmap.Width;
end;
procedure TQuickPixel.SetPixel(X, Y: Integer; const Value: TColor);
var
  P: PRGBTriple;
begin
  P := FScanLines[Y];
  Inc(P, X);
  P^.rgbtBlue := (Value and $FF0000) shr 16;
  P^.rgbtGreen := (Value and $00FF00) shr 8;
  P^.rgbtRed := Value and $0000FF;
end;
end.
unit DesktopCanvas;
// original aurthor is Erwin Molendijk
interface
uses
  Graphics, Windows;
type
  TDesktopCanvas = class(TCanvas)
  private
    FDC: HDC;
    function GetWidth: Integer;
    function GetHeight: Integer;
  public
    constructor Create;
    destructor Destroy; override;
  published
    property Width: Integer read GetWidth;
    property Height: Integer read GetHeight;
  end;
implementation
{ TDesktopCanvas }
function TDesktopCanvas.GetWidth: Integer;
begin
  Result := GetDeviceCaps(Handle, HORZRES);
end;
function TDesktopCanvas.GetHeight: Integer;
begin
  Result := GetDeviceCaps(Handle, VERTRES);
end;
constructor TDesktopCanvas.Create;
begin
  inherited Create;
  FDC := GetDC(0);
  Handle := FDC;
end;
destructor TDesktopCanvas.Destroy;
begin
  Handle := 0;
  ReleaseDC(0, FDC);
  inherited Destroy;
end;
end.

[浏览: 次]   
上一篇:delphi CapsLock打开与关闭   下一篇:delphi 如何注册剪切板的格式
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi Delphi中ShellExecute的妙用
·delphi 如何快速读取文本文件
·delphi 如何判断输入值是否中文
·delphi 在应用层截获键盘消息
·delphi delphi实现服务开启与关闭
·delphi 实时记录事件日志
·delphi 使MEMO自动滚动
·delphi 如何区分键盘两个Enter键
·delphi 汉字输入法的编程及使用
·delphi Delphi程序输入法自动切换最简
·delphi 程序缩小为任务右下角的小图标
·delphi 消息是由谁来发出又由谁来完成
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932