log.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "Win32.h"
  2. #include "Function.h"
  3. #include "SharedValue.h"
  4. static bool statu = TRUE;
  5. static void Reflesh(HWND hwnd)
  6. {
  7. if (!statu) return;
  8. std::ifstream read;
  9. read.open("log.txt", std::ios::in);
  10. Err(&read, _T("打开日志文件失败"));
  11. std::string text(
  12. (std::istreambuf_iterator<char>(read)),
  13. std::istreambuf_iterator<char>()
  14. );
  15. read.close();
  16. int len = MultiByteToWideChar(CP_ACP, 0, text.c_str(), -1, NULL, 0);
  17. std::wstring wtext(len, 0);
  18. MultiByteToWideChar(CP_ACP, 0, text.c_str(), -1, &wtext[0], len);
  19. SetWindowText(hwnd, wtext.c_str());
  20. SendMessage(hwnd, WM_VSCROLL, SB_BOTTOM, 0);
  21. }
  22. static void GetLog()
  23. {
  24. static DWORD size = 0;
  25. char log[10240] = { 0 };
  26. PeekNamedPipe(UIr_log, NULL , NULL, NULL,&size,NULL);
  27. if(size < 1)
  28. {
  29. statu = FALSE;
  30. return;
  31. }
  32. statu = ReadFile(UIr_log, log, sizeof(log), NULL, NULL);
  33. std::ofstream write("log.txt", std::ios::app);
  34. Err(&write, _T("打开日志文件失败"));
  35. write << log;
  36. write.close();
  37. }
  38. void ClearLog()
  39. {
  40. std::ofstream clear;
  41. Err(&clear, _T("打开日志文件失败"));
  42. clear.open("log.txt", std::ios::out);
  43. clear.close();
  44. }
  45. void Log(HWND hwnd)
  46. {
  47. GetLog();
  48. Reflesh(hwnd);
  49. statu = TRUE;
  50. }