| 心铃回音(2003-2) |
| 心铃 |
|
vc问答
读者lwwxw问:如何取得系统当前日期!并将其转化成数值型以便计算!
答:在VC中,我们可以借助CTime时间类,获取系统当前日期,具体使用方法如下:
CTime t = CTime::GetCurrentTime(); //获取系统日期
int d=t.GetDay(); //获得几号
int y=t.GetYear(); //获取年份
int m=t.GetMonth(); //获取当前月份
int h=t.GetHour(); //获取当前为几时
int mm=t.GetMinute(); //获取分钟
int s=t.GetSecond(); //获取秒
int w=t.GetDayOfWeek(); //获取星期几,注意1为星期天,7为星期六
如果想计算两段时间的差值,可以使用CTimeSpan类,具体使用方法如下:
CTime t1( 1999, 3, 19, 22, 15, 0 );
CTime t = CTime::GetCurrentTime();
CTimeSpan span=t-t1; //计算当前系统时间与时间t1的间隔
int iDay=span.GetDays(); //获取这段时间间隔共有多少天
int iHour=span.GetTotalHours(); //获取总共有多少小时
int iMin=span.GetTotalMinutes();//获取总共有多少分钟
int iSec=span.GetTotalSeconds();//获取总共有多少秒
读者mmc@0451.com问:我是软件报的忠实读者,我特别喜爱心玲回音这个栏目,我现在有一个列举系统进程的代码,我没有调试通过。系统提示如下:
[C++ Error] Unit1.cpp(18): E2451 Undefined symbol ’PROCESSENTRY32’
[C++ Error] Unit1.cpp(18): E2379 Statement missing ;
[C++ Error] Unit1.cpp(19): E2451 Undefined symbol ’processinfo’
[C++ Error] Unit1.cpp(19): E2109 Not an allowed type
[C++ Error] Unit1.cpp(20): E2268 Call to undefined function ’CreateToolhelp32Snapshot’
[C++ Error] Unit1.cpp(20): E2451 Undefined symbol ’TH32CS_SNAPPROCESS’
[C++ Error] Unit1.cpp(20): E2034 Cannot convert ’int’ to ’void *’
[C++ Error] Unit1.cpp(23): E2268 Call to undefined function ’Process32First’
[C++ Error] Unit1.cpp(38): E2268 Call to undefined function ’Process32Next’
[C++ Error] Unit1.cpp(46): E2451 Undefined symbol ’PROCESSENTRY32’
[C++ Error] Unit1.cpp(46): E2379 Statement missing ;
[C++ Error] Unit1.cpp(47): E2451 Undefined symbol ’processinfo’
[C++ Error] Unit1.cpp(47): E2109 Not an allowed type
[C++ Error] Unit1.cpp(48): E2451 Undefined symbol ’TH32CS_SNAPPROCESS’
[C++ Error] Unit1.cpp(48): E2268 Call to undefined function ’CreateToolhelp32Snapshot’
[C++ Error] Unit1.cpp(51): E2268 Call to undefined function ’Process32First’
[C++ Error] Unit1.cpp(66): E2268 Call to undefined function ’Process32Next’
我想程式中说PROCESSENTRY32 没有定义,是不是没有包含某一个头文件呢?不知是什么原因?
答:出现上述问题的原因是没有包含定义PROCESSENTRY32和声明函数Process32Next的头文件,该头文件名称为Tlhelp32.h,因此需要加入
#include即可解决上面的编译错误!
读者husiyou@sohu.com问:我用VC6.0编程遇到了问题,想请教您。 用CFileDialog 选择存盘文件时,若不输入文件扩展名,怎么从文件类型栏中获得文件扩展名。
答:从文件对话框中的文件类型栏中获取文件扩展名,需要借助CFileDialog类的成员变量m_ofn中的nFilterIndex属性(用户选择了文件类型下拉列表中的第几项),如下面的代码:
//文件类型栏中的扩展名字符串
char buf[]="可执行文件(*.exe) |*.exe|小型可执行文件(*.com)|*.com |\\
批处理文件(*.bat) |*.bat | All Files (*.*) |*.*||\0";
……
CFileDialog chfileDlg(FALSE,NULL,NULL, OFN_HIDEREADONLY|\
OFN_OVERWRITEPROMPT,buf);
if(chfileDlg.DoModal()!=IDOK) //弹出保存文件对话框
return;
int index=chfileDlg.m_ofn.nFilterIndex; //获取用户选择了当前文件类型栏中第几项
//从文件类型字符串中依次寻找字符串"|*.",找到对应文件类型名的起始位置
int iB=0;
for(int i=0;i< index;i++)
iB=strstr(buf+iB,"|*.")-buf+2;
//获取对应文件类型名的终止位置
int iE=strchr(buf+iB+1,’|’)-buf+1;
//由起始与终止位置获取类型名字符串
char extBuf[20];
strncpy(extBuf,buf+iB,iE-iB-1);
extBuf[iE-iB-1]=0;
if(strcmp(extBuf,".*")==0)
extBuf[0]=0;
//生成用户输入文件的全路径名,含扩展名
CString fname=chfileDlg.GetPathName ()+CString(extBuf);
……
需要注意的是:文件扩展名字符串中的字串"|*."不能包含空格!
vfp问答
读者jsx问:我是天津的蒋双喜,以前曾经与你通过信,现在我遇到一个紧急难题向你请教,请我去年前用VFP编写的程序(源文件及编译后的安装程序)在现在的win ME、win XP中只要系统里装过 Visual FoxPro(卸载过也是一样)我的程序运行时就报“资源文件版本不匹配”、“Visual FoxPro cannot Start.Could not load resource.”
在其他没装过Visual FoxPro机器中运行正常。但我单位绝大多数都装过,总不能中作系统吧!此问题紧急,请您百忙之中予以答复。另外请问:VB编写的程序能否反编译?用什么软件?
答:在新的环境下删除foxbase.dbf、foxbase.fpt,然后由系统重建。或者,直接在win ME、win XP操作系统环境下重新编译,再安装新的生成的安装程序即可!关于VBExe文件反编译的问题,可到http://secrecy.ayinfo.ha.cn/unlock/discomp.htm 看看是否有你需要的。
|
|
文章检索
编程>热门文章
|