VS2003模板的下载与使用和注意事项

开发 后端
我们新的VS2003模板,是一个很通用的数据库管理程序,到目前为止所有的代码都是通过VS编写的,核心部分的设计基本完成,希望可以通过.NET开发一些小的模块,VC8.0(Visual C++2005)。

本文讲述VS2003模板的具体细节,怎样创建VS2003模板。这些内容都是我这些天花了一周的时间查阅资料并像IT精英学习出来的,中间可能有不少的错误,欢迎大家指正。下面就说明下。

VS2003模板升级的基本过程如下:

1、首先备份现有的VC程序,备份之后启动VS2005。

2、通过VS2005打开要升级的解决方案,系统提示自动转换,如果VC程序已经被嵌入到VSS中,则系统将提示登录VSS,并且自动将解决方案文件和项目文件签出。(注意选择备份原来版本 的解决方案的选项。)

3、一般情况下系统提示成功,可能会有两个警告,可以不予理会。因为升级过程中仅仅修改了解决方案文件和工程项目文件,所以速度会很快,C++头文件和CPP文件都不作任何修改(这和VB6到VB2005的升级不同),因此速度很快。

4、在VS2005中重新编译升级后的程序,很可能出现很多警告和错误提示,警告可以不予理会,错误提示必须修改。我所遇到的错误提示主要有两种:一种提示是“某个变量没有定义”,另外一种是模板类的消息映射的错误提示。

先说第一种错误提示,例如如下的两个for循环语句

  1. for(int i=0;i<10;i++)  
  2. {  
  3. }  
  4. for(i=0;i<100;i++)//此处将提示i没有定义  

上面的语句在VS2003中没有问题,在2005中则是错误的,2005将i作为第一个for循环中的局部变量处理,因此编译器认为第二个for循环中的i没有定义。这类错误可能有很多,但是修改起来比较容易。

VS2003模板第二种错误是模板类的消息映射宏错误。我在程序中设计了一个控件模板:

  1. template <class B,class P>class CUniDataCtrl : public B,public CUniDataBaseCtrl  #t#

则直接实现了原来几十行代码实现的功能。

上述的模板类消息映射宏我是参考BEGIN_TEMPLATE_MESSAGE_MAP(theClass, type_name, baseClass)编写的,该宏只支持一个模板参数,而我定义的模板中需要两个模板参数,因此,我自己扩充了一下VS2003模板的内容。关于BEGIN_TEMPLATE_MESSAGE_MAP的帮助在MSDN中好像没有,在afxwin.h中定义了:

  1. #define BEGIN_TEMPLATE_MESSAGE_MAP_EX(theClass, type_name1,type_name2,  baseClass)     
  2.  PTM_WARNING_DISABLE                
  3.  template < typename type_name1,typename type_name2 >             
  4.  const AFX_MSGMP* theClass< type_name1 ,type_name2 >::GetMessageMap() const     
  5.   { return GetThisMessageMap(); }            
  6.  template < typename type_name1 ,typename type_name2>             
  7.  const AFX_MSGMAP* PASCAL theClass< type_name1 ,type_name2  >::GetThisMessageMap()    
  8.  {                    
  9.   typedef theClass< type_name1 ,type_name2  > ThisClass;         
  10.   typedef baseClass TheBaseClass;            
  11.   static const AFX_MSGMAP_ENTRY _messageEntries[] =    
  12.   {  
  13.  
  14. BEGIN_TEMPLATE_MESSAGE_MAP_EX(CUniDataCtrl,B,P ,B)  
  15.  ON_WM_LBUTTONDOWN()  
  16.  ON_WM_RBUTTO  
  17.  
  18. #define DECLARE_MESSAGE_MAP()   
  19. protected:   
  20.  static const AFX_MSGMAP* PASCAL GetThisMessageMap();   
  21.  virtual const AFX_MSGMAP* GetMessageMap() const;   
  22.  
  23. #define BEGIN_TEMPLATE_MESSAGE_MAP(theClass, type_name, baseClass)     
  24.  PTM_WARNING_DISABLE                
  25.  template < typename type_name >             
  26.  const AFX_MSGMAP* theClass< type_name >::GetMessageMap() const     
  27.   { return GetThisMessageMap(); }            
  28.  template < typename type_name >             
  29.  const AFX_MSGMAP* PASCAL theClass< type_name >::GetThisMessageMap()    
  30.  {                    
  31.   typedef theClass< type_name > ThisClass;         
  32.   typedef baseClass TheBaseClass;            
  33.   static const AFX_MSGMAP_ENTRY _messageEntries[] =       
  34.   {  
  35. #define BEGIN_MESSAGE_MAP(theClass, baseClass)   
  36.  PTM_WARNING_DISABLE   
  37.  const AFX_MSGMAP* theClass::GetMessageMap() const   
  38.   { return GetThisMessageMap(); }   
  39.  const AFX_MSGMAP* PASCAL theClass::GetThisMessageMap()   
  40.  {   
  41.   typedef theClass ThisClass;           
  42.   typedef baseClass TheBaseClass;  
  43.   static const AFX_MSGMAP_ENTRY _messageEntries[] =    
  44.   {  
  45. #define END_MESSAGE_MAP()   
  46.   {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 }   
  47.  };   
  48.   static const AFX_MSGMAP messageMap =   
  49.   { &TheBaseClass::GetThisMessageMap, &_messageEntries[0] };   
  50.   return &messageMap;  
  51.  }     
  52.  PTM_WARNING_RESTORE  

 

责任编辑:chenqingxiang 来源: 许诺
相关推荐

2009-11-26 10:35:16

VS2003制作安装

2009-12-01 11:21:25

VS2003 报表

2009-12-10 09:50:49

VS.NET 2003

2009-11-27 09:53:15

VS2003安装程序

2009-11-25 13:35:05

VS2003使用

2009-11-30 11:14:57

VS2003 WebS

2009-11-26 09:42:38

VS2003插件

2009-11-30 09:27:38

VS2003源代码

2009-11-26 11:30:12

VS2003控件

2009-12-01 16:32:20

VS2003安装步骤

2009-11-27 14:25:57

VS2003模板

2009-11-30 11:05:19

VS2003 WebS

2009-11-30 17:28:39

VS2003 ASP

2009-11-27 10:14:44

2009-11-26 10:02:06

2009-11-30 10:34:28

VS2003编译

2009-11-30 09:16:44

VS2003源代码

2009-11-26 13:05:39

VS2003断点

2009-12-11 14:38:06

VS2003安装程序

2009-12-15 10:10:38

VS 2008开发
点赞
收藏

51CTO技术栈公众号