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.

167 lines
4.5 KiB

  1. /******************************************************************************
  2. Source File: Dialog.CPP
  3. Implements the CDialog class. See Dialog.H for class definitions and details
  4. Copyright (c) 1996 by Microsoft Corporation
  5. A Pretty Penny Enterprises Production
  6. Change History:
  7. 11-01-96 a-robkj@microsoft.com Created it
  8. 12-11-96 a-robkj@microsoft.com Implemented hook
  9. ******************************************************************************/
  10. #include "ICMUI.H"
  11. // CDialog member functions
  12. // Class constructor- just save things, for now
  13. CDialog::CDialog(HINSTANCE hiWhere, int id, HWND hwndParent) {
  14. m_idMain = id;
  15. m_hwndParent = hwndParent;
  16. m_hiWhere = hiWhere;
  17. m_bIsModal = FALSE;
  18. m_hwnd = NULL;
  19. m_dpHook = NULL;
  20. m_lpHook = 0;
  21. }
  22. CDialog::CDialog(CDialog &cdOwner, int id) {
  23. m_idMain = id;
  24. m_hwndParent = cdOwner.m_hwnd;
  25. m_hiWhere = cdOwner.m_hiWhere;
  26. m_bIsModal = FALSE;
  27. m_hwnd = NULL;
  28. m_dpHook = NULL;
  29. m_lpHook = 0;
  30. }
  31. // Class destructor- clean up the window, if it is modeless.
  32. CDialog::~CDialog() {
  33. Destroy();
  34. }
  35. // Modal Dialog Box
  36. LONG CDialog::DoModal() {
  37. m_bIsModal = TRUE;
  38. return (LONG)DialogBoxParam(m_hiWhere, MAKEINTRESOURCE(m_idMain), m_hwndParent,
  39. CDialog::DialogProc, (LPARAM) this);
  40. }
  41. // Modeless dialog box creation
  42. void CDialog::Create() {
  43. if (!m_bIsModal && m_hwnd)
  44. return; // We'va already got one!
  45. m_bIsModal = FALSE;
  46. CreateDialogParam(m_hiWhere, MAKEINTRESOURCE(m_idMain),
  47. m_hwndParent, CDialog::DialogProc, (LPARAM) this);
  48. }
  49. // Modeless dialog box destruction
  50. void CDialog::Destroy() {
  51. if (!m_bIsModal && m_hwnd) {
  52. DestroyWindow(m_hwnd);
  53. m_hwnd = NULL;
  54. }
  55. }
  56. // Dialog Procedure- this is a static private method. This means
  57. // that all instances of this class (including derived classes) share
  58. // this code (no pointers needed) and that only instances of this
  59. // class (not even derived classes) can find it.
  60. INT_PTR CALLBACK CDialog::DialogProc(HWND hwndMe, UINT uMsg, WPARAM wp,
  61. LPARAM lp) {
  62. CDialog *pcdMe = (CDialog *) GetWindowLongPtr(hwndMe, DWLP_USER);
  63. // If there is a hook procedure, it can either ignore or filter a
  64. // message by returning FALSE, or it can handle itself by returning
  65. // TRUE. WM_INITDALOG hook processing occurs AFTER all of our other
  66. // calls are made, and we allow the base class to define the LPARAM
  67. // that is passed in to the hook.
  68. // Because we do not have a pointer to the base class, we will miss
  69. // messages sent before WM_INITDIALOG (specifically WM_SETFONT)
  70. if (uMsg != WM_INITDIALOG && pcdMe && pcdMe -> m_dpHook &&
  71. (*pcdMe -> m_dpHook)(hwndMe, uMsg, wp, lp))
  72. return TRUE;
  73. switch (uMsg) {
  74. case WM_INITDIALOG:
  75. // The lp is the this pointer for the caller
  76. pcdMe = (CDialog *) lp;
  77. if(!pcdMe)
  78. {
  79. return FALSE;
  80. }
  81. SetWindowLongPtr(hwndMe, DWLP_USER, (LONG_PTR)pcdMe);
  82. pcdMe -> m_hwnd = hwndMe;
  83. // Derived classes override OnInit to initialize the dialog
  84. if (!pcdMe -> m_dpHook)
  85. return pcdMe -> OnInit();
  86. else {
  87. // If there is a hook procedure, we will call that after the
  88. // override- if the override returned FALSE, so must we
  89. BOOL bReturn = pcdMe -> OnInit();
  90. return (*pcdMe -> m_dpHook)(hwndMe, uMsg, wp,
  91. pcdMe -> m_lpHook) && bReturn;
  92. }
  93. case WM_COMMAND:
  94. if(pcdMe)
  95. {
  96. return pcdMe -> OnCommand(HIWORD(wp), LOWORD(wp), (HWND) lp);
  97. }
  98. break;
  99. case WM_NOTIFY:
  100. if(pcdMe)
  101. {
  102. return pcdMe -> OnNotify((int) wp, (LPNMHDR) lp);
  103. }
  104. break;
  105. case WM_HELP:
  106. if(pcdMe)
  107. {
  108. return pcdMe -> OnHelp((LPHELPINFO) lp);
  109. }
  110. break;
  111. case WM_CONTEXTMENU:
  112. if(pcdMe)
  113. {
  114. return pcdMe -> OnContextMenu((HWND) wp);
  115. }
  116. break;
  117. }
  118. return FALSE;
  119. }
  120. // Moves the window into position (needed to get dialogs positioned proeprly
  121. // in tab control display area).
  122. void CDialog::Adjust(RECT& rc) {
  123. SetWindowPos(m_hwnd, HWND_TOP, rc.left, rc.top, 0, 0,
  124. SWP_NOACTIVATE | SWP_NOSIZE | SWP_SHOWWINDOW);
  125. }