//*********************************** void WINAPI Get_Version_Str(FILE* fp) //*********************************** // Fill Str with Windows version. { OSVERSIONINFOEX V = {sizeof(OSVERSIONINFOEX)}; //EX for NT 5.0 and later if (!GetVersionEx((POSVERSIONINFO)&V)) { ZeroMemory(&V, sizeof(V)); V.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx((POSVERSIONINFO)&V); } if (V.dwPlatformId != VER_PLATFORM_WIN32_NT) V.dwBuildNumber = LOWORD(V.dwBuildNumber); //for 9x HIWORD(dwBuildNumber) = 0x04xx TCHAR dateBuf[32]; _tstrdate(dateBuf); TCHAR timeBuf[32]; _tstrtime(timeBuf); _ftprintf(fp, _T("==============================================================================") NL _T("Windows: %d.%d.%d, SP %d.%d, Product Type %d") NL //SP - service pack, Product Type - VER_NT_WORKSTATION,... NL _T("Time: %s %s")NL, V.dwMajorVersion, V.dwMinorVersion, V.dwBuildNumber, V.wServicePackMajor, V.wServicePackMinor, V.wProductType, dateBuf, timeBuf); } //Get_Version_Str
int AddNewLogMsg() { LV_ITEM lvi; TCHAR szText[64]; int nCount = ListView_GetItemCount(g_hLogMsgWnd); if (nCount >= 50) { ListView_DeleteItem(g_hLogMsgWnd, 0); nCount--; } lvi.mask = LVIF_TEXT; lvi.iItem = nCount; lvi.iSubItem = 0; _tstrdate(szText); lvi.pszText = szText; ListView_InsertItem(g_hLogMsgWnd, &lvi); _tstrtime(szText); ListView_SetItemText(g_hLogMsgWnd, nCount, 1, szText); return nCount; }
void duLEDTimer::OnTimer(UINT nEventId) { if (nEventId != m_nTimerID) return; if (!Plugin_IsVisible(this)) return; TCHAR szTime[MAX_NAME]; ZeroMemory(szTime, MAX_NAME *sizeof(TCHAR)); _tstrtime(szTime); SetText(szTime); Plugin_Redraw(this, TRUE); }
/////////////////////////////////////////////////////////////////////////////// // // 函数功能描述:标准日志打印 // 输入:日志级别、类型、源文件名、代码行,格式字串 // 输出:向窗口或文件写日志 // 返回值: // 其它说明: // /////////////////////////////////////////////////////////////////////////////// void CLogTrace::Trace(BYTE cLevel, BYTE cType, const TCHAR * pszSourceFile, DWORD dwLine, LPCTSTR lpszFormat, ...) { if (! IsLogFileEnable()) return; //指定类型级别以下的日志不打印; if ( m_nOutLogLevel < cType ) { return; } //合法性检测 if (!pszSourceFile || !lpszFormat) { OutputDebugString(_T("Error: pszSourceFile or lpszFormat is NULL\r\n")); return; } //读取参数 va_list args; va_start(args, lpszFormat); CLocalLock localLock(&m_lock); //锁 //打入字串 m_szBuffer[0][0] = 0; int nBuf = -1; if(cType == LOGT_COMPRESS) //对打印的日志进行压缩 { TCHAR *tmp = new TCHAR[200000]; memset(tmp,0,200000 * sizeof(TCHAR)); int nBuf = _vsntprintf(tmp,200000-1,lpszFormat,args); CString strSource,strZipData; strSource.Format(_T("%s"),tmp); if (strSource.GetLength() < 100) { strZipData = strSource; } else { ZipEecodeStdString(strSource,strZipData); } _tcsncpy(m_szBuffer[0],strZipData.GetBuffer(strZipData.GetLength()),MAX_LEN_OF_LOG_LINE-128); strZipData.ReleaseBuffer(); delete []tmp; } else { nBuf = _vsntprintf(m_szBuffer[0], MAX_LEN_OF_LOG_LINE - 128, lpszFormat, args); } va_end(args); if (nBuf < 0) //出错 { //有可能是字符串太长 m_szBuffer[0][MAX_LEN_OF_LOG_LINE - 128] = 0; } //取系统日期、时间 TCHAR szData[12], szTime[12]; _tstrdate(szData); _tstrtime(szTime); //类型字串及颜色 CString strType; DWORD dwColor = 0; //获取日志的类型文本及颜色 GetLogType(strType,dwColor,cType); //源文件名缩短处理 TCHAR * pszSourceShort = NULL; TCHAR szSourceShort[MAX_PATH]; WORD wSourceNameLen = lstrlen(pszSourceFile); if (wSourceNameLen > LEN_SHORT_SOURCEFILE_NAME) //太长 { wsprintf(szSourceShort, _T("...%s"), pszSourceFile + (wSourceNameLen - LEN_SHORT_SOURCEFILE_NAME)); pszSourceShort = szSourceShort; } else { pszSourceShort = (TCHAR *)pszSourceFile; } //形成结果字串 nBuf = _sntprintf(m_szBuffer[1], MAX_LEN_OF_LOG_LINE, _T("%s %s [%d]%s: %s at %d in %s\r\n"), szData, szTime, GetCurrentThreadId(), strType.GetBuffer(), m_szBuffer[0], dwLine, pszSourceShort); if (nBuf < 0) //出错 { //有可能是字符串太长 m_szBuffer[1][MAX_LEN_OF_LOG_LINE - 1] = 0; } strType.ReleaseBuffer(); //打印 TraceColor(cLevel, dwColor); }