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.7 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  2. /*--------------------------------------------------------
  3. filename: window.hpp"
  4. author: B.Rajeev
  5. purpose: Provides declarations for the Window class.
  6. --------------------------------------------------------*/
  7. #ifndef __WINDOW__
  8. #define __WINDOW__
  9. #include "forward.h"
  10. #include "common.h"
  11. #include "sync.h"
  12. // these are events shared by all winsnmp session derivatives
  13. #define NULL_EVENT_ID (WM_USER+1)
  14. #define MESSAGE_ARRIVAL_EVENT (WM_USER+2)
  15. #define SENT_FRAME_EVENT (WM_USER+3)
  16. #define SEND_ERROR_EVENT (WM_USER+4)
  17. #define OPERATION_COMPLETED_EVENT (WM_USER+5)
  18. #define DELETE_SESSION_EVENT (WM_USER+6)
  19. #define SNMP_WM_TIMER (WM_USER+7)
  20. #define DUMMY_TITLE "Dummy Window"
  21. typedef CMap< HWND, HWND &, Window *, Window *& > WindowMapping;
  22. // It creates a window and, when asked to, displays it if successful.
  23. // Lets users check for success and obtain a handle to the window
  24. class Window
  25. {
  26. BOOL is_valid;
  27. HWND window_handle;
  28. // serializes access to the WindowMapping
  29. static CriticalSection window_CriticalSection;
  30. // map to associate an HWND with an EventHandler.
  31. // this is shared by all EventHandlers
  32. static WindowMapping mapping;
  33. void Initialize (
  34. char *templateCode,
  35. WNDPROC EventHandler,
  36. BOOL display
  37. );
  38. static BOOL CreateCriticalSection () ;
  39. static void DestroyCriticalSection () ;
  40. public:
  41. Window (
  42. char *templateCode = DUMMY_TITLE,
  43. BOOL display = FALSE
  44. ) ;
  45. virtual ~Window(void);
  46. HWND GetWindowHandle(void) { return window_handle; }
  47. // it determines the corresponding EventHandler and calls it
  48. // with the appropriate parameters
  49. static LONG_PTR CALLBACK HandleGlobalEvent (
  50. HWND hWnd ,
  51. UINT message ,
  52. WPARAM wParam ,
  53. LPARAM lParam
  54. );
  55. static BOOL InitializeStaticComponents () ;
  56. static void DestroyStaticComponents () ;
  57. // calls the default handler
  58. // a deriving class may override this, but
  59. // must call this method explicitly for default
  60. // case handling
  61. virtual LONG_PTR HandleEvent (
  62. HWND hWnd ,
  63. UINT message ,
  64. WPARAM wParam ,
  65. LPARAM lParam
  66. );
  67. BOOL PostMessage (
  68. UINT user_msg_id,
  69. WPARAM wParam,
  70. LPARAM lParam
  71. );
  72. // lets users check if the window was successfully created
  73. virtual void * operator()(void) const
  74. {
  75. return ( (is_valid)?(void *)this:NULL );
  76. }
  77. static UINT g_SendErrorEvent ;
  78. static UINT g_OperationCompletedEvent ;
  79. static UINT g_TimerMessage ;
  80. static UINT g_DeleteSessionEvent ;
  81. static UINT g_MessageArrivalEvent ;
  82. static UINT g_SentFrameEvent ;
  83. static UINT g_NullEventId ;
  84. };
  85. #endif // __WINDOW__