1
0

updateServicePopup.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "main.h"
  2. #include "./updateService.h"
  3. #include "./api.h"
  4. #include "../omBrowser/obj_ombrowser.h"
  5. #include "../omBrowser/ifc_omservice.h"
  6. #include "../omBrowser/browserPopup.h"
  7. #include "../omBrowser/browserHost.h"
  8. #ifndef LONGX86
  9. #ifdef _WIN64
  10. #define LONGX86 LONG_PTR
  11. #else /*_WIN64*/
  12. #define LONGX86 LONG
  13. #endif /*_WIN64*/
  14. #endif // LONGX86
  15. #define SVCPOPUP_PROP L"Winamp_UpdateSvcWndProp"
  16. typedef struct __SVCPOPUP
  17. {
  18. UpdateService *service;
  19. WNDPROC originalProc;
  20. } SVCPOPUP;
  21. static LRESULT WINAPI ServicePopup_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  22. HRESULT ServiceSubclass_Attach(HWND hwnd, UpdateService *service)
  23. {
  24. SVCPOPUP *psp = (SVCPOPUP*)calloc(1, sizeof(SVCPOPUP));
  25. if (NULL == psp) return E_OUTOFMEMORY;
  26. psp->service = service;
  27. if (NULL != service) service->AddRef();
  28. psp->originalProc = (WNDPROC)(LONG_PTR)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)ServicePopup_WindowProc);
  29. if (NULL == psp->originalProc || FALSE == SetPropW(hwnd, SVCPOPUP_PROP, psp))
  30. {
  31. if (NULL != psp->originalProc)
  32. SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)psp->originalProc);
  33. if (NULL != psp->service)
  34. service->Release();
  35. free(psp);
  36. return E_FAIL;
  37. }
  38. return S_OK;
  39. }
  40. static void ServicePopup_Dettach(HWND hwnd, SVCPOPUP *psp)
  41. {
  42. RemovePropW(hwnd, SVCPOPUP_PROP);
  43. if (NULL == psp) return;
  44. if (NULL != psp->originalProc)
  45. SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)psp->originalProc);
  46. if (NULL != psp->service)
  47. {
  48. psp->service->Finish();
  49. psp->service->Release();
  50. }
  51. free(psp);
  52. }
  53. static void ServicePopup_OnBrowserNotify(HWND hwnd, UpdateService *service, NMHDR *pnmh)
  54. {
  55. switch(pnmh->code)
  56. {
  57. case NBHN_DOCUMENTREADY:
  58. if (0 == (WS_VISIBLE & GetWindowLongPtrW(hwnd, GWL_STYLE)))
  59. ShowWindowAsync(hwnd, SW_SHOWNORMAL);
  60. break;
  61. }
  62. }
  63. static LRESULT WINAPI ServicePopup_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  64. {
  65. SVCPOPUP *psp = (SVCPOPUP*)GetPropW(hwnd, SVCPOPUP_PROP);
  66. if (NULL == psp || NULL == psp->originalProc)
  67. return DefWindowProcW(hwnd, uMsg, wParam, lParam);
  68. switch(uMsg)
  69. {
  70. case WM_NCDESTROY:
  71. case WM_DESTROY:
  72. {
  73. WNDPROC proc = psp->originalProc;
  74. ServicePopup_Dettach(hwnd, psp);
  75. if (NULL != proc)
  76. CallWindowProcW(proc, hwnd, uMsg, wParam, lParam);
  77. }
  78. return 0;
  79. case WM_NOTIFY:
  80. switch(wParam)
  81. {
  82. case 0x1000 /*IDC_BROWSER*/:
  83. ServicePopup_OnBrowserNotify(hwnd, psp->service, (NMHDR*)lParam);
  84. break;
  85. }
  86. break;
  87. }
  88. return CallWindowProcW(psp->originalProc, hwnd, uMsg, wParam, lParam);
  89. }