TRACE用于debug模式下。
MSDN地址:https://msdn.microsoft.com/zh-cn/library/w6xa1ayx(v=vs.80).aspx
// Example for TRACE0 TRACE0( "Start Dump of MyClass members:" ); // Another example for TRACE0 // This works, but it is easier to use TRACE() or TRACE1() DWORD dwLastError = ::GetLastError(); CString str; str.Format("The last error code for this thread is %d\n", dwLastError); TRACE0( (LPCTSTR) str); // These are all normal uses of TRACE0() TRACE0("This message will be output. "); TRACE0("This text is on the same line.\n"); TRACE0("This text is on the next line.\n");TRACE1:
// Example for TRACE1 int i = 1; TRACE1( "Integer = %d\n", i ); // Output: 'Integer = 1' // Another example for TRACE1 DWORD dwLastError = ::GetLastError(); TRACE1("The last error code for this thread is %d\n", dwLastError);
// Example for TRACE2 int i = 1; char sz[] = "one"; TRACE2( "Integer = %d, String = %s\n", i, sz ); // Output: 'Integer = 1, String = one' // Another example for TRACE2 // Get major and minor version numbers of Windows DWORD dwVersion = GetVersion(); DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); TRACE2("This is Windows version %d.%2.2d.\n", dwWindowsMajorVersion, dwWindowsMinorVersion);
// Example for TRACE3 // get the display context HDC hdc = ::GetDC(NULL); // Get information about the display int nVertRes = ::GetDeviceCaps(hdc, VERTRES); int nHorzRes = ::GetDeviceCaps(hdc, HORZRES); int nDepth = ::GetDeviceCaps(hdc, BITSPIXEL); // Done with the DC, give it back ::ReleaseDC(hdc); // Tell the user TRACE3("Your screen is at %d by %d resolution, with %d bits per pixel\n", nHorzRes, nVertRes, nDepth);