skinnedmenu.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "main.h"
  2. #include "./skinnedmenu.h"
  3. #include "./skinnedmenuwnd.h"
  4. SkinnedMenu::SkinnedMenu()
  5. {
  6. hwndOwner = NULL;
  7. skinStyle = SMS_NORMAL;
  8. hmlil = NULL;
  9. width = 0;
  10. if (FAILED(SkinnedMenuThreadInfo::GetInstance(TRUE, &threadInfo)))
  11. threadInfo = NULL;
  12. }
  13. SkinnedMenu::~SkinnedMenu(void)
  14. {
  15. if (NULL != threadInfo)
  16. {
  17. threadInfo->RemoveAttachHook(this);
  18. threadInfo->Release();
  19. }
  20. }
  21. HWND SkinnedMenu::WindowFromHandle(HMENU menu)
  22. {
  23. HWND hwnd;
  24. SkinnedMenuThreadInfo *threadInfo;
  25. if (S_OK != SkinnedMenuThreadInfo::GetInstance(FALSE, &threadInfo))
  26. return NULL;
  27. hwnd = threadInfo->FindMenuWindow(menu);
  28. threadInfo->Release();
  29. return hwnd;
  30. }
  31. BOOL SkinnedMenu::InitializeHook(HWND hwndOwner, UINT skinStyle, HMLIMGLST hmlil, INT width, MENUCUSTOMIZEPROC _customProc, ULONG_PTR customParam)
  32. {
  33. if (NULL == threadInfo)
  34. return FALSE;
  35. if (FALSE != threadInfo->IsAttachHookActive())
  36. return FALSE;
  37. this->hwndOwner = hwndOwner;
  38. this->hmlil = hmlil;
  39. this->width = width;
  40. this->skinStyle = skinStyle;
  41. this->customProc = _customProc;
  42. this->customParam = customParam;
  43. return threadInfo->SetAttachHook(this);
  44. }
  45. BOOL SkinnedMenu::TrackMenuPopupEx(HMENU hmenu, UINT fuFlags, INT x, INT y, HWND hwnd, LPTPMPARAMS lptpm, UINT skinStyle,
  46. HMLIMGLST hmlil, INT width, MENUCUSTOMIZEPROC customProc, ULONG_PTR customParam)
  47. {
  48. if (NULL == hwnd ||
  49. !InitializeHook(hwnd, skinStyle, hmlil, width, customProc, customParam))
  50. {
  51. return FALSE;
  52. }
  53. return TrackPopupMenuEx(hmenu, fuFlags, x, y, hwnd, lptpm);
  54. }
  55. BOOL SkinnedMenu::AttachToHwnd(HWND hwndMenu)
  56. {
  57. SkinnedMenuWnd *psw = new SkinnedMenuWnd(skinStyle, hmlil, width, customProc, customParam);
  58. if (!psw || !psw->Attach(hwndMenu, hwndOwner))
  59. {
  60. delete(psw);
  61. return FALSE;
  62. }
  63. return TRUE;
  64. }