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

📄 bcjq100.txt

📁 c++ builder 的一些txt文档
💻 TXT
字号:

C++ Builder开发者:程序员之家
var how_many_ads = 3;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
 
  
  
    
      
        
          
            首页   
              | 控件天堂 | 控件使用                        
              | 编程技巧                         
              |  源代码 |  编程工具 |             
               系统补丁 |  电子书籍 | 技术论坛                         
              |  相关链接                      
                                
                              
                            
                          
                          
                            
                              
                                
                                  
                                
                      
       if (ad==1) {document.write(''+'');}                    
       if (ad==2) {document.write(''+'');}                    
       if (ad==3) {document.write(''+'');}                    
                                   
                                
                             
                                         
                             
                           
                         
                       
                       
                         
                           
                             
                               
                            
                          
var marqueecontents=''+scroll_text+''                
if (document.all)                
document.write(''+marqueecontents+'')                
function regenerate(){                
window.location.reload()                
}                
function regenerate2(){                
if (document.layers){                
setTimeout("window.onresize=regenerate",450)                
intializemarquee()                
}                
}                
function intializemarquee(){                
document.cmarquee01.document.cmarquee02.document.write(marqueecontents)                
document.cmarquee01.document.cmarquee02.document.close()                
thelength=document.cmarquee01.document.cmarquee02.document.height                
scrollit()                
}                
function scrollit(){                
if (document.cmarquee01.document.cmarquee02.top>=thelength*(-1)){                
document.cmarquee01.document.cmarquee02.top-=speed                
setTimeout("scrollit()",100)                
}                
else{                
document.cmarquee01.document.cmarquee02.top=marqueeheight                
scrollit()                
}                
}                
window.onload=regenerate2                
                            
                              
                            
                          
                        
                      
                      
                        
                          
                            
                              
                                
                                  
                                    
                  当前位置
         
         
                    编程技巧                 
                                 
                               
                             
                             
                             
                               
                                 
                                   
                    如何在C++ 
                      Builder环境中实现在菜单中显示历史文件列表         
                           
                     
                       
                         
                           
                          本文介绍了如何在Windows环境下实现菜单中显示历史文件列表,同时概要介绍了TRegistry类的使用方法。
                            
                              现在,在许多Windows应用程序都具有这样一个功能:可以在文件菜单下面显示列出最近访问过的文件,这使用户很容易再次访问曾经访问过的文件。在过去几年中,这项技术以成为拥有文件菜单项的应用程序的共同特色:如Wps系列和Office系列。在以前的DOS环境中,程序员一般通过创建一个文件用来记录文件列表;那么在Windows环境中,还有其他的方法吗?最近笔者利用C++ 
                            Builder5.0 C/S版提供的TRegedit类成功在注册表中实现了上述功能,现介绍如下:
                            
                            1、在C++ Builder中新建一个工程文件project1,并在Form1上添加如下控件:
                            
                            控件名称         
                            属性         值
                            
                            TOpenDialog       Name         
                            OpenDialog1
                            
                            TMainMenu         Name         
                            MainMneu1
                            
                            同时在 MainMenu1控件中增加一个菜单项,其属性为
                            
                            Name             Caption
                            
                            Items1           打开文件
                            
                            2、在unit1.h中
                            
                            private:
                            
                            TRegistry *Registry;
                            
                            String Items[3];//建立显示历史文件的数组//
                            
                            int ItemsCount;
                            
                            void _fastcall TForm1::Display();//显示历史文件记录//
                            
                            
                            
                            3、在Items的Click事件中输入如下内容:
                            
                            void __fastcall TForm1::Items1Click(TObject *Sender)
                            
                            {
                            
                            
                            
                            String TempFile,Files;
                            
                            OpenDialog1->Filter="All 
                            Files(*.*)|*.*";
                            
                            if(OpenDialog1->Execute())
                            
                            {
                            
                            Files=OpenDialog1->FileName;//取得文件名//
                            
                              for(int i=0;i<3;i++)
                            
                               TempFile=Items[0];
                            
                               if(ItemsCount<3)
                            
                               ItemsCount++;
                            
                               for(int i=ItemsCount-1;i>0;i--)
                            
                               Items[i]=Items[i-1];//对打开的历史文件进排序//
                            
                               Items[0]=Files;//使最近打开的文件在最前面//
                            
                               }
                            
                              Display();
                            
                            }
                            
                            4、在unit.cpp中建立Display函数
                            
                            void _fastcall TForm1::Display()
                            
                            {
                            
                            TMenuItem *NewItem;
                            
                            while(MainMenu1->Items->Items[MainMenu1->Items->Count-1]->Count>2)
                            
                            {
                            
                            MainMenu1->Items->Items[MainMenu1->Items->Count-1]->
                            
                            Delete(MainMenu1->Items->Items[MainMenu1->Items->Count-1]->Count-1);
                            
                            }//除去原有的历史文件列表//
                            
                              for(int i=0;i<ItemsCount;i++)
                            
                              {
                            
                               NewItem=new TMenuItem(MainMenu1);
                            
                               NewItem->Caption=Items[i];
                            
                               
                            MainMenu1->Items->Items[MainMenu1->Items->Count-1]->Insert
                            
                            ( 
                            MainMenu1->Items->Items[MainMenu1->Items->Count-1]->Count,NewItem);
                            
                               }//建立新的历史文件列表//
                            
                            }
                            
                            5、在Form1的Show事件中输入如下内容:
                            
                            void __fastcall TForm1::FormShow(TObject *Sender)
                            
                            {
                            
                            Registry =new TRegistry;
                            
                            ItemsCount=0;
                            
                              Registry->RootKey=HKEY_LOCAL_MACHINE;
                            
                              Registry->OpenKey("SOFTWARE\\MYCOMPANY\\Remember",TRUE);
                            
                            //在注册表中打开主键,如果该主键不存在则新建该主键//
                            
                            Items[0]=Registry->ReadString("Item1");//读items[i]字符串的值//
                            
                            ItemsCount++;
                            
                            Items[1]=Registry->ReadString("Item2");
                            
                            ItemsCount++;
                            
                            Items[2]=Registry->ReadString("Item3");
                            
                            ItemsCount++;
                            
                            
                            
                            }
                            
                            6、在Form1的Show事件中输入如下内容:
                            
                            void __fastcall TForm1::FormClose(TObject *Sender, 
                            TCloseAction &Action)
                            
                            {
                            
                               if(ItemsCount<3)
                            
                               for(int i=ItemsCount+1;i<=3;i++)
                            
                               Items[i]="";
                            
                               Registry->WriteString("Item1",Items[0]);
                            
                               Registry->WriteString("Item2",Items[1]);
                            
                               Registry->WriteString("Item3",Items[2]);
                            
                               //向注册表写入items[i]字符串的值//
                            
                            
                            
                            }
                            
                              以上程序在PWin98、C++Builder5.0环境中通过。
                            
                              其实许多程序的其他功能,如:自动保存程序界面大小、自动记忆用户口令、也是利用
                            
                            TRegedit在注册表中实现的。有兴趣的读者可以试一试。
                            作者:孙航东 
                               
                             
                           
                               
                       
                             
                               
                             
                  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 + -