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

📄 bcjq035.txt

📁 c++ builder 的一些txt文档
💻 TXT
📖 第 1 页 / 共 2 页
字号:

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           
                       
                         
                       
                     
                   
                 
                 
                   
                     
                       
                         
                           
                             
                               
                  当前位置
    
    
                    编程技巧            
                            
                          
                        
                        
                        
                          
                            
                              
                    BCB控件制作和消息处理        
                          
                    
                      
                        
                          
                          1 前言
  
            作为和delphi类似的rad(rapid application development)工具,c++   
            builder的强大功能不仅体现在数据库开发方面,也凸现于应用程序开发上(令人称绝的是这两方面结合得非常好)。仅就应用程序而言,要真正体现c++   
            builder的优势,开发出高质量的软件,则在拖拉拽放之外,尚需用到一些进阶技术。如消息处理、dll、ole、线程、sdk编程。c++   
            builder在这些方面都或多或少有独到的优势。此外,可以方便地制作自定义控件,也是c++   
            builder的一大特色和高级功能。本文将通过制作一个标题棒在窗口左边的对话框控件,来示范一些c++   
            builder中关于控件制作和消息处理的概念,同时涉及到一点sdk编程。我们将要制作的是一个对话框,就如同opendialog等一样,一调用其execute()方法,就弹出一个如图一所示的窗口。这个窗口的标题棒位于左方,绿色,文字走向为由下而上的90度字形,其功能和一般的标题棒相同,可以將鼠标移至该处来移动该窗口。
  
            首先来完成这个窗口,然后用它来制作对话框控件。
  
            
  
            2 利用wm_nchittest消息制作竖直标题的窗口
  
            .wm_nchittest消息
  
            c++builder将某些windows消息封装于事件(event)中,但无法囊括所有消息,如wm_nc****   
            系列消息。wm_nchittest消息发生于游标(cursor)移动或鼠标按下、释放时,返回值指示目前游标所在位置,如返回hthscroll表示处于水平滚动条内,返回htcaption表示处于标题棒内(参见win32   
            sdk help)。其参数xpos、ypos分别表示游标的x、y坐标(相对于屏幕左上角),分别对应于lparam的低字和高字。如果拦截wm_nchittest消息,使得当鼠标在窗口左边按下时,人为地将返回值设为htcaption,则系统将以为是在标题棒内,于是将可以移动窗口,完成了标题棒的功能,至于颜色和文字,则与消息无关,将在下面叙述其原理。
  
            .windows消息
  
            消息就是windows操作系统送往程序的事件。但事件数以百计,操作系统并沒有为各个事件设计不同的消息结构,而是以一个一般性的结构来来描述消息,这个结构在c++   
            builder中定义为tmessage。另外c++ builder对常见消息定义了专用结构,二者对等。可以直接将消息转换为专用结构,也可以自行解释tmessage参数。以wm_nchittest消息为例,它的定义如下:
  
            struct twmnchittest
  
            {
  
            cardinal msg;
  
            long unused;
  
            union
  
            {
  
            struct
  
            {
  
            windows::tsmallpoint pos;
  
            long result;
  
            };
  
            struct
  
            {
  
            short xpos;
  
            short ypos;
  
            };
  
            };
  
            };
  
            对照tmessage定义:
  
            struct tmessage
  
            {
  
            cardinal msg;
  
            union
  
            {
  
            struct
  
            {
  
            word wparamlo;
  
            word wparamhi;
  
            word lparamlo;
  
            word lparamhi;
  
            word resultlo;
  
            word resulthi;
  
            };
  
            struct
  
            {
  
            long wparam;
  
            long lparam;
  
            long result;
  
            };
  
            };
  
            };
  
            可以发现,tmessage的lparam成员对应twmnchittest的pos成员,就是说以下两行语句
  
            等价:
  
            tpoint pt=tpoint(msg.lparam); //此时msg类型为tmessage
  
            tpoint pt=tpoint(msg.pos); //此时msg类型为twmnchittest
  
            .c++ builder处理消息的宏
  
            在c++ builder中自定义消息处理是较为方便的,结合wm_nchittest举例如下:
  
            在窗口类的protected部分加入如下宏定义:
  
            begin_message_map
  
            message_handler(wm_nchittest,tmessage,onnchittest)
  
            end_message_map(tform)
  
            message_handler包含3个参数:wm_nchittest,消息标识,也可以为自定义消息如wm_mymessage,这时只需加一个宏如#define   
            wm_mymessage wm_app+1等;第二个参数tmessage代表消息类型,也可以为符合要求的自定义消息结构类型如tmymsg等,onnchittest为消息处理函数。这样,一旦有wm_nchittest消息传给tform,对该消息的响应就完全交由onnchittest函数处理。onnchittest函数只有一个参数,类型为message_handler中第2个参数的引用,即tmessage   
            &或tmymsg &。
  
            .完成图一的窗口。
  
            开始一个新应用程序(new application),将form1命名为vcform,对应单元文件为vcap.cpp,头文件为vcap.h。vcform的boarderstyle设置为bsnone,其上放置一个位图按钮bitbtn1,caption为&ok,kind为bkok,onclick事件处理函数中加入一句close()。然后在vcap.h的protected部分加入如前所述消息处理宏和函数onnchittest的声明,以处理标题条的拖动功能。为完成标题的着色和文字输出,双击vcform的onpaint事件以定制formpaint函数,具体代码见下面源码。此外为使窗口有立体感,重载虚函数createparams,以修改窗口的风格。完整的vcap.h和vcap.cpp如下:
  
            //vcap.h
  
            #ifndef vcaph
  
            #define vcaph
  
            #include
  
            #include
  
            #include
  
            #include
  
            #include
  
            class tvcform : public tform
  
            {
  
            __published: // ide-managed components
  
            tbitbtn *bitbtn1;
  
            void __fastcall formpaint(tobject *sender);
  
            void __fastcall bitbtn1click(tobject *sender);
  
            private: // user declarations
  
            protected:
  
            void __fastcall onnchittest(tmessage & msg);
  
            void __fastcall createparams(tcreateparams& params);
  
            begin_message_map
  
            message_handler(wm_nchittest,tmessage,onnchittest)
  
            end_message_map(tform)
  
            public: // user declarations
  
            __fastcall tvcform(tcomponent* owner);
  
            };
  
            extern package tvcform *vcform;
  
            #endif
  
            //vcap.cpp
  
            #include
  
            #pragma hdrstop
  
            #include "vcap.h"
  
            #pragma package(smart_init)
  
            #pragma resource "*.dfm"
  
            tvcform *vcform;
  
            __fastcall tvcform::tvcform(tcomponent* owner)
  
            : tform(owner)
  
            {
  
            }
  
            void __fastcall tvcform::formpaint(tobject *sender)
  
            {
  
            //绘制宽20的绿色标题条
  
            rect rc;
  
            setrect(&rc,0,0,clientwidth,clientheight);
  
            canvas->pen->color=clgreen;
  
            canvas->brush->color=clgreen;
  
            canvas->rectangle(0,0,20,clientheight);
  
            //输出旋转文字
  
            char* msg=caption.c_str();
  
            logfont fontrec;
  
            memset(&fontrec,0,sizeof(logfont));
  
            fontrec.lfheight = -13;
  
            fontrec.lfweight = fw_normal;
  
            fontrec.lfescapement = 900; //旋转角度900x0.1度=90度
  
            lstrcpy(fontrec.lffacename,"宋体");

⌨️ 快捷键说明

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