log.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "Win32.h"
  2. #include "ID.h"
  3. #include "Function.h"
  4. static DWORD size = 0;
  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("Failed to open log.txt"));
  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. }
  22. static void GetLog()
  23. {
  24. char log[4096] = { 0 };
  25. statu = ReadFile(UIr_log, log, sizeof(log), &size, NULL);
  26. if (!statu || size < 4)
  27. {
  28. statu = FALSE;
  29. return;
  30. }
  31. std::ofstream write("log.txt", std::ios::app);
  32. Err(&write, _T("Failed to open log.txt"));
  33. write << log;
  34. write.close();
  35. }
  36. void ClearLog()
  37. {
  38. std::ofstream clear;
  39. Err(&clear, _T("Failed to open log.txt"));
  40. clear.open("log.txt", std::ios::out);
  41. clear.close();
  42. }
  43. void Log(HWND hwnd)
  44. {
  45. GetLog();
  46. Reflesh(hwnd);
  47. size = 0;
  48. }