Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.3 KiB

  1. #include "precomp.h"
  2. #include "ThreadEvent.h"
  3. const int WM_TEP_MESSAGE = WM_USER+101;
  4. // static members
  5. BOOL ThreadEventProxy::s_bWndClassRegistered = FALSE;
  6. const LPTSTR ThreadEventProxy::s_szWndClassName = "NAC_TEP_HIDDENWINDOW";
  7. ThreadEventProxy::ThreadEventProxy(IStreamEventNotify *pNotify, HINSTANCE hInst)
  8. {
  9. WNDCLASSEX wndClass;
  10. if (s_bWndClassRegistered == FALSE)
  11. {
  12. ZeroMemory(&wndClass, sizeof(wndClass));
  13. wndClass.cbSize = sizeof(wndClass);
  14. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  15. wndClass.lpfnWndProc = WndProc;
  16. wndClass.hInstance = hInst;
  17. wndClass.lpszClassName = s_szWndClassName;
  18. RegisterClassEx(&wndClass);
  19. s_bWndClassRegistered = TRUE;
  20. }
  21. m_hwnd = CreateWindow(s_szWndClassName, "Hidden Window",
  22. WS_OVERLAPPEDWINDOW, 0, 0, 0, 0,
  23. NULL,
  24. NULL,
  25. hInst,
  26. NULL);
  27. if (m_hwnd)
  28. SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LPARAM)this);
  29. m_pNotify = pNotify;
  30. return;
  31. }
  32. ThreadEventProxy::~ThreadEventProxy()
  33. {
  34. MSG msg;
  35. // just in case there is an outstanding message posted in the
  36. // queue for this window, clear the
  37. if (m_hwnd)
  38. {
  39. SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
  40. }
  41. while (PeekMessage(&msg, m_hwnd, 0, 0, PM_REMOVE))
  42. {
  43. ;
  44. }
  45. DestroyWindow(m_hwnd);
  46. m_hwnd = NULL;
  47. }
  48. // static
  49. LPARAM ThreadEventProxy::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  50. {
  51. ThreadEventProxy *pTEP;
  52. pTEP = (ThreadEventProxy*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  53. if (pTEP != NULL)
  54. {
  55. switch (uMsg)
  56. {
  57. case WM_TEP_MESSAGE:
  58. {
  59. // the message codes for the stream notifcation are
  60. // contained
  61. if (pTEP->m_pNotify)
  62. pTEP->m_pNotify->EventNotification(HIWORD(wParam), LOWORD(wParam), HIWORD(lParam), LOWORD(lParam));
  63. return 0;
  64. }
  65. }
  66. }
  67. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  68. }
  69. BOOL ThreadEventProxy::ThreadEvent(UINT uDirection, UINT uMediaType,
  70. UINT uEventCode, UINT uSubCode)
  71. {
  72. WPARAM wParam;
  73. LPARAM lParam;
  74. wParam = MAKELONG(uMediaType, uDirection);
  75. lParam = MAKELONG(uSubCode, uEventCode);
  76. if (m_hwnd)
  77. {
  78. PostMessage(m_hwnd, WM_TEP_MESSAGE, wParam, lParam);
  79. return TRUE;
  80. }
  81. return FALSE;
  82. }