Vs2012的MFC中编写SetTimer函数出错,求解。
如下图:
一下代码经过vc6实测OK写到对话框类头文件里static void CALLBACK EXPORT TimerProc(HWND hWnd, // handle of CWnd that called SetTimerUINT nMsg, // WM_TIMERUINT nIDEvent, // timer identificationDWORD dwTime // system time){CTime t;switch(nIDEvent){case 100:::SetWindowText(AfxGetMainWnd()->GetSafeHwnd(), (LPCTSTR)CString(((t=CTime::GetCurrentTime()),t.Format("%H:%M:%S"))));break;}}写到对话框OnInitDialog里SetTimer(100, 1000, CMfcdlg2014Dlg::TimerProc);KillTimer你自己写吧添加对框类析构函数或WM_CLOSE消息响应函数
时间日期选取器的两个变量有什么区别,怎么使用
CTime类1) 获取当前时间。
CTime time;time = CTime::GetCurrentTime();2) 获取时间元素。
int year = time.GetYear() ;int month = time.GetMonth();int day = time.GetDay();int hour = time.GetHour();int minute = time.GetMinute();int second = time.GetSecond();int DayOfWeek = time.GetDayOfWeek() ;3) 获取时间间隔。
CTimeSpan timespan(0,0,1,0); // days,hours,minutes,secondstimespan = CTime::GetCurrentTime() - time;4) 把时间转换为字符串。
CString sDate,sTime,sElapsed Time ;sDate = time.Format("%m/%d/%y"); //ex: 12/10/98sTime = time.Format("%H:%M:%S"); //ex: 9:12:02sElapsed Time = timespan.Format("%D:%H:%M:%S");// %D is total elapsed days要想知道更多的时间格式,参见M F C文档中的strftime。
使用COleDateTime类1) 获得一年中的某一天。
COleDate Time datetime;datetime = COleDateTime::GetCurrentTime();int DayOfYear = datetime.GetDayOfYear();2) 从文本串中读取时间。
COleDate Time datetime;datetime.ParseDateTime("12:12:23 27 January 93");说明。
CTime和COleDateTime具有几乎同样的功能。
然而COleDateTime允许用户获得一年中的某一天(创建Julian日期的一种好方法),以及分析一个时间文本串。
与CTime相比, COleDateTime的优点在于它支持DWORD变量。
COleDateTime使用的位数是双浮点的两倍,既然CTime只是简单地计算从1970年1月1日之后经过的秒数,所以到了2 0 3 7年它将达到4 2 9 4 9 6 7 2 9 5,从而不能再使用。
相反, COleDateTime是一个浮点数,它表示是从1 9 0 0年1 2月3 0号之后的天数(小时是天的小数部分),几千年之内不会溢出。
CTime是无符号long类型,它的范围是0-4 2 9 4 9 6 7 2 9 5;COleDateTime是double类型,它占64位。
关于VC文件写入的问题
//取当前时间为文件名, 以使随时保存, 下面一段放入按钮事件中CString sFileName;CTime t = CTime::GetCurrentTime();CString sTmp;sTmp.Format("%d-%d-%d %d-%d-%d",t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond());sFileName = sTmp+".txt";//保存文件CFile f;CFileFind ff;CString sFile =sFileName ;if(!ff.FindFile(sFile, 0)){f.Open(sFile.GetBuffer(1),CFile::modeCreate,NULL);f.Close();}f.Open(sFile.GetBuffer(1),CFile::modeReadWrite);CString sText;//文本框内容GetDlgItem(IDC_TEXT1)->GetWindowText(sText);//写入数据f.Write((void*)sText.GetBuffer(1), sText.GetLength());f.Close();ff.Close();
C++获取系统时间和控制
方法一:PathFileExists(FilePath); 返回true则存在,返回false则不存在,注意要加上以下代码:#include #pragma comment(lib,"Shlwapi.lib")方法二:CFile::GetStatus(WMSIniFilePath,filestatus),返回true则存在,返回false则不存在参数: rStatus:A reference to a user-supplied CFileStatus structure that will receive the status information. The CFileStatus structure has the following fields:CTime m_ctime The date and time the file was created.CTime m_mtime The date and time the file was last modified.CTime m_atime The date and time the file was last accessed for reading.LONG m_size The logical size of the file in bytes, as reported by the DIR command.BYTE m_attribute The attribute byte of the file.char m_szFullName[_MAX_PATH] The absolute filename in the Windows character set.lpszFileName:A string in the Windows character set that is the path to the desired file. The path can be relative or absolute, but cannot contain a network name.参考:http://msdn.microsoft.com/zh-cn/aa270504
急!!C++中如何同时运行两个函数??怎样通过代码来实现???? ...
#include #include using namespace std;DWORD WINAPI fun(LPVOID argv)//函数一{while(1){static int i=0;coutSleep(1000);}return 0;}int main()//函数二{HANDLE th=CreateThread( 0,0,fun,0,0,0);CloseHandle(th);while(1){coutSleep(2000);}return 0;}
如何用C++实现关机
// FileScan.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"#include #include #define OK 0#define ERR -1#define TEST_FILE_MAX_SIZE "4.67G"#define EXT_LEN 8#define TYPE_LEN 8#define DIR_MAX_LEN 260 //文件路径最多256个字符,加上D:\\ //ftell()返回int,最大2G 1 typedef enum COND_VALUE { COND_VALUE_MORE = 0 ,//大于 COND_VALUE_LESS = 1 ,//小于 COND_VALUE_EUAQL = 2 ,//等于 COND_VALUE_MAX = 0xf }COND_VALUE_E; typedef enum COND_TYPE { COND_TYPE_SIZE = 0 , COND_TYPE_CTIME = 1 , COND_TYPE_MTIME = 2, COND_TYPE_EXTNAME = 4, COND_TYPE_FILETYPE = 8, COND_TYPE_MAX = 0xf }COND_TYPE_E; typedef struct COND_INFO { char cCondType : 4; char cCondValue : 4; }COND_INFO_S; typedef struct FILE_COND { //按照bit位来划分,前面四个bit位表示条件类型,后面四个bit位表示条件值 char cSymbol;//用来标志大于或者小于,搜索时间,大小,类型,扩展名,属性 char szRes[ 3 ];//预留3个字节,四字节对齐 unsigned int uiSizeHigh;//文件大小 高位 unsigned int uiSizeLow;//低位 unsigned int uiCStartTime;//创建时间 unsigned int uiCEndTime; unsigned int uiMStartTime;//修改时间 unsigned int uiMEndTime; char szExtName[ EXT_LEN ];//扩展名 char szFileType[ TYPE_LEN ];//文件类型 unsigned int uiFileAttrib;//文件属性 unsigned int uiFolderSizeHight;//文件夹大小 unsigned int uiFolderSizeLow; }FILE_COND_S;//最大允许多少个条件搜索#define CONDITION_MAX 4 FILE_COND_S g_astCond[ CONDITION_MAX ] = { 0 }; int g_iCondCnt = 0; int DisposeFile(char szFilePath[] , WIN32_FIND_DATA stWinFile) { DWORDLONG dwHighBase = MAXDWORD; dwHighBase += 1; DWORDLONG FileSize = stWinFile.nFileSizeHigh* dwHighBase + stWinFile.nFileSizeLow; printf("%s\\%s--Size:%lu\n" , szFilePath , stWinFile.cFileName , FileSize); return OK; }//转换字符串文件大小(如 45.67G)到int类型的文件大小#define SECTION_CNT 2#define MAX_NUM_DEC 100#define UNIT_CNT 4#define KB_OFFSET 10 //1KB == 1BIT#define MB_OFFSET 20#define GB_OFFSET 30#define TB_OFFSET 40#define INT_OFFSET 32 int ConvertSizeStr2SizeLong(char szSizeStr[],unsigned int* puiSizeHigh,unsigned int* puiSizeLow) { int aNumSect[ SECTION_CNT ] = { 0 };//分别存整数位和小数位 //char sz = "..."; char acValidUint[UNIT_CNT] = { 'K' , 'M' , 'G' , 'T' };//数组 //char acValidUint[] = "KMGT";//字符串 char acOffset[ UNIT_CNT ] = { KB_OFFSET , MB_OFFSET , GB_OFFSET , TB_OFFSET }; char cOffset = 0; int iBaseNum; char* pcTmp; int index = 0; int i; int iMask; //入参判断 if (szSizeStr == NULL) { return ERR; } pcTmp = szSizeStr; while (*pcTmp!=0) { if (*pcTmp == '.') { index++; if ( index >= SECTION_CNT ) { return ERR; } } else if ( *pcTmp >= '0' && *pcTmp { //小数位取3位,剩余的舍去 if ( index == 1 && aNumSect[ index ] > MAX_NUM_DEC ) { pcTmp++; continue; } else if (index == 0 && aNumSect[index] > MAX_NUM_DEC) { //1234G 不合法,应该写成1.234T return ERR; } aNumSect[ index ] = aNumSect[ index ] * 10 + *pcTmp - '0'; } else { for ( i = 0; i { if ( toupper(*pcTmp) == acValidUint[ i ] ) { break; } } if (i == UNIT_CNT) { return ERR; } } pcTmp++; } if (cOffset == 0) { *puiSizeHigh = 0; *puiSizeLow = aNumSect[ 0 ]; } else { //先转为下一级单位 iBaseNum = ( aNumSect[ 0 ] cOffset -= KB_OFFSET; } iMask = ( 1 *puiSizeHigh = ( iBaseNum >> ( INT_OFFSET - cOffset ) ) & iMask; *puiSizeLow = iBaseNum return OK; }//比较文件大小 int CompareFileSize(WIN32_FIND_DATA stWinFile , FILE_COND_S stCond,char cCondValue) { switch ( cCondValue ) { case COND_VALUE_LESS: { if ( stWinFile.nFileSizeHigh > stCond.uiSizeHigh ) { return ERR; } else if ( stWinFile.nFileSizeHigh ==stCond.uiSizeHigh ) { if ( stWinFile.nFileSizeLow > stCond.uiSizeLow ) { return ERR; } } break; } case COND_VALUE_MORE: { if ( stWinFile.nFileSizeHigh { return ERR; } else if ( stWinFile.nFileSizeHigh == stCond.uiSizeHigh ) { if ( stWinFile.nFileSizeLow { return ERR; } } break; } case COND_VALUE_EUAQL: { if ( stWinFile.nFileSizeHigh != stCond.uiSizeHigh || stWinFile.nFileSizeLow != stCond.uiSizeLow ) { return ERR; } break; } default: break; } return OK; } int CompareFileTime(WIN32_FIND_DATA stWinFile , FILE_COND_S stCond , char cCondValue) { return OK; } int CheckCondition(char szFilePath[],WIN32_FIND_DATA stWinFile) { int i; int iCondType; int iCondValue; COND_INFO_S* pstCondInfo; for ( i = 0; i { pstCondInfo = (COND_INFO_S*)(&( g_astCond[ i ].cSymbol)); switch (pstCondInfo->cCondType) { case COND_TYPE...
VC如何查看自己程序生成时间和所占用的内存
展开全部 运行时间在我们实际的编程工作中,经常要测量程序的运行时间,比如衡量算法的运行时间等等。
在这里我收集了网上集中测量程序运行时间的方法。
SYSTEMTIME systemTime; GetSystemTime( &systemTime ); FILETIME fileTime; SystemTimeToFileTime( &systemTime, &fileTime ); //get current time static double getTime( ) { #ifdef _WIN32 LARGE_INTEGER s_freq; LARGE_INTEGER performanceCount = {0}; QueryPerformanceFrequency(&s_freq); QueryPerformanceCounter(&performanceCount); return 1000. * performanceCount.QuadPart / s_freq.QuadPart; #else struct timeval tmVal; gettimeofday(&tmVal, NULL); return tmVal.tv_sec * 1000. + tmVal.tv_usec / 1000.; #endif } 方法一 利用GetTickCount函数(ms)代码:CString str; longt1=GetTickCount();//程序段开始前取得系统运行时间(ms) 。
。
。
。
。
。
//to do sthlongt2=GetTickCount();//程序段结束后取得系统运行时间(ms) str.Format("time:%dms",t2-t1);//前后之差即程序运行时间 AfxMessageBox(str); 方法二利用C/C++计时函数(s)代码:#include"time.h"clock_t start, finish;start =clock(); finish = clock();printf("%f seconds\n",(double)(finish-start)/CLOCKS_PER_SEC); 方法三 利用CTime类 获取系统时间代码:CString str;//获取系统时间CTime tm;tm=CTime::GetCurrentTime();str=tm.Format("现在时间是%Y年%m月%d日 %X");AfxMessageBox(str);方法四 利用GetLocalTime类获取系统时间SYSTEMTIME st;CString strDate,strTime;GetLocalTime(&st);strDate.Format("M----",st.wYear,st.wMonth,st.wDay);strTime.Format("-:-:-",st.wHour,st.wMinute,st.wSecond);AfxMessageBox(strDate);AfxMessageBox(strTime);占用内存BOOL WINAPI GetProcessMemoryInfo( __in HANDLE Process, __out PPROCESS_MEMORY_COUNTERS ppsmemCounters, __in DWORD cb );
转载请注明出处51数据库 » ctime dword