1
0

foreignwnd.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "precomp.h"
  2. #include "foreignwnd.h"
  3. PtrListQuickSorted<ForeignWndProc, ForeignWndProcComparator> ForeignWnd::foreignwndprocs;
  4. LRESULT CALLBACK foreignWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  5. {
  6. ForeignWndProc *wp = ForeignWnd::foreignwndprocs.findItem((const wchar_t *)hwnd);
  7. if (wp)
  8. {
  9. if (uMsg == WM_SHOWWINDOW) // more ?
  10. wp->wnd->wndProc(hwnd, uMsg, wParam, lParam);
  11. return CallWindowProc(wp->oldWindowProc, hwnd, uMsg, wParam, lParam);
  12. }
  13. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  14. }
  15. ForeignWnd::ForeignWnd(OSWINDOWHANDLE wndhandle, OSMODULEHANDLE module, int subclass)
  16. {
  17. thishwnd = wndhandle;
  18. setOSModuleHandle(module);
  19. #ifdef EXPERIMENTAL_INDEPENDENT_AOT
  20. DebugString("ForeignWnd::ForeignWnd(OSWINDOWHANDLE wndhandle): There might be problems with GWL_USERDATA assumptions when EXPERIMENTAL_INDEPENDENT_AOT is on, lone should audit\n");
  21. #endif
  22. // access protected basewnd member
  23. hwnd = wndhandle;
  24. setForeignWnd(1);
  25. if (subclass)
  26. {
  27. oldWindowProc = (WNDPROC) GetWindowLongPtrW(wndhandle, GWLP_WNDPROC);
  28. wndprocentry = new ForeignWndProc;
  29. wndprocentry->wnd = this;
  30. wndprocentry->hwnd = thishwnd;
  31. wndprocentry->oldWindowProc = oldWindowProc;
  32. foreignwndprocs.addItem(wndprocentry);
  33. SetWindowLongPtrW(thishwnd, GWLP_WNDPROC, (LONG_PTR)foreignWindowProc);
  34. }
  35. else
  36. {
  37. oldWindowProc = NULL;
  38. wndprocentry = NULL;
  39. }
  40. }
  41. ForeignWnd::~ForeignWnd()
  42. {
  43. if (wndprocentry && oldWindowProc)
  44. {
  45. foreignwndprocs.removeItem(wndprocentry);
  46. delete wndprocentry;
  47. wndprocentry = NULL;
  48. SetWindowLongPtrW(thishwnd, GWLP_WNDPROC, (LONG_PTR)oldWindowProc);
  49. oldWindowProc = NULL;
  50. }
  51. }