vc6.0 如何添加全局变量

来源:互联网 发布:网络手游排行榜2015 编辑:程序博客网 时间:2024/05/21 15:08

方法:

在现有工程中添加 GlobalVariables.h 头文件。

添加方法之一:

File->New->C/C++Header File->(Add to project要选对)->(File填GlobalVariables(不要加.h))->OK

内容如下:

//Begin the GlobalVariables.h

#if !defined(GLOBAL_H_H)
#define GLOBAL_H_H

extern BOOL g_bOnOff;

extern COleDateTime g_DnTime;


#endif


//宏名可以自定义,但一般按照规则定义。如GLOBAL_H_H
//#if !defined(GLOBAL__INCLUDED_)
//#define GLOBAL__INCLUDED_
//这样也行。
// #if !defined(ZXCVBNM)
// #define ZXCVBNM
//这样也行。
// #if !defined(zxcvbnm)
// #define zxcvbnm
//这样也行。
//End the GlobalVariables.h


然后再添加 GlobalVariables.cpp 源文件,对应的内容如下:
//Begin the GlobalVariables.cpp

#include "stdafx.h"

BOOL g_bOnOff=0;//初始化。

COleDateTime g_DnTime;//注意,不初始化也要写。


//End the GlobalVariables.cpp

到此为止,只需要在工程内的某文件里添加 #include "GlobalVariables.h",则在相应的文件中就可以使用g_bOnOff变量和g_DnTime变量。
0 0