www.pudn.com > IsMenu-v1.4.rar > tsForm.pas, change:2014-08-11,size:9426b


//一句(关键)代码实现全透明 by diystar.cnblogs.com 
//改进版0.2:减少拖动闪烁 
//改进版0.3:改进Win7兼容性 
//改进版0.4:提高性能 
//改进版0.5:完美版,进一步提高性能,彻底解决Win7兼容性 
//改进版0.6:gdi+版,果然强大易用,压轴!与前面版本虽形式不同,内里是一致的 
//0.6版 主要贡献者 Aric Green http://www.codeproject.com/KB/GDI-plus/DesktopLyrics.aspx 
//以及 无幻 http://blog.csdn.net/akof1314/archive/2011/05/18/6430583.aspx 
//期待你的改进,别忘了发我一份wang_zm@163.com 
 
unit tsForm; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, Registry, ExtCtrls, gdipapi, gdipobj, Menus, CoolTrayIcon, 
  StdCtrls; 
type 
  TForm1 = class(TForm) 
    CheckBox6: TCheckBox; 
    procedure FormCreate(Sender: TObject); 
    procedure FormDestroy(Sender: TObject); 
    procedure FormActivate(Sender: TObject); 
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure FormPaint(Sender: TObject); 
  private 
    { Private declarations } 
    procedure ShadowText(Bk: TGPGraphics; f:TGPFont; c,Shadow:TGPColor; l,t, 
      w,h: Single; Text: String); 
 
  public 
  procedure UpdateDisplay(r: TRect); 
    { Public declarations } 
  end; 
 
var 
  Form1: TForm1; 
  str:string; 
implementation 
uses Unit2; 
{$R *.dfm} 
 
var 
  hdcScreen,m_hdcMemory: HDC; 
  g: TGPGraphics; 
 
 
 
 
 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
  hdcTemp:HDC; 
  hBitMap:Windows.HBITMAP; 
begin 
//  SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); //不在任务栏出现 
   
  Self.BorderStyle:=bsNone; 
  SetWindowLong(Self.Handle, 
                GWL_EXSTYLE, 
                GetWindowLong(Self.Handle,GWL_EXSTYLE) 
                or WS_EX_LAYERED); //层次窗口 
 
  hdcTemp := GetDC(Self.Handle); 
  m_hdcMemory := CreateCompatibleDC(hdcTemp); 
  hBitMap := CreateCompatibleBitmap(hdcTemp,ClientWidth,ClientHeight); 
  SelectObject(m_hdcMemory,hBitMap); 
  hdcScreen := GetDC(Self.Handle); 
  g := TGPGraphics.Create(m_hdcMemory); 
  if Win32MajorVersion>5 then 
  g.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit); 
  ReleaseDC(Self.Handle,hdcTemp); 
  DeleteObject(hBitMap); 
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
begin 
  ReleaseDC(Self.Handle,hdcScreen); 
  DeleteDC(m_hdcMemory); 
end; 
 
procedure TForm1.FormActivate(Sender: TObject); 
begin 
  Self.Refresh; 
end; 
 
procedure TForm1.UpdateDisplay(r: TRect); 
var 
  p: TGPPen; 
  w,h,x,y: integer; 
  brush: TGPSolidBrush; 
  pen:TGPPen; 
  f:TGPFont; 
  GPRectF: TGPRectF; 
  r2:TRect; 
  blend: BLENDFUNCTION; 
  ptWinPos,ptSrc: TPoint; 
  sizeWindow: SIZE; 
begin 
  //处理边框和文字 
  g.SetCompositingMode(CompositingModeSourceCopy); 
  brush := TGPSolidBrush.Create(MakeColor(1,100,100,100)); //填充颜色 
  g.SetClip(MakeRect(r)); 
  g.FillRectangle(brush,MakeRect(r)); 
  g.SetCompositingMode(CompositingModeSourceOver); 
  r2:=ClientRect; 
  r2.Bottom:=r2.Bottom-1;//下边边框距离 
  r2.Right:=r2.Right-1;    //右边边框距离 
  pen := TGPPen.Create(MakeColor(64,0,0,0),1); //最后一个参数画笔宽 
  g.DrawRectangle(pen,MakeRect(r2)); 
  InflateRect(r2,-1,-1); 
  pen.SetColor(MakeColor(150,255,255,255));  //变宽透明度、颜色 
  g.DrawRectangle(pen,MakeRect(r2)); 
  f:=TGPFont.Create(Self.Font.Name,10);       //字体大小 
  //f:=TGPFont.Create(Self.Font.Name,Self.Font.Size);  字体样式、大小 
  GPRectF:=MakeRect(0.0,0,ClientWidth,ClientHeight); 
  g.MeasureString('IsMenu v1.4.1 by isaac 【快捷方式管理】QQ:236572970',-1,f,GPRectF,GPRectF);//获取字符串宽度高度 
  ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(78,35,192,23),10,10,GPRectF.Width,GPRectF.Height,'IsMenu v1.4.1 by isaac 【快捷方式管理】QQ:236572970');        //标题 
  if Form2.sShellListView1.Visible=True then 
  ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(78,200,135,215),10,25,GPRectF.Width,GPRectF.Height,'使用方法:直接将任意文件拖放到此程序上');        //标题 
  if Form2.sShellListView1.Visible=False then 
  begin 
  f:=TGPFont.Create(Self.Font.Name,10); 
  ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(100,238,29,108),(100),105,GPRectF.Width,GPRectF.Height,'按钮名称为红色时表示现在所在分类'); 
 { ShadowText(g,f,MakeColor(254,10,255,4),MakeColor(100,0,0,0),(30),70,GPRectF.Width,GPRectF.Height,'-------'); 
  ShadowText(g,f,MakeColor(254,10,255,4),MakeColor(100,0,0,0),98,70,GPRectF.Width,GPRectF.Height,'-------'); 
  ShadowText(g,f,MakeColor(254,10,255,4),MakeColor(100,0,0,0),(166),70,GPRectF.Width,GPRectF.Height,'-------'); 
  ShadowText(g,f,MakeColor(254,10,255,4),MakeColor(100,0,0,0),(234),70,GPRectF.Width,GPRectF.Height,'-------'); 
  ShadowText(g,f,MakeColor(254,10,255,4),MakeColor(100,0,0,0),(302),70,GPRectF.Width,GPRectF.Height,'-------'); 
  ShadowText(g,f,MakeColor(254,255,255,4),MakeColor(100,0,0,0),(370),70,GPRectF.Width,GPRectF.Height,'----'); } 
 
 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,0,0,255),(22),135,GPRectF.Width,GPRectF.Height,'设置中心:'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,0,0,255),(22),155,GPRectF.Width,GPRectF.Height,'一.拖动文件为lnk快捷方式文件时,是否删除原快捷方式'); 
  // ShadowText(g,f,MakeColor(254,255,255,4),MakeColor(100,0,0,0),(22),155,GPRectF.Width,GPRectF.Height,'   文件时,是否删除原快捷方式'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,0,0,255),(22),175,GPRectF.Width,GPRectF.Height,'二.此程序是否需要开机启动'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,0,0,255),(22),195,GPRectF.Width,GPRectF.Height,'三.此程序存放快捷方式目录'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,0,0,255),(22),215,GPRectF.Width,GPRectF.Height,'四.完全自定义按钮名称,按自己的习惯分类'); 
 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(78,35,192,23),(100),342,GPRectF.Width,GPRectF.Height,'IsMenu v1.4.1 小巧、绿色、干净、无广告、终身免费'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(108,23,35,192),(20),360,GPRectF.Width+50,GPRectF.Height,'关闭此显示,请右键单击托盘选择帮助----Isaac 2014.8.11'); 
  f:=TGPFont.Create(Self.Font.Name,10); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,255,0,0),(22),245,GPRectF.Width,GPRectF.Height+5,'使用方法:'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,255,0,0),(22),265,GPRectF.Width,GPRectF.Height+5,'一.直接将各种文件拖放到本程序上'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,255,0,0),(22),285,GPRectF.Width,GPRectF.Height+5,'二.在该程序上对准各种快捷方式进行操作'); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,255,0,0),(22),305,GPRectF.Width+100,GPRectF.Height,'...左键双击打开,右键-打开、刷新、重命名、删除、查找目录'); 
  f:=TGPFont.Create(Self.Font.Name,10); 
   ShadowText(g,f,MakeColor(254,255,255,255),MakeColor(150,255,0,0),(40),320,GPRectF.Width+100,GPRectF.Height+5,'功能虽然简单,但是很实用。用来还你一个干净、绿色的桌面'); 
 
 
  brush.Free; 
  pen.Free; 
  f.Free; 
  // 
 
  p := TGPPen.Create(0, 2);                      //绘制矩形 
  p.SetColor(aclBlue); 
  g.DrawRectangle(p, 13, 35, 342, 40); 
//  g.DrawLine(p, 20, 40, 200, 40); 
  g.DrawRectangle(p, 95, 102, 220, 18);                                 {参数是整数} 
  g.DrawLine(p, MakePoint(13,75), MakePoint(200,100)); 
  g.DrawLine(p, MakePoint(200,100), MakePoint(355,75));            {参数是点(整数)} 
  p.SetColor(aclRed); 
  g.DrawRectangle(p, 359, 35, 45, 40); 
  g.DrawLine(p, MakePoint(385,75), MakePoint(385,130)); 
  g.DrawRectangle(p, 18, 130, 385, 105); 
  p.SetColor(aclDarkKhaki); 
  g.DrawRectangle(p, 18, 240, 385, 95); 
  p.Free; 
  end; 
 
 
  with blend do 
  begin  
    BlendOp := AC_SRC_OVER; 
    BlendFlags := 0; 
    AlphaFormat := AC_SRC_ALPHA; 
    SourceConstantAlpha := 255; 
  end; 
  ptWinPos := Point(Self.Left,Self.Top); 
  sizeWindow.cx := ClientWidth; 
  sizeWindow.cy := ClientHeight; 
  ptSrc := Point(0,0); 
 
  //关键的一句 
  UpdateLayeredWindow(Self.Handle, 
                                hdcScreen, 
                                @ptWinPos, 
                                @sizeWindow, 
                                m_hdcMemory, 
                                @ptSrc, 
                                0, 
                                @blend, 
                                ULW_ALPHA); 
end; 
 
procedure TForm1.ShadowText(Bk: TGPGraphics; f: TGPFont; c,Shadow: TGPColor; 
  l,t,w,h: Single; Text: String); 
var 
  strFormat: TGPStringFormat; 
  brush: TGPSolidBrush; 
  pen:TGPPen; 
  i,j:Single; 
 
  procedure DrawText; 
  begin 
    g.DrawString(Text,-1,f,MakeRect(i,j,w,h),strFormat,brush); 
  end; 
 
begin 
  strFormat := TGPStringFormat.Create(); 
  brush := TGPSolidBrush.Create(Shadow); 
  pen:=TGPPen.Create(Shadow); 
 
  i:=l+1; j:=t+1; DrawText; 
  i:=l-1; j:=t-1; DrawText; 
  i:=l+1; j:=t-1; DrawText; 
  i:=l-1; j:=t+1; DrawText; 
  i:=l  ; j:=t+1; DrawText; 
  i:=l  ; j:=t-1; DrawText; 
  i:=l+1; j:=t;   DrawText; 
  i:=l-1; j:=t;   DrawText; 
 
  brush.SetColor(c); 
  pen.SetColor(c); 
  i:=l;   j:=t;   DrawText; 
 
  strFormat.Free; 
  brush.Free; 
  pen.Free; 
end; 
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
begin 
  ReleaseCapture; 
  SendMessage(form2.Handle, WM_SYSCOMMAND,SC_MOVE+HTCAPTION, 0);   //无边框移动 
end; 
 
 
 
procedure TForm1.FormPaint(Sender: TObject); 
begin 
UpdateDisplay(ClientRect); 
end; 
 
end.