www.pudn.com > Desktop-Manager.rar > Unit1.pas, change:2005-05-01,size:23995b


unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls, DB, ADODB, ExtDlgs,JPEG, Menus, StdCtrls, Grids, 
  DBGrids, Buttons, DBCtrls, shellAPI, Registry, Clipbrd, ToolWin, ComCtrls; 
 
type 
  TForm1 = class(TForm) 
    Panel2: TPanel; 
    Panel3: TPanel; 
    ADOQuery1: TADOQuery; 
    DataSource1: TDataSource; 
    ADOConnection1: TADOConnection; 
    OpenDialog1: TOpenDialog; 
    SavePictureDialog1: TSavePictureDialog; 
    OpenPictureDialog1: TOpenPictureDialog; 
    PopupMenu1: TPopupMenu; 
    LoadFormFile: TMenuItem; 
    LoadManyPic: TMenuItem; 
    SaveToFile: TMenuItem; 
    SaveManyPic: TMenuItem; 
    DeleteFormDB: TMenuItem; 
    MenuSeperator1: TMenuItem; 
    NewPicFile: TMenuItem; 
    OpenPicDataFile: TMenuItem; 
    MenuSeperator4: TMenuItem; 
    Rename: TMenuItem; 
    PicFilt: TMenuItem; 
    ShowAll: TMenuItem; 
    FiltByName: TMenuItem; 
    SetToDesktop: TMenuItem; 
    MenuSeperator2: TMenuItem; 
    CopyToCBoard: TMenuItem; 
    CutToCBoard: TMenuItem; 
    PasteFromCBoard: TMenuItem; 
    MenuSeperator3: TMenuItem; 
    Quit: TMenuItem; 
    Panel4: TPanel; 
    Panel5: TPanel; 
    Splitter2: TSplitter; 
    DBGrid1: TDBGrid; 
    Panel6: TPanel; 
    ScrollBox1: TScrollBox; 
    Image1: TImage; 
    MainMenu1: TMainMenu; 
    sdfsdf1: TMenuItem; 
    Panel1: TPanel; 
    Panel7: TPanel; 
    CoolBar1: TCoolBar; 
    DBText1: TDBText; 
    Label1: TLabel; 
    Label2: TLabel; 
    Label3: TLabel; 
    Panel8: TPanel; 
    SpeedButton1: TSpeedButton; 
    SpeedButton2: TSpeedButton; 
    SpeedButton3: TSpeedButton; 
    SpeedButton4: TSpeedButton; 
    SpeedButton5: TSpeedButton; 
    SpeedButton6: TSpeedButton; 
    LoadFromFile2: TMenuItem; 
    LoadFromFiles2: TMenuItem; 
    SaveFile2: TMenuItem; 
    SaveFiles2: TMenuItem; 
    N1: TMenuItem; 
    NewDataFile2: TMenuItem; 
    OpenDataFile2: TMenuItem; 
    N3: TMenuItem; 
    Exit2: TMenuItem; 
    N4: TMenuItem; 
    Copy2: TMenuItem; 
    Cut2: TMenuItem; 
    Paste2: TMenuItem; 
    N5: TMenuItem; 
    Delete2: TMenuItem; 
    N2: TMenuItem; 
    RenamePic2: TMenuItem; 
    PicFilt2: TMenuItem; 
    ShowAllPic2: TMenuItem; 
    FiltByName2: TMenuItem; 
    SetDesktop2: TMenuItem; 
    H1: TMenuItem; 
    About: TMenuItem; 
    procedure FormCreate(Sender: TObject); 
    procedure LoadFormFileClick(Sender: TObject); 
    procedure SaveToFileClick(Sender: TObject); 
    procedure QuitClick(Sender: TObject); 
    procedure SpeedButton1Click(Sender: TObject); 
    procedure SpeedButton2Click(Sender: TObject); 
    procedure SpeedButton5Click(Sender: TObject); 
    procedure DeleteFormDBClick(Sender: TObject); 
    procedure RenameClick(Sender: TObject); 
    procedure Image1Click(Sender: TObject); 
    procedure SetToDesktopClick(Sender: TObject); 
    procedure SpeedButton6Click(Sender: TObject); 
    procedure CopyToCBoardClick(Sender: TObject); 
    procedure CutToCBoardClick(Sender: TObject); 
    procedure PasteFromCBoardClick(Sender: TObject); 
    procedure FiltByNameClick(Sender: TObject); 
    procedure ShowAllClick(Sender: TObject); 
    procedure DataSource1DataChange(Sender: TObject; Field: TField); 
    procedure OpenPicDataFileClick(Sender: TObject); 
    procedure NewPicFileClick(Sender: TObject); 
    procedure SaveManyPicClick(Sender: TObject); 
 //   procedure SavePicFileAsClick(Sender: TObject); 
//    function CountPictures(ADOQuery1:TADOQuery):integer; 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  Form1: TForm1; 
  PicName:string; 
  sign1:boolean; 
  NumPictures:integer; 
implementation 
uses unit2,unit3,unit4,unit5,unit6,unit7,unit8; 
{$R *.dfm} 
// 说明:Image1显示是为了能自动缩放图片,应该将其AutoSize属性设置为false 
//       同时将center属性设置为true 
procedure TForm1.FormCreate(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  sign1:=false;//取消载入图片时的特殊判断标志 
////////////////////////// 
 ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source='+GetcurrentDir()+ 
 '\pictures.dmf;Persist Security Info=False'; 
  ADOQuery1.Active:=true; 
  //设置主对话框标题 
  Form1.Caption:=Form1.Caption+'    默认文件[ '+GetCurrentDir()+'\pictures.dmf ]'; 
//判断数据库是否为空,若不空则执行初始载入图片的动作 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    JPEG:=TJPEGImage.Create;//JEPG对象做为中间变量 
    try//JPEG从数据库中读出图片后付给Image1 
      JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
      Image1.Picture.Assign(JPEG); 
      NumPictures:=ADOQuery1.RecordCount;//得到数据库中的记录条数 
    finally 
      JPEG.Free;// 释放JPGE对象 
    end; 
    SpeedButton1.Enabled:=false;//由于初始时指向第一条记录,所以根据 
    SpeedButton2.Enabled:=true; //情况设置按钮的可用情况 
  end 
  else 
  begin 
    SpeedButton1.Enabled:=false;//若数据库为空 
    SpeedButton2.Enabled:=false;//分别设置相关按钮为不可用 
    SpeedButton3.Enabled:=false; 
    SpeedButton4.Enabled:=false; 
    DeleteFormDB.Enabled:=false; 
    SaveToFile.Enabled:=false; 
    SetToDesktop.Enabled:=false; 
    rename.Enabled:=False; 
    ShowAll.Enabled:=False; 
    FiltByName.Enabled:=False; 
    CopyToCBoard.Enabled:=False; 
    CutToCBoard.Enabled:=False; 
    NumPictures:=0;//同时将指示数据库记录条数的变量置为0 
  end; 
  Label3.Caption:=IntTostr(NumPictures)+'   张';//显示数据库记录条数 
end; 
 
 
procedure TForm1.LoadFormFileClick(Sender: TObject); 
var 
  Pic:TPicture; 
  JPEG,JPEG2:TJPEGImage; 
begin 
  DataSource1.DataSet.Edit; 
    //说明:如果按下了打开文件对话框的-取消-键,if内的语句将不执行 
    if(OpenpictureDialog1.Execute) then 
    begin 
 
      Pic:=TPicture.Create;//利用TPicture的对象转换bitmap与JPEG 
      JPEG:=TJPEGImage.Create; 
      JPEG2:=TJPEGImage.Create; 
      try 
        Pic.LoadFromFile(OpenPictureDialog1.FileName); 
        if Pic.Bitmap.Empty=false then//如果文件是未图则转换成JPEG 
          JPEG.Assign(Pic.Bitmap) 
        else//如果不是位图则直接载入JPEG对象 
          JPEG.LoadFromFile(OpenPictureDialog1.FileName); 
 
        if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
          JPEG2.Assign(Image1.Picture);//将image1中的图片先保存在JPEG2中 
 
        Image1.Picture.Assign(JPEG);//将JPEG付值给Image1 
        Form2:=TForm2.Create(nil); //创建输入名字的对话框 
        //生成默认的图片名字 
        Form2.Edit1.Text:='图片'+IntToStr(NumPictures+1); 
        Form2.ShowModal; 
        //如果载入图片的行为在输入名字时被取消,则执行if内的语句 
        if not sign1 then //判断对话框是否被取消 
        begin 
         //若被取消就恢复载入前最近一张图片 
         //同时若原数据库原来为空,则将Image1指想空 
          if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
            Image1.Picture.Assign(JPEG2)//原数据库不为空的情况 
          else 
            Image1.Picture.Assign(nil);//原数据库为空的情况 
          exit;//在此调处函数 
        end; 
        //若始终没有取消操作,则继续执行 
        DataSource1.DataSet.Append; //添加一条记录 
        //将图片和名字存入数据库 
        DataSource1.DataSet.FieldByName('filename').Value:=PicName;//PicName为全局变量 
        DataSource1.DataSet.FieldByName('picture').Assign(JPEG); 
 
        NumPictures:=NumPictures+1;//指示数据库记录条数的变量加一 
        Label3.Caption:=IntTostr(NumPictures)+'   张'; 
        SpeedButton1.Enabled:=true;//根据情况将有关按钮置为可用 
        SpeedButton2.Enabled:=False; 
        SpeedButton3.Enabled:=true; 
        SpeedButton4.Enabled:=true; 
        DeleteFormDB.Enabled:=true; 
        SaveToFile.Enabled:=true; 
        Rename.Enabled:=true; 
        ShowAll.Enabled:=true; 
        FiltByName.Enabled:=true; 
        SetToDesktop.Enabled:=true; 
        CopyToCBoard.Enabled:=true; 
        CutToCBoard.Enabled:=true; 
      finally 
        Pic.Free; 
        JPEG.Free; 
        JPEG2.Free; 
        Form2.Free; 
        sign1:=false;//恢复初始值 
      end; 
      DataSource1.DataSet.Post; 
     // OpenPictureDialog1.CleanupInstance; 
     // OpenPictureDialog1.Filter:='JPEG Image File (*.jpg)|*.jpg|JPEG Image File (*.jpeg)|*.jpeg|Bitmaps (*.bmp)'+ 
     //                            '|*.bmp|All Support Files(*.jpg;*.jpeg;*.bmp)|*.jpg;*.jpeg;*.bmp' 
    end; 
 
 
end; 
 
//此函数中加入了自动添加文件后缀名的功能 
procedure TForm1.SaveToFileClick(Sender: TObject); 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    if(SavePictureDialog1.Execute) then 
    begin// 根据所选择的类型添加后缀 
      if SavePictureDialog1.Filter='JPEG Image File (*.jpg)|*.jpg' then 
       SavePictureDialog1.FileName:=SavePictureDialog1.FileName+'.jpg' 
      else if SavePictureDialog1.Filter='JPEG Image File (*.jpeg)|*.jpeg' then 
        SavePictureDialog1.FileName:=SavePictureDialog1.FileName+'.jpeg' 
      else 
 
      Image1.Picture.Graphic.SaveToFile(SavePictureDialog1.FileName); 
      SavePictureDialog1.CleanupInstance;//清空对话框 
      SavePictureDialog1.Filter:='All (*.jpg;*.jpeg)|*.jpg;*.jpeg|JPEG Image File (*.jpg)' 
                                  +'|*.jpg|JPEG Image File (*.jpeg)|*.jpeg'; 
    end; 
   end 
   else 
   begin 
    ShowMessage('当前没有可保存的图片'); 
    exit; 
   end; 
 
end; 
 
 
procedure TForm1.QuitClick(Sender: TObject); 
begin 
  close; 
end; 
 
procedure TForm1.SpeedButton1Click(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    SpeedButton2.Enabled:=true; //将‘下一张图片’按钮置为可用 
    ADOQuery1.Active:=true; 
    ADOQuery1.Prior; //数据库指针向前移动 
    JPEG:=TJPEGImage.Create;//创建JPEG对象,付值给Image1 
    try 
      JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
      Image1.Picture.Assign(JPEG); 
    finally 
      JPEG.Free; 
    end; 
    if ADOQuery1.Bof=true then//如果到了第一条记录,则置本按钮为不可用 
      SpeedButton1.Enabled:=false; 
   end; 
 
end; 
 
//本函数用法和上一函数相同,只是指针移动方向相反 
procedure TForm1.SpeedButton2Click(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    SpeedButton1.Enabled:=true; 
    ADOQuery1.Active:=true; 
    ADOQuery1.Next; 
    JPEG:=TJPEGImage.Create; 
    try 
      JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
      Image1.Picture.Assign(JPEG); 
    finally 
    JPEG.Free; 
    end; 
    if ADOQuery1.Eof=true then 
      SpeedButton2.Enabled:=false; 
   end;    
end; 
 
procedure TForm1.SpeedButton5Click(Sender: TObject); 
begin 
  close; 
end; 
 
 
procedure TForm1.DeleteFormDBClick(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    ADOQuery1.Active:=true; 
    JPEG:=TJPEGImage.Create;//创建JPEG对象,付值给Image1 
    try 
      if ADOQuery1.RecordCount=1 then //确保数据库中至少剩下一长图片 
      begin 
        ShowMessage('数据库中至少要保留一张图片,你不能删除此图!'); 
        exit; 
      end; 
      //删除图片的条件已经具备 
      if MessageDlg('你真的要从数据库中删除此图片吗?',mtConfirmation, 
                    mbOKCancel,0)=mrOK then 
      begin 
        ADOQuery1.Delete; 
        JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
        Image1.Picture.Assign(JPEG); 
 
        NumPictures:=NumPictures-1;//删除图片后,指示数据库记录条数的变量减一 
        Label3.Caption:=IntTostr(NumPictures)+'   张'; 
      end 
      else 
        exit; 
    finally 
    JPEG.Free; 
    end; 
  end 
  else 
    ShowMessage('当前没有可删除的图片'); 
end; 
 
//此函数实现重命名图片 
procedure TForm1.RenameClick(Sender: TObject); 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    Form3:=TForm3.Create(nil); 
    Form3.ShowModal; 
    Form3.Free; 
  end 
  else 
    ShowMessage('当前没有可命名的图片!'); 
 
end; 
 
procedure TForm1.Image1Click(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  Form4:=TForm4.Create(nil); 
  JPEG:=TJPEGImage.Create; 
  DataSource1.Edit; 
  try 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    Form4.Caption:=Form4.Caption+'    < '+Form1.DBText1.Caption+' >'; 
    JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
    Form4.Image1.Picture.Assign(JPEG); 
    //得到原始图片的大小 
    Form4.Hint:='图片大小:'+IntTostr(Form4.Image1.Width)+' X '+IntToStr(Form4.Image1.Height) 
                +'     单击关闭'; 
    Form4.ShowModal; 
   end 
   else 
   begin 
    ShowMessage('没有可查看的图片'); 
    exit; 
   end;  
  finally 
    Form4.Free; 
    JPEG.Free; 
  end; 
end; 
 
procedure TForm1.SetToDesktopClick(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
  bmp:TBitmap; 
  Reg:TRegistry;//创建注册表对象读取注册表 
  FileName:string; 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
///////////////////////////////////////////////////////////////////// 
//每次用本软件换桌面都会留下无用bmp图片, 
//为了节省磁盘空间,在换桌面前删除以前的图片 
    Reg:=TRegistry.Create; 
    Reg.RootKey:=HKEY_CURRENT_USER;//设置根键为HKEY_CURRENT_USER 
    try//如果已经存在主键,则读取最近一次用本软件设置为壁纸的图片文件名 
      if Reg.KeyExists('\software\DesktopManagement') then 
      begin 
        Reg.OpenKey('\software\DesktopManagement',false); 
        FileName:=Reg.ReadString('FileName'); 
        Reg.CloseKey; 
        //的到文件名后先删除指定路径下的该文件,在删除余下的空目录 
        DeleteFile('C:\WINDOWS\Web\Wallpaper\myWallPaper\'+FileName+'.bmp'); 
        RmDir('C:\WINDOWS\Web\Wallpaper\myWallPaper') 
      end; 
      //创建主键,并把当前设置为桌面的图片的文件名写入注册表 
      Reg.OpenKey('\software\DesktopManagement',true); 
      Reg.WriteString('FileName',DBText1.Caption); 
      Reg.CloseKey; //关闭主键 
    Finally 
        Reg.Free;//释放TRegistry对象 
    end; 
 
    //将当前图片转换为bmp格式存到C:\WINDOWS\Web\Wallpaper\myWallPaper目录下 
    //如果目录不存在则创建 
    if not DirectoryExists('C:\WINDOWS\Web\Wallpaper\myWallPaper') then 
      ForceDirectories('C:\WINDOWS\Web\Wallpaper\myWallPaper'); 
 
      JPEG:=TJPEGImage.Create; 
      bmp:=Tbitmap.Create; 
 
      //以下2句实现bmp向jpeg的转换 
      JPEG.Assign(Image1.Picture); 
      bmp.Assign(JPEG); 
 
      //将得到的位图存到指定路径 
      bmp.SaveToFile('C:\WINDOWS\Web\Wallpaper\myWallPaper\'+DBText1.Caption+'.bmp'); 
     //调用aip函数设置桌面 
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,pchar('C:\WINDOWS\Web\Wallpaper\myWallPaper\' 
                         +DBText1.Caption+'.bmp'),SPIF_UPDATEINIFILE{=1}); 
/////////////////////////////////////////////////// 
//最小化桌面所有程序,用api模拟了win+D的动作 
    keybd_event(91,mapvirtualkey(91,0),0,0); 
    keybd_event(77,mapvirtualkey(77,0),0,0); 
    keybd_event(77,mapvirtualkey(77,0),keyeventf_keyup	,0); 
    keybd_event(91,mapvirtualkey(91,0),keyeventf_keyup	,0); 
//过1000毫秒重新显示程序主窗口 
    Form1.Hide; 
    sleep(1000); 
    Form1.Show; 
///////////////////////////////////////////////////////////////// 
  end 
  else 
    ShowMessage('当前没有可作为桌面的图片!'); 
end; 
 
procedure TForm1.SpeedButton6Click(Sender: TObject); 
begin 
  Form5:=TForm5.Create(nil); 
  Form5.ShowModal; 
  Form5.Free; 
end; 
 
procedure TForm1.CopyToCBoardClick(Sender: TObject); 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
    //在包含Clipbrd单元后,该单元中已经申明好了ClipBoard 
    //ClipBoard可直接使用 
    ClipBoard.Assign(Image1.Picture) 
  else 
    ShowMessage('当前没有可复制的图片!'); 
end; 
 
procedure TForm1.CutToCBoardClick(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    ADOQuery1.Active:=true; 
    JPEG:=TJPEGImage.Create;//创建JPEG对象,付值给Image1 
    try 
      if ADOQuery1.RecordCount=1 then //确保数据库中至少剩下一长图片 
      begin 
        ShowMessage('数据库中至少要保留一张图片,你不能剪切此图!'); 
        exit; 
      end; 
      //删除图片的条件已经具备 
      if MessageDlg('剪切的图片将在数据库中删除,确实要删除此图片吗?',mtConfirmation, 
                    mbOKCancel,0)=mrOK then 
      begin 
        ClipBoard.Assign(Image1.Picture);//将Image1中的图片复制到剪贴板 
        ADOQuery1.Delete; 
        JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
        Image1.Picture.Assign(JPEG);//替换Image1中的图片 
         
        NumPictures:=NumPictures-1;//删除图片后,指示数据库记录条数的变量减一 
        Label3.Caption:=IntTostr(NumPictures)+'   张'; 
      end 
      else 
        exit; 
    finally 
    JPEG.Free; 
    end; 
  end 
  else 
    ShowMessage('当前没有可剪切的图片!'); 
end; 
 
procedure TForm1.PasteFromCBoardClick(Sender: TObject); 
var 
 // Pic:TPicture; 
  JPEG,JPEG2:TJPEGImage; 
begin 
  DataSource1.DataSet.Edit; 
 
  JPEG:=TJPEGImage.Create; 
  JPEG2:=TJPEGImage.Create; 
  try 
    if ClipBoard.HasFormat(CF_BITMAP) then 
    begin 
      //将image1中的图片先保存在JPEG2中,待取消粘贴时恢复 
      JPEG2.Assign(DataSource1.DataSet.FieldByName('picture')); 
      Image1.Picture.Assign(ClipBoard); 
      JPEG.Assign(Image1.Picture.Bitmap); 
    end 
    else 
    begin 
      ShowMessage('剪贴板中没有二进制图片拷贝!'); 
      exit; 
    end; 
///////////////////////////////////////////////////////////////// 
    Form2:=TForm2.Create(nil); //创建输入名字的对话框 
    //生成默认的图片名字 
    Form2.Edit1.Text:='图片'+IntToStr(NumPictures+1); 
    Form2.ShowModal; 
    Form2.Free; 
    //如果粘贴图片的行为在输入名字时被取消,则执行if内的语句 
    if not sign1 then //判断对话框是否被取消 
    begin 
      //若被取消就恢复载入前最近一张图片 
      //同时若原数据库原来为空,则将Image1指向空 
      if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
        Image1.Picture.Assign(JPEG2)//原数据库不为空的情况 
      else 
        Image1.Picture.Assign(nil);//原数据库为空的情况 
      exit;//在此调处函数 
    end; 
    //若始终没有取消操作,则继续执行 
    DataSource1.DataSet.Append; //添加一条记录 
    //将图片和名字存入数据库 
    DataSource1.DataSet.FieldByName('filename').Value:=PicName;//PicName为全局变量 
    DataSource1.DataSet.FieldByName('picture').Assign(JPEG); 
    Datasource1.DataSet.Post; 
 
    NumPictures:=NumPictures+1;//指示数据库记录条数的变量加一 
    Label3.Caption:=IntTostr(NumPictures)+'   张'; 
    SpeedButton1.Enabled:=true;//根据情况将有关按钮置为可用 
    SpeedButton2.Enabled:=False; 
    SpeedButton3.Enabled:=true; 
    SpeedButton4.Enabled:=true; 
    DeleteFormDB.Enabled:=true; 
    SaveToFile.Enabled:=true; 
    Rename.Enabled:=true; 
    ShowAll.Enabled:=true; 
    FiltByName.Enabled:=true; 
    SetToDesktop.Enabled:=true; 
    CopyToCBoard.Enabled:=true; 
    CutToCBoard.Enabled:=true; 
  finally 
    JPEG.Free; 
    JPEG2.Free; 
    sign1:=false;//恢复初始值 
  end; 
   
end; 
 
procedure TForm1.FiltByNameClick(Sender: TObject); 
begin 
  Form6:=TForm6.Create(nil); 
  Form6.ShowModal; 
  Form6.Free; 
end; 
 
procedure TForm1.ShowAllClick(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  ADOQuery1.Active:=True; 
  ADOQuery1.SQL.Clear; 
  ADOQuery1.SQL.Text:='select * from pictures'; 
  ADOQuery1.Open; 
/////////////////////////////// 
//刷新image1中的图片 
  JPEG:=TJPEGImage.Create; 
  try 
    if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
    begin 
      JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
      Image1.Picture.Assign(JPEG); 
    end 
    else 
      Image1.Picture.Assign(nil); 
  finally 
    JPEG.Free; 
  end; 
end; 
 
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField); 
var 
  JPEG:TJPEGImage; 
begin 
if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin//实现image1显示的图片与点击的图片同步 
    JPEG:=TJPEGImage.Create; 
    try 
      JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
      Image1.Picture.Assign(JPEG); 
    finally 
      JPEG.Free; 
    end; 
    if ADOQuery1.Bof=true then 
    begin //根据点击图片位置的不同置各键的可用属性 
      SpeedButton1.Enabled:=false; 
      SpeedButton2.Enabled:=true; 
    end 
    else if ADOQuery1.Eof=true then 
    begin 
      SpeedButton1.Enabled:=true; 
      SpeedButton2.Enabled:=false; 
    end 
    else 
    begin 
      SpeedButton1.Enabled:=true; 
      SpeedButton2.Enabled:=true; 
    end; 
  end 
  else 
  begin 
    SpeedButton1.Enabled:=false; 
    SpeedButton2.Enabled:=false; 
  end; 
end; 
 
//本函数将重定向程序所指向的数据库,语句大部分和OnCreate函数一样 
procedure TForm1.OpenPicDataFileClick(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
begin 
  if(OpenDialog1.Execute) then 
  begin 
   ADOConnection1.Close; 
   ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=' 
   +OpenDialog1.FileName+';Persist Security Info=False'; 
   ADOConnection1.Open(); 
  ADOQuery1.Active:=true; 
  Form1.Caption:='桌面背景图片管理器    [ '+OpenDialog1.FileName+' ]'; 
//判断数据库是否为空,若不空则执行初始载入图片的动作 
  if DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    JPEG:=TJPEGImage.Create;//JEPG对象做为中间变量 
    try//JPEG从数据库中读出图片后付给Image1 
      JPEG.Assign(DataSource1.DataSet.FieldByName('picture')); 
      Image1.Picture.Assign(JPEG); 
      NumPictures:=ADOQuery1.RecordCount;//得到数据库中的记录条数 
        SpeedButton1.Enabled:=true;//根据情况将有关按钮置为可用 
        SpeedButton2.Enabled:=False; 
        SpeedButton3.Enabled:=true; 
        SpeedButton4.Enabled:=true; 
        DeleteFormDB.Enabled:=true; 
        SaveToFile.Enabled:=true; 
        Rename.Enabled:=true; 
        ShowAll.Enabled:=true; 
        FiltByName.Enabled:=true; 
        SetToDesktop.Enabled:=true; 
        CopyToCBoard.Enabled:=true; 
        CutToCBoard.Enabled:=true;       
    finally 
      JPEG.Free;// 释放JPGE对象 
    end; 
    SpeedButton1.Enabled:=false;//由于初始时指向第一条记录,所以根据 
    SpeedButton2.Enabled:=true; //情况设置按钮的可用情况 
  end 
  else 
  begin 
    Image1.Picture.Assign(nil); 
    SpeedButton1.Enabled:=false;//若数据库为空 
    SpeedButton2.Enabled:=false;//分别设置相关按钮为不可用 
    SpeedButton3.Enabled:=false; 
    SpeedButton4.Enabled:=false; 
    DeleteFormDB.Enabled:=false; 
    SaveToFile.Enabled:=false; 
    SetToDesktop.Enabled:=false; 
    rename.Enabled:=False; 
    ShowAll.Enabled:=False; 
    FiltByName.Enabled:=False; 
    CopyToCBoard.Enabled:=False; 
    CutToCBoard.Enabled:=False; 
    NumPictures:=0;//同时将指示数据库记录条数的变量置为0 
  end; 
  Label3.Caption:=IntTostr(NumPictures)+'   张'; 
  //OpenDialog1.CleanupInstance; 
  //OpenDialog1.Filter:='Desktop Management 文件(*.dmf)|*.dmf|Access文件(*.mdb)|*.mdb'; 
 end; 
end; 
 
 
{//另寸数据库文件 
procedure TForm1.SavePicFileAsClick(Sender: TObject); 
var 
  FileName:string; 
  Path:string; 
begin 
  if SaveDialog1.Execute then 
  begin 
     ADOConnection1.Close; 
    try 
     CopyFile(pchar('pictures.mdb'),Pchar(ExtractFileName(SaveDialog1.FileName)),false); 
     fileName:=ExtractFileName(SaveDialog1.FileName); 
     ShowMessage(Filename); 
     Path:=SaveDialog1.FileName; 
     ShowMessage(Path); 
     MoveFile('dfg.dfm','C:\Documents and Settings\eric\桌面\dfg.dfm'); 
    finally 
      ADOConnection1.Open(); 
      ADOQuery1.Active:=True; 
      //SaveDialog1.CleanupInstance; 
     // SaveDialog1.Filter:='Desktop Management 文件(*.dmf)|*.dmf|Access文件(*.mdb)|*.mdb'; 
    end; 
  end; 
end; } 
 
 
procedure TForm1.NewPicFileClick(Sender: TObject); 
begin 
  Form7:=TForm7.Create(nil); 
  Form7.ShowModal; 
  Form7.Free; 
end; 
 
procedure TForm1.SaveManyPicClick(Sender: TObject); 
begin 
  SaveManyPicDlg:=TSaveManyPicDlg.Create(nil); 
  SaveManyPicDlg.Edit1.Enabled:=False; 
  saveManyPicDlg.Edit1.Color:=cl3DLight; 
  SaveManyPicDlg.ShowModal; 
  SaveManyPicDlg.Free; 
end; 
 
end.