有没有win32编程因为打印变量调试程序而头疼呢.方法二的函数完全类似printf.非常完美.
方法一:
不带参数输出如printf("hello world");
OutputDebugString("debug");
1 case WM_COMMAND: 2 wmId = LOWORD(wParam); 3 wmEvent = HIWORD(wParam); 4 // Parse the menu selections: 5 switch (wmId) 6 { 7 case IDS_BTN1: 8 OutputDebugString("1"); 9 break; 10 case IDS_CLEAR: 11 SetWindowText(GetDlgItem(hWnd,IDS_EDIT),(LPCTSTR)""); 12 break; 13 case IDM_ABOUT: 14 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); 15 break; 16 case IDM_EXIT: 17 DestroyWindow(hWnd); 18 break; 19 default: 20 return DefWindowProc(hWnd, message, wParam, lParam); 21 } 22 break;
使用工具debug view查看:
方法二:
带参数输出入如 printf("hello %s welcome this %d ", "world", "501");
1 #include <stdio.h> 2 #include <stdarg.h> 3 #include <stdlib.h> 4 #include <windows.h> 5 6 void __cdecl odprintf(const char *format, ...) 7 { 8 char buf[4096], *p = buf; 9 va_list args; 10 11 va_start(args, format); 12 p += _vsnprintf(p, sizeof buf - 1, format, args); 13 va_end(args); 14 15 while ( p > buf && isspace(p[-1]) ) 16 { 17 *--p = '