Clip.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:4k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Clipbrd.hpp"
- #include "Clip.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- if (Clipboard()->HasFormat(CF_TEXT))
- //如果剪贴板上的数据为文本格式
- {
- Form1->RichEdit1->Visible=true;
- Form1->BitBtn1->Visible=false;
- //设置控件可见状态
- RichEdit1->Text = Clipboard()->AsText;
- //显示剪贴板上的文本
- }
- else if (Clipboard()->HasFormat(CF_BITMAP))
- //如果剪贴板上的数据为图像格式
- {
- Form1->BitBtn1->Visible=true;
- Form1->RichEdit1->Visible=false;
- //设置控件可见状态
- Form1->BitBtn1->Glyph->Assign(Clipboard());
- //显示剪贴板上的图像
- }
- else
- {
- Form1->BitBtn1->Visible=false;
- Form1->RichEdit1->Visible=false;
- //设置控件可见状态
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- if (Form1->RichEdit1->Visible)
- //如果文本框控件可见
- Clipboard()->AsText=RichEdit1->Text;
- //把当前显示文本复制到剪贴板上
- if (Form1->BitBtn1->Visible)
- //如果BitBtn1控件可见
- Clipboard()->Assign(Form1->BitBtn1->Glyph);
- //把当前显示图像复制到剪贴板上
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- if (Form1->OpenDialog1->Execute())
- //显示一个对话框
- {
- Form1->RichEdit1->Visible=true;
- Form1->BitBtn1->Visible=false;
- //设置控件可见状态
- Form1->RichEdit1->Lines->LoadFromFile(Form1->OpenDialog1->FileName);
- //显示指定文本文件的内容
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- if (Form1->OpenPictureDialog1->Execute())
- //显示一个对话框
- {
- Form1->BitBtn1->Visible=true;
- Form1->RichEdit1->Visible=false;
- //设置控件可见状态
- Form1->BitBtn1->Glyph->LoadFromFile(Form1->OpenPictureDialog1->FileName);
- //显示指定图像文件的内容
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button5Click(TObject *Sender)
- {
- Clipboard()->Clear();
- //清除剪贴板上的数据
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Form1->Button1->Enabled=true;
- Form1->Button2->Enabled=true;
- Form1->Button3->Enabled=true;
- Form1->Button4->Enabled=true;
- Form1->Button5->Enabled=true;
- //设置按钮有效状态
- Form1->RichEdit1->Text="";
- //清空文本框中的内容
- Form1->OpenDialog1->Title="请选择一个文本文件:";
- //设置对话框标题
- Form1->OpenDialog1->Filter="文本文件(*.txt)|*.txt";
- //设置文件过滤条件
- Form1->OpenPictureDialog1->Title="请选择一个图象文件:";
- //设置对话框标题
- Form1->OpenPictureDialog1->Filter="文本文件(*.bmp)|*.bmp";
- //设置文件过滤条件
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button6Click(TObject *Sender)
- {
- Application->Terminate();
- }
- //---------------------------------------------------------------------------