Loading.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //#ifdef _load
  2. #include "Hunt.h"
  3. #define winw 240
  4. #define winh 120
  5. HWND hwndLoad;
  6. bool _EndLoading;
  7. HANDLE hLoadThread;
  8. DWORD hLOADID;
  9. HDC hdcLoad, hdcCLoad;
  10. HBITMAP hbmpLoad;
  11. void *lpLoadVideoBuf;
  12. char txt[128];
  13. bool lock;
  14. void CreateLoadDIB()
  15. {
  16. hdcLoad=GetDC(hwndLoad);
  17. hdcCLoad = CreateCompatibleDC(hdcLoad);
  18. SetBkMode(hdcCLoad, TRANSPARENT);
  19. SetTextColor(hdcCLoad, 0x909090);
  20. BITMAPINFOHEADER bmih;
  21. bmih.biSize = sizeof( BITMAPINFOHEADER );
  22. bmih.biWidth = winw;
  23. bmih.biHeight = -winh;
  24. bmih.biPlanes = 1;
  25. bmih.biBitCount = 16;
  26. bmih.biCompression = BI_RGB;
  27. bmih.biSizeImage = 0;
  28. bmih.biXPelsPerMeter = 400;
  29. bmih.biYPelsPerMeter = 400;
  30. bmih.biClrUsed = 0;
  31. bmih.biClrImportant = 0;
  32. BITMAPINFO binfo;
  33. binfo.bmiHeader = bmih;
  34. hbmpLoad =
  35. CreateDIBSection(hdcLoad, &binfo, DIB_RGB_COLORS, &lpLoadVideoBuf, NULL, 0);
  36. DeleteDC(hdcLoad);
  37. }
  38. void UpdateLWindow()
  39. {
  40. lock = TRUE;
  41. HBITMAP hbmpOld = SelectObject(hdcCLoad, hbmpLoad);
  42. HFONT hfntOld = SelectObject(hdcCLoad, fnt_Small);
  43. FillMemory(lpLoadVideoBuf, winw*winh*2, 1);
  44. TextOut(hdcCLoad, 10, winh-16, txt, strlen(txt) );
  45. BitBlt(hdcLoad,0,0,winw,winh, hdcCLoad,0,0, SRCCOPY);
  46. MessageBeep(0xFFFFFFFF);
  47. SelectObject(hdcCLoad,hfntOld);
  48. SelectObject(hdcCLoad,hbmpOld);
  49. lock = FALSE;
  50. }
  51. LONG APIENTRY LoadWndProc( HWND hWnd, UINT message, UINT wParam, LONG lParam)
  52. {
  53. switch (message) {
  54. case WM_CREATE: return 0;
  55. //case WM_ERASEBKGND:
  56. //case WM_NCPAINT : break;
  57. case WM_PAINT: {
  58. PAINTSTRUCT ps;
  59. HDC hdc = BeginPaint(hWnd, &ps );
  60. EndPaint(hWnd, &ps);
  61. UpdateLWindow();
  62. break;
  63. }
  64. default:
  65. return (DefWindowProc(hWnd, message, wParam, lParam));
  66. }
  67. return 0;
  68. }
  69. DWORD WINAPI ProcessLoading (LPVOID ptr)
  70. {
  71. WNDCLASS wc;
  72. wc.style = CS_OWNDC;
  73. wc.lpfnWndProc = (WNDPROC)LoadWndProc;
  74. wc.cbClsExtra = 0;
  75. wc.cbWndExtra = 0;
  76. wc.hInstance = hInst;
  77. wc.hIcon = wc.hIcon = LoadIcon(hInst,"ACTION");
  78. wc.hCursor = NULL;
  79. wc.hbrBackground = GetStockObject( BLACK_BRUSH );
  80. wc.lpszMenuName = NULL;
  81. wc.lpszClassName = "HuntLoadingWindow";
  82. if (!RegisterClass(&wc)) return FALSE;
  83. hwndLoad = CreateWindow(
  84. "HuntLoadingWindow","Loading...",
  85. WS_VISIBLE | WS_POPUP,
  86. 400-winw/2, 300-winh/2, winw, winh, NULL, NULL, hInst, NULL );
  87. CreateLoadDIB();
  88. ShowWindow(hwndLoad, SW_SHOW);
  89. MSG msg;
  90. while (!_EndLoading) {
  91. if( PeekMessage( &msg, hwndLoad, NULL, NULL, PM_REMOVE ) ) {
  92. TranslateMessage( &msg );
  93. DispatchMessage( &msg );
  94. } else {
  95. Sleep(100);
  96. UpdateLWindow();
  97. }
  98. }
  99. DestroyWindow(hwndLoad);
  100. ExitThread(0);
  101. return 0;
  102. }
  103. void PrintLoad(char *t)
  104. {
  105. if (t) {
  106. strcpy(txt, t);
  107. }
  108. }
  109. void StartLoading()
  110. {
  111. hLoadThread = CreateThread(NULL, 0, ProcessLoading, NULL, 0, &hLOADID);
  112. SetThreadPriority(hLoadThread, THREAD_PRIORITY_HIGHEST);
  113. }
  114. void EndLoading()
  115. {
  116. _EndLoading = TRUE;
  117. //SetFocus(hwndMain);
  118. //SetActiveWindow(hwndMain);
  119. //ShowWindow(hwndMain, SW_SHOW);
  120. //BringWindowToTop(hwndMain);
  121. }
  122. //#endif