⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcjq014.txt

📁 c++ builder 的一些txt文档
💻 TXT
📖 第 1 页 / 共 2 页
字号:
            
    
             void __fastcall Button3Click(TObject *Sender);
    
            
    
             void __fastcall Button2Click(TObject *Sender);
    
            
    
             void __fastcall Button5Click(TObject *Sender);
    
            
    
            private:// User declarations
    
            
    
            public:// User declarations
    
            
    
             Variant     
            V,Vdocuments,Vdocument1,Vdocument2,Vactive;
    
            
    
            / * 定 义Variant 型 全 局// 变 量,分 别 指 代Application 对 象, V 的Documents    
      对 象,documents 的Document 对 象(Vdocument1,Vdocument2) 以 及  
      V 的ActiveDocument 对 象 */
    
      
int tag; // 用 于 记 录Button3 被 点 击     
            的 次 数
    
             __fastcall TForm1(TComponent * Owner);
    
             Variant __fastcall GetWordObject();
    
             // 获 得Word 97 自 动 化 对 象 函 数
    
             void __fastcall Add(int i);
    
             // 编 辑 当 前 活 动 文 档 指 定 的
    
             段 落 文 字 的 函 数
    
            };
    
            // - - - - - - - - - - - - -
    
            extern PACKAGE TForm1 *Form1;
    
            // - - - - - - - - - - - - -
    
            #endif
    
            Unit1.cpp 文 件 代 码 为:
    
            #include    
            
    
            #pragma hdrstop
    
            #include "Unit1.h"
    
            #include    
            
    
            // - - - - - - - - - - - - -
    
            #pragma package(smart_init)
    
            #pragma resource " *.dfm"
    
            TForm1 *Form1;
    
            // - - - - - - - - - - - - -
    
            __fastcall TForm1::TForm1(TComponent * Owner) : TForm(Owner)
    
            {
    
            tag=1;// 令tag 的 初 值 为1, 其 将 随Button3 的 点 击 次 数 而 递 增
    
            }
    
            // - - - - - - - - - - - - -
    
            Variant __fastcall TForm1::GetWordObject()
    
            {
    
            Variant Obj1;
    
            AnsiString AppName="Word.Application" ;
    
            HWND hPrevApp = ::FindWindow(NULL, "Microsoft Word");
    
            if(!hPrevApp)
    
            {
    
            Obj1=CreateOleObject(AppName) ;
    
            //Word 没 启 动 就 启 动 它 返 回 一 自 动 化 对 象
    
            }
    
            else
    
            Obj1=GetActiveOleObject(AppName);
    
            // 否 则 返 回 正 在 运 行 的 实 例 自 动 化 对     
    
            Obj1.OlePropertySet("Visible",true);
    
            return Obj1;
    
             }
   
            void __fastcall TForm1::Button1Click(TObject *Sender)
    
            {
    
            int j;
    
            V=GetWordObject();
    
             // 获 得Word 97 自 动 化 对 象Application
    
            Vdocuments=V.OleFunction("Documents");
    
            // 通 过Application 获 取Documents 对 象
    
            if (OpenDialog1 ->Execute())
    
            // 使 用Documents 对 象 的Open 方 法 打 开 文 件, 并 返 回Document 对 象
    
            Vdocument1=Vdocuments.OleFunction
    
             ("Open",OpenDialog1 ->FileName);
    
            j=Vdocument1.OleFunction("ComputeStatistics",2);
    
             // 计 算 打 开 文 档 的 页 数
    
            Label1 ->Caption=" 文 件"+Vdocument1.OlePropertyGet("Name")+" 页 数 是:"+IntToStr(j);
    
            }
    
            
    
            // - - - - - - - - - - - - -
    
            
    
            void __fastcall TForm1::Button3Click(TObject *Sender)
    
            {
    
            int i,j;
    
            i=tag;
    
            Vactive=V.OleFunction("ActiveDocument");
    
            // 获 取Application 的ActiveDocument 对 象
    
            j=Vactive.OleFunction("ComputeStatistics",4);
    
            // 计 算 当 前 文 档 的 段 落 数
    
            // 的 的Paragraphs 集 合 对 象 增 加 一 段
    
            Vactive.OleFunction("Paragraphs").OleFunction("Add");
    
            i=j +i;// 当 前 文 档 被 编 辑 的 段 落 序 号
    
            Add(i);// 调 用 编 辑 当 前 活 动 文 档
    
             指 定 的 段 落 文     
            字 的 函 数
    
            Memo1 ->Clear();// 清 除Memo1 的 内 容
    
            tag=tag +1;
    
            }
    
            // - - - - - - - - - - - - - -
    
            void __fastcall TForm1::Button2Click(TObject *Sender)
    
            {
    
            V=GetWordObject();
    
            Vdocuments=V.OleFunction("");
    
            Vdocument2=Vdocuments.OleFunction("Add");
    
            // 使 用Documents 对 象 的Add 方 法 新 建 文 档
    
            Vdocument2.OlePropertySet("Password","12345");
    
             // 设 置 新 建 文 档 的 口 令
    
            }
    
            // - - - - - - - - - - - - - -
    
            void __fastcall TForm1::Add(int i)
    
            {
    
            Variant V1;
    
            // 设 置 被 编 辑 段 的 内 容、 字 体 大 小、
    
             颜 色 及 是 否 斜 体
    
            V1=((Vactive.OleFunction("Paragraphs")).
    
             OleFunction("Item",i)).OleFunction("Range");
  
            (V1.OleFunction("Font")).OlePropertySet("Italic",true);
  
            (V1.OleFunction("Font")).OlePropertySet("Size",18);
  
            (V1.OleFunction("Font")).OlePropertySet("ColorIndex",6);
  
            (V1.OleFunction("Font")).OlePropertySet("Size",18);
  
            V1.OlePropertySet("Text",Memo1 ->Text);
    
            }
    
            // - - - - - - - - - - - - -
    
            void __fastcall TForm1::Button5Click(TObject *Sender)
    
            {
    
            Variant Vshape,Vactive1,Vline;
    
            Vactive1=V.OleFunction("ActiveDocument");
    
            Vshape=Vactive1.OleFunction("Shapes");
    
            // 获 取 当 前 活 动 文 档 的Shapes 对 象
    
            // 使 用Shapes 对 象 的AddLine 方 法 化 直 线
    
            Vline=Vshape.OleFunction("AddLine",90,80,400,80);    
            
    
            if (OpenDialog1 ->Execute())// 使 用Shapes 对 象 的AddPicture   
    方 法 插 入 指 定 位 图
    
             Vshape.OleFunction("AddPicture",OpenDialog1 ->FileName,50,50,80,100);
   
            }
   
             此 程 序 在C + + Builder 3 中 编 译通     
            过, 运 行 该 应 用 程 序 首 先 必 须 获 得 文     
            档,然 后 才 可 以 编辑 文 档。   
                           
                         
                             
                     
                           
                             
                           
                  if (ad==1) {document.write(''+'');}           
                  if (ad==2) {document.write(''+'');}           
                  if (ad==3) {document.write(''+'');}           
                                             
                           
                         
                       
                     
                
                 
                   
                     
                   
                   
                       
                   
                 
                    
                  
                
              
            
            
              
                
                  
                    
            C++ Builder开发者®         
              2000年06月01日 站长:唐朝         
                   
                 
               
             
             
               
             
           
           
         
         
         
         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -