1
0

view_wait.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include "main.h"
  2. #include "./resource.h"
  3. #include "../nu/DialogSkinner.h"
  4. #include <windowsx.h>
  5. static HBRUSH hbBack = NULL;
  6. #define TIMER_SHOWTEXT_ID 1985
  7. #define TIMER_SHOWTEXT_DELAY 1000
  8. static INT_PTR WINAPI DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  9. // public function
  10. HWND CreateWaitWindow(HWND hwndParent, CHAR cLetter)
  11. {
  12. return WASABI_API_CREATEDIALOGPARAMW(IDD_VIEW_WAIT, hwndParent, DlgProc, (LPARAM)cLetter);
  13. }
  14. static void CALLBACK Window_TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  15. {
  16. switch(idEvent)
  17. {
  18. case TIMER_SHOWTEXT_ID:
  19. KillTimer(hwnd, TIMER_SHOWTEXT_ID);
  20. SetDlgItemTextW(hwnd, IDC_LBL_TEXT, WASABI_API_LNGSTRINGW(IDS_READINGDISC));
  21. break;
  22. }
  23. }
  24. static INT_PTR Window_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  25. {
  26. SendMessageW(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(IDC_BTN_SHOWINFO, BN_EX_GETTEXT), (LPARAM)GetDlgItem(hwnd, IDC_BTN_SHOWINFO));
  27. SetTimer(hwnd, TIMER_SHOWTEXT_ID, TIMER_SHOWTEXT_DELAY, Window_TimerProc);
  28. return 0;
  29. }
  30. static void Window_OnDestroy(HWND hwnd)
  31. {
  32. if (hbBack)
  33. {
  34. DeleteObject(hbBack);
  35. hbBack = NULL;
  36. }
  37. }
  38. static void Window_OnDisplayChange(HWND hwnd, INT dpi, INT resX, INT resY)
  39. {
  40. if (hbBack)
  41. {
  42. DeleteObject(hbBack);
  43. hbBack = NULL;
  44. }
  45. RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
  46. }
  47. static void Window_OnWindowPosChanged(HWND hwnd, WINDOWPOS *pwp)
  48. {
  49. HWND hwndCtrl;
  50. RECT rw;
  51. hwndCtrl = GetDlgItem(hwnd, IDC_BTN_SHOWINFO);
  52. if(hwndCtrl)
  53. {
  54. GetWindowRect(hwndCtrl, &rw);
  55. OffsetRect(&rw, -rw.left, -rw.top);
  56. SetWindowPos(hwndCtrl, NULL, pwp->cx - rw.right, pwp->cy - rw.bottom, 0, 0,
  57. SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOCOPYBITS);
  58. }
  59. hwndCtrl = GetDlgItem(hwnd, IDC_LBL_TEXT);
  60. if(hwndCtrl)
  61. {
  62. GetWindowRect(hwndCtrl, &rw);
  63. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rw, 2);
  64. SetWindowPos(hwndCtrl, NULL, 0, 0, pwp->cx - rw.left - 2, pwp->cy - 22 - rw.top,
  65. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOCOPYBITS);
  66. }
  67. if (0 == (SWP_NOREDRAW & pwp->flags))
  68. {
  69. InvalidateRect(hwnd, NULL, TRUE);
  70. RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
  71. }
  72. }
  73. static void Window_OnCommand(HWND hwnd, INT eventId, INT ctrlId, HWND hwndCtrl)
  74. {
  75. switch(ctrlId)
  76. {
  77. case IDC_BTN_SHOWINFO:
  78. switch(eventId)
  79. {
  80. case BN_CLICKED:
  81. SendMessageW(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(ctrlId, eventId),(LPARAM)hwndCtrl);
  82. break;
  83. }
  84. break;
  85. }
  86. }
  87. static HBRUSH Window_OnStaticColor(HWND hwnd, HDC hdc)
  88. {
  89. if (!hbBack) hbBack = CreateSolidBrush(dialogSkinner.Color(WADLG_ITEMBG));
  90. SetTextColor(hdc, dialogSkinner.Color(WADLG_ITEMFG));
  91. SetBkColor(hdc, dialogSkinner.Color(WADLG_ITEMBG));
  92. return hbBack;
  93. }
  94. static void Window_OnPaint(HWND hwnd)
  95. {
  96. int tab[] = { IDC_LBL_TEXT | DCW_SUNKENBORDER};
  97. dialogSkinner.Draw(hwnd, tab, 1);
  98. }
  99. static void Window_OnQueryInfo(HWND hwnd)
  100. {
  101. HWND hwndParent;
  102. hwndParent = GetParent(hwnd);
  103. if (hwndParent) SendMessageW(hwndParent, WM_SHOWFILEINFO, (WPARAM)WISF_NORMAL, (LPARAM)L"");
  104. }
  105. static INT_PTR WINAPI DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  106. {
  107. INT_PTR result;
  108. if (WM_CTLCOLORSTATIC == uMsg) return (INT_PTR)Window_OnStaticColor(hwnd, (HDC)wParam);
  109. result = dialogSkinner.Handle(hwnd, uMsg, wParam, lParam);
  110. if (result) return result;
  111. switch(uMsg)
  112. {
  113. case WM_INITDIALOG: return (INT_PTR)Window_OnInitDialog(hwnd, (HWND)wParam, lParam);
  114. case WM_DESTROY: Window_OnDestroy(hwnd); break;
  115. case WM_DISPLAYCHANGE: Window_OnDisplayChange(hwnd, (INT)wParam, LOWORD(lParam), HIWORD(lParam)); break;
  116. case WM_WINDOWPOSCHANGED: Window_OnWindowPosChanged(hwnd, (WINDOWPOS*)lParam); break;
  117. case WM_COMMAND: Window_OnCommand(hwnd, HIWORD(wParam), LOWORD(wParam), (HWND)lParam); break;
  118. case WM_PAINT: Window_OnPaint(hwnd); break;
  119. case WM_QUERYFILEINFO: Window_OnQueryInfo(hwnd); break;
  120. }
  121. return 0;
  122. }