文件预览程序源代码_第1页
文件预览程序源代码_第2页
文件预览程序源代码_第3页
文件预览程序源代码_第4页
文件预览程序源代码_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

■编程实现文献预览————————————————下列为程序代码—————————————TXTDLGTEMPLATEDIALOG0,0,316,76STYLE0x404L|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGSFONT8,"MSSansSerif"{LTEXT"",1119,0,0,204,76,SS_LEFT|WS_CHILD|NOTWS_VISIBLE|WS_GROUP}————————————————————————————————unittxtDialog;interfaceusesWindows,Messages,SysUtils,Classes,StdCtrls,ExtCtrls,Buttons,Dialogs,ShellAPI,Controls;typeTtxtDialog=class(TOpenDialog)private{Privatedeclarations}FtxtPanel:TPanel;FtxtLabel:TLabel;FPreviewButton:TSpeedButton;FtxtCtrl:TMemo;protected{Protecteddeclarations}procedurePreviewClick(Sender:TObject);virtual;procedureDoSelectionChange;override;procedureDoShow;override;propertytxtCtrl:TMemoreadFtxtCtrl;public{Publicdeclarations}constructorCreate(AOwner:TComponent);override;functionExecute:Boolean;override;published{Publisheddeclarations}end;implementation{$RtxtDialog.res}{TtxtDialog}constructorTtxtDialog.Create(AOwner:TComponent);begininheritedCreate(AOwner);//文献扩展名过滤器Filter:='文本文献(*.txt)|*.txt';//定义一种主Panel---FtxtPanel,其它全部的构件都建立在这个Panel上FtxtPanel:=TPanel.Create(Self);withFtxtPaneldobeginName:='txtPanel';Caption:='';SetBounds(204,5,169,200);BevelOuter:=bvNone;BorderWidth:=2;TabOrder:=1;FtxtLabel:=TLabel.Create(Self);withFtxtLabeldobeginName:='txtLabel';Caption:='文本文献预览';Font.Charset:=GB2312_CHARSET;Font.Name:='宋体';Font.Size:=9;SetBounds(6,6,157,23);Align:=alTop;AutoSize:=False;Parent:=FtxtPanel;end;//文献预览按钮FPreviewButton:=TSpeedButton.Create(Self);withFPreviewButtondobeginName:='PreviewButton';SetBounds(77,1,23,22);Enabled:=False;//从资源文献中读出TXTGLYPH图像,用于SpeedButton的图像Glyph.LoadFromResourceName(HInstance,'TXTGLYPH');Hint:='查看该文献';ParentShowHint:=False;ShowHint:=True;//OnClick事件,调用记事本打开该文本文献OnClick:=PreviewClick;Parent:=FtxtPanel;end;//添加一种Memo元件,用于显示文献内容FtxtCtrl:=TMemo.Create(Self);withFtxtCtrldobeginName:='Memo';SetBounds(6,29,157,145);Align:=alClient;//OnDblClick事件OnDblClick:=PreviewClick;TabOrder:=2;ReadOnly:=True;Text:='';ScrollBars:=ssBoth;Parent:=FtxtPanel;end;end;end;procedureTtxtDialog.DoSelectionChange;varValided:Boolean;f:TextFile;s:string;functionValidFile(constFileName:string):Boolean;beginResult:=GetFileAttributes(PChar(FileName))<>$FFFFFFFF;end;beginFtxtCtrl.Lines.Clear;Valided:=FileExists(FileName)andValidFile(FileName)and(UpperCase(ExtractFileExt(Filename))='.TXT');ifValidedthentry//打开文献,逐行读入Memo的Lines,完毕预览AssignFile(f,Filename);FileMode:=fmOpenRead;Reset(f);whilenotEOF(f)dobeginReadln(f,s);FtxtCtrl.Lines.Add(s);end;CloseFile(f);FPreviewButton.Enabled:=True;exceptValided:=False;end;ifnotValidedthenFPreviewButton.Enabled:=False;inheritedDoSelectionChange;end;procedureTtxtDialog.DoShow;varPreviewRect,StaticRect:TRect;begin//GetClientRect是WindowsAPI,求出了整个Client区的大小GetClientRect(Handle,PreviewRect);//GetStaticRect是TOpenDialog提供的办法,求出了原则区的大小StaticRect:=GetStaticRect;//将PreviewRect缩小在StaticRect的右边//应当使用PreviewRect.Left:=StaticRect.Right,此处保存了ExtDlgs.pas中语句PreviewRect.Left:=StaticRect.Left+(StaticRect.Right-StaticRect.Left);Inc(PreviewRect.Top,4);//添加预览内容FtxtPanel.BoundsRect:=PreviewRect;FPreviewButton.Left:=FtxtCtrl.BoundsRect.Right-FPreviewButton.Width-2;FtxtPanel.ParentWindow:=Handle;inheritedDoShow;end;functionTtxtDialog.Execute:Boolean;begin//传递自定义对话框TXTDLGTEMPLATEifNewStyleControlsandnot(ofOldStyleDialoginOptions)thenTemplate:='TXTDLGTEMPLATE'elseTemplate:=nil;Result:=inheritedExecute;end;procedureTtxtDialog.PreviewClick(Sender:TObject);begin//使用记事本打开该文本文献ifUpperCase(ExtractFileExt(Filename))='.TXT't

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论