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.

223 lines
5.0 KiB

  1. /*
  2. * basewin.cxx
  3. *
  4. * Copyright (c) 1998 Microsoft Corporation
  5. *
  6. * Purpose: Implements the Base Windows classes for Trigger
  7. *
  8. * Owner: pierrec
  9. */
  10. #include "headers.hxx"
  11. #include <prsht.h>
  12. #include <process.h>
  13. #ifdef _DEBUG
  14. CTraceTag tagAttachDetach(_T("Base"), _T("Attach/Detach"));
  15. CTraceTag tagFrameProc(_T("Base"), _T("FrProc"));
  16. CTraceTag tagHelp(_T("{Base}"), _T("Help"));
  17. CTraceTag tagServiceControl(_T("Base"), _T("ServiceControl"));
  18. CTraceTag tagProgress(_T("Base"), _T("Progress"));
  19. CTraceTag tagStartup(_T("BaseWin"), _T("Startup"));
  20. #endif
  21. // class CBaseFrame
  22. // Static variables
  23. HINSTANCE CBaseFrame::s_hinst = NULL;
  24. HINSTANCE CBaseFrame::s_hinstPrev = NULL;
  25. HINSTANCE CBaseFrame::s_hinstMailBase;
  26. CBaseFrame * CBaseFrame::s_pframe = NULL;
  27. //tstring strFrameClassName(_T("CTriggerFrame"));
  28. CBaseFrame::CBaseFrame()
  29. {
  30. m_nReturn = 0;
  31. m_fExit = FALSE;
  32. m_hicon = NULL;
  33. SetFrameComponentBits(0);
  34. }
  35. CBaseFrame::~CBaseFrame(void)
  36. {
  37. s_pframe = NULL;
  38. }
  39. /*
  40. * CBaseFrame::DeinitInstance()
  41. *
  42. * Purpose: Finishes the clean-up & dumps memory leaks.
  43. */
  44. void CBaseFrame::DeinitInstance()
  45. {
  46. }
  47. LONG CBaseFrame::IdMessageBox(tstring& szMessage, UINT fuStyle)
  48. {
  49. MMCErrorBox(szMessage.data());
  50. return 0;
  51. }
  52. // Needed to avoid the compiler warning on SEH & destructors.
  53. void FatalAppExit(SC sc)
  54. {
  55. MMCErrorBox(sc);
  56. FatalExit(sc.GetCode());
  57. }
  58. /*
  59. * CBaseFrame::OnDestroy()
  60. *
  61. * Purpose:
  62. * Exit processing that requires the frame window to still be up
  63. */
  64. void CBaseFrame::OnDestroy(void)
  65. {
  66. Detach();
  67. }
  68. DWORD CBaseFrame::DwActiveModeBits(void)
  69. {
  70. return 0;
  71. }
  72. /*
  73. * CBaseFrame::ScInitInstance
  74. *
  75. * Purpose: Standard Windows InitInstance stuff.
  76. *
  77. * Return value:
  78. * sc error encountered.
  79. */
  80. SC CBaseFrame::ScInitInstance( void )
  81. {
  82. SC sc;
  83. return sc;
  84. }
  85. // class CBaseWindow
  86. /*
  87. * Purpose: Place holder for the virtual destructor.
  88. */
  89. CBaseWindow::~CBaseWindow(void)
  90. {
  91. ;
  92. }
  93. void CBaseWindow::Attach(HWND hwnd)
  94. {
  95. ASSERT(hwnd);
  96. #ifdef _DEBUG
  97. Trace(tagAttachDetach,
  98. _T("Attaching hwnd = %#08lX to this = %#08lX"),
  99. hwnd, this);
  100. #endif
  101. ::SetWindowLong(hwnd, GWL_USERDATA, (LONG) this);
  102. SetHwnd(hwnd);
  103. }
  104. CBaseWindow * CBaseWindow::Pwin(HWND hwnd)
  105. {
  106. return (CBaseWindow *) ::GetWindowLong(hwnd, GWL_USERDATA);
  107. }
  108. void CBaseWindow::Detach(void)
  109. {
  110. #ifdef _DEBUG
  111. Trace(tagAttachDetach,
  112. _T("Detaching hwnd = %#08lX from this = %#08lX"),
  113. Hwnd(), this);
  114. #endif
  115. if (Hwnd())
  116. {
  117. ::SetWindowLong(Hwnd(), GWL_USERDATA, NULL);
  118. }
  119. SetHwnd(NULL);
  120. }
  121. void CBaseWindow::InvalidateWindow(PVOID pv)
  122. {
  123. ASSERT(pv);
  124. ASSERT(::IsWindow((HWND) pv));
  125. ::InvalidateRect((HWND) pv, NULL, FALSE);
  126. }
  127. /*******************************************************************************
  128. * procedure : ActiveWaitForObjects
  129. *
  130. * purpose : Use MsgWaitForMultipleObjects to wait for signal-state of these
  131. * objects to change -- but remain alive to process windows messages
  132. *
  133. ********************************************************************************/
  134. DWORD ActiveWaitForObjects (DWORD cObjects,
  135. LPHANDLE lphObjects,
  136. BOOL fWaitAll,
  137. DWORD dwTimeout,
  138. DWORD fdwWakeMask)
  139. {
  140. DWORD dwWaitResult;
  141. MSG msg;
  142. while (TRUE)
  143. {
  144. dwWaitResult = MsgWaitForMultipleObjects (cObjects, lphObjects, fWaitAll, dwTimeout, fdwWakeMask);
  145. if (dwWaitResult == (WAIT_OBJECT_0 + cObjects))
  146. {
  147. // Process the queued windows messages
  148. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  149. {
  150. TranslateMessage(&msg);
  151. DispatchMessage(&msg);
  152. }
  153. }
  154. else
  155. break;
  156. }
  157. return(dwWaitResult);
  158. }