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.

183 lines
5.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. dialog.cpp
  7. base dialog class to handle help
  8. FILE HISTORY:
  9. 7/10/97 Eric Davison Created
  10. */
  11. #include "stdafx.h"
  12. #include "dialog.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /*---------------------------------------------------------------------------
  19. Global help map
  20. ---------------------------------------------------------------------------*/
  21. PFN_FINDHELPMAP g_pfnHelpMap = NULL;
  22. /*!--------------------------------------------------------------------------
  23. SetGlobalHelpMapFunction
  24. -
  25. Author: KennT
  26. ---------------------------------------------------------------------------*/
  27. void SetGlobalHelpMapFunction(PFN_FINDHELPMAP pfnHelpFunction)
  28. {
  29. g_pfnHelpMap = pfnHelpFunction;
  30. }
  31. IMPLEMENT_DYNAMIC(CBaseDialog, CDialog)
  32. CBaseDialog::CBaseDialog()
  33. {
  34. }
  35. CBaseDialog::CBaseDialog(UINT nIDTemplate, CWnd *pParent)
  36. : CDialog(nIDTemplate, pParent)
  37. {
  38. }
  39. BEGIN_MESSAGE_MAP(CBaseDialog, CDialog)
  40. //{{AFX_MSG_MAP(CBaseDialogDlg)
  41. // NOTE: the ClassWizard will add message map macros here
  42. //}}AFX_MSG_MAP
  43. ON_WM_HELPINFO()
  44. ON_WM_CONTEXTMENU()
  45. END_MESSAGE_MAP()
  46. HWND FixupIpAddressHelp(HWND hwndItem)
  47. {
  48. HWND hwndParent;
  49. TCHAR szClassName[32]; // should be enough to hold "RtrIpAddress"
  50. // If any of these calls fail, bail and pass the call down
  51. hwndParent = ::GetParent(hwndItem);
  52. if (hwndParent)
  53. {
  54. if (::GetClassName(hwndParent, szClassName, DimensionOf(szClassName)))
  55. {
  56. // Ensure that the string is NULL terminated
  57. szClassName[DimensionOf(szClassName)-1] = 0;
  58. if (lstrcmpi(szClassName, TEXT("IPAddress")) == 0)
  59. {
  60. // Ok, this control is part of the IP address
  61. // control, return the handle of the parent
  62. hwndItem = hwndParent;
  63. }
  64. }
  65. }
  66. return hwndItem;
  67. }
  68. /*!--------------------------------------------------------------------------
  69. CBaseDialog::OnHelpInfo
  70. Brings up the context-sensitive help for the controls.
  71. Author: EricDav
  72. ---------------------------------------------------------------------------*/
  73. BOOL CBaseDialog::OnHelpInfo(HELPINFO* pHelpInfo)
  74. {
  75. int i;
  76. DWORD dwCtrlId;
  77. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  78. {
  79. DWORD * pdwHelp = GetHelpMapInternal();
  80. if (pdwHelp)
  81. {
  82. // Ok to fix the f**king help for the f**king IP address
  83. // controls, we will need to add special case code. If we
  84. // can't find the id of our control in our list, then we look
  85. // to see if this is the child of the "RtrIpAddress" control, if
  86. // so then we change the pHelpInfo->hItemHandle to point to the
  87. // handle of the ip address control rather than the control in
  88. // the ip addrss control. *SIGH*
  89. dwCtrlId = ::GetDlgCtrlID((HWND) pHelpInfo->hItemHandle);
  90. for (i=0; pdwHelp[i]; i+=2)
  91. {
  92. if (pdwHelp[i] == dwCtrlId)
  93. break;
  94. }
  95. if (pdwHelp[i] == 0)
  96. {
  97. // Ok, we didn't find the control in our list, so let's
  98. // check to see if it's part of the IP address control.
  99. pHelpInfo->hItemHandle = FixupIpAddressHelp((HWND) pHelpInfo->hItemHandle);
  100. }
  101. #ifdef DEBUG
  102. LPCTSTR pszTemp = AfxGetApp()->m_pszHelpFilePath;
  103. #endif
  104. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  105. AfxGetApp()->m_pszHelpFilePath,
  106. HELP_WM_HELP,
  107. (ULONG_PTR)pdwHelp);
  108. }
  109. }
  110. return TRUE;
  111. }
  112. /*!--------------------------------------------------------------------------
  113. CBaseDialog::OnContextMenu
  114. Brings up the help context menu for those controls that don't
  115. usually have context menus (i.e. buttons). Note that this won't
  116. work for static controls since they just eat up all messages.
  117. Author: EricDav
  118. ---------------------------------------------------------------------------*/
  119. void CBaseDialog::OnContextMenu(CWnd* pWnd, CPoint point)
  120. {
  121. DWORD * pdwHelp = GetHelpMapInternal();
  122. if (pdwHelp)
  123. {
  124. ::WinHelp (pWnd->m_hWnd,
  125. AfxGetApp()->m_pszHelpFilePath,
  126. HELP_CONTEXTMENU,
  127. (ULONG_PTR)pdwHelp);
  128. }
  129. }
  130. /*!--------------------------------------------------------------------------
  131. CBaseDialog::GetHelpMapInternal
  132. -
  133. Author: KennT
  134. ---------------------------------------------------------------------------*/
  135. DWORD * CBaseDialog::GetHelpMapInternal()
  136. {
  137. DWORD * pdwHelpMap = NULL;
  138. DWORD dwIDD = 0;
  139. // if (HIWORD(m_lpszTemplateName) == 0)
  140. // dwIDD = LOWORD((DWORD) m_lpszTemplateName);
  141. if ((ULONG_PTR) m_lpszTemplateName < 0xFFFF)
  142. dwIDD = (WORD) m_lpszTemplateName;
  143. // If there is no dialog IDD, give up
  144. // If there is no global help map function, give up
  145. if ((dwIDD == 0) ||
  146. (g_pfnHelpMap == NULL) ||
  147. ((pdwHelpMap = g_pfnHelpMap(dwIDD)) == NULL))
  148. return GetHelpMap();
  149. return pdwHelpMap;
  150. }