log.cpp 1.3 KB

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