1
0

view_info.cpp 3.5 KB

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