Source code of Windows XP (NT5)
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.

188 lines
3.7 KiB

  1. //*******************************************************************************************
  2. //
  3. // Filename : Dlg.cpp
  4. //
  5. // Implementation file for CDlg, CFileDlg and CPropPage
  6. //
  7. // Copyright (c) 1994 - 1996 Microsoft Corporation. All rights reserved
  8. //
  9. //*******************************************************************************************
  10. #include "Pch.H"
  11. #include "ThisDll.H"
  12. #include "Dlg.H"
  13. INT_PTR CDlg::RealDlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  14. {
  15. return(FALSE);
  16. }
  17. INT_PTR CALLBACK CDlg::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  18. {
  19. CDlg *pThis = (CDlg *)GetWindowLongPtr(hDlg, DWLP_USER);
  20. if (uMsg == WM_INITDIALOG)
  21. {
  22. pThis = (CDlg *)lParam;
  23. pThis->m_hDlg = hDlg;
  24. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  25. }
  26. else if (!pThis)
  27. {
  28. return(FALSE);
  29. }
  30. return(pThis->RealDlgProc(uMsg, wParam, lParam));
  31. }
  32. int CDlg::DoModal(UINT idRes, HWND hParent)
  33. {
  34. return((int)DialogBoxParam(g_ThisDll.GetInstance(), MAKEINTRESOURCE(idRes), hParent,
  35. DlgProc, (LPARAM)this));
  36. }
  37. HWND CDlg::DoModeless(UINT idRes, HWND hParent)
  38. {
  39. return(CreateDialogParam(g_ThisDll.GetInstance(), MAKEINTRESOURCE(idRes), hParent,
  40. DlgProc, (LPARAM)this));
  41. }
  42. CFileDlg::CFileDlg(HWND hwndParent, LPCTSTR szFilter, LPTSTR szFile, UINT uFileLen,
  43. LPCTSTR szTitle)
  44. : m_dwError(0)
  45. {
  46. memset((LPOPENFILENAME)this, 0, sizeof(OPENFILENAME));
  47. lStructSize = sizeof(OPENFILENAME);
  48. hwndOwner = hwndParent;
  49. hInstance = g_ThisDll.GetInstance();
  50. lpstrFilter = szFilter;
  51. lpstrFile = szFile;
  52. nMaxFile = uFileLen;
  53. lpstrTitle = szTitle;
  54. }
  55. UINT_PTR CFileDlg::RealHookProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  56. {
  57. return(FALSE);
  58. }
  59. UINT_PTR CFileDlg::HookProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  60. {
  61. CFileDlg *pThis = (CFileDlg *)GetWindowLongPtr(hDlg, DWLP_USER);
  62. if (uMsg == WM_INITDIALOG)
  63. {
  64. LPOPENFILENAME pofn = (LPOPENFILENAME)lParam;
  65. pThis = (CFileDlg *)pofn->lCustData;
  66. pThis->m_hDlg = hDlg;
  67. SetWindowLongPtr(hDlg, DWLP_USER, pofn->lCustData);
  68. }
  69. else if (!pThis)
  70. {
  71. return(FALSE);
  72. }
  73. return(pThis->RealHookProc(uMsg, wParam, lParam));
  74. }
  75. BOOL CFileOpenDlg::DoModal()
  76. {
  77. // Caller needs to set OFN_ENABLEHOOK to get a hook
  78. lpfnHook = HookProc;
  79. lCustData = (LPARAM)this;
  80. BOOL bRet = GetOpenFileName(this);
  81. m_dwError = bRet ? 0 : CommDlgExtendedError();
  82. return(bRet);
  83. }
  84. CPropPage::~CPropPage()
  85. {
  86. }
  87. CPropPage::CPropPage(LPCTSTR szTmplt)
  88. {
  89. dwSize = sizeof(CPropPage);
  90. dwFlags = PSP_DEFAULT;
  91. hInstance = g_ThisDll.GetInstance();
  92. pszTemplate = szTmplt;
  93. pfnDlgProc = PageProc;
  94. m_pThis = this;
  95. }
  96. HRESULT CPropPage::DoModeless(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  97. {
  98. dwFlags |= PSP_USECALLBACK;
  99. pfnCallback = PageRelease;
  100. // add the page; note this whole object has been copied to the page structure
  101. HPROPSHEETPAGE hPage = CreatePropertySheetPage(this);
  102. if (!hPage)
  103. {
  104. return(E_OUTOFMEMORY);
  105. }
  106. if (!lpfnAddPage(hPage, lParam))
  107. {
  108. return(E_UNEXPECTED);
  109. }
  110. return(NOERROR);
  111. }
  112. INT_PTR CALLBACK CPropPage::PageProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  113. {
  114. CPropPage *pThis = (CPropPage *)GetWindowLongPtr(hDlg, DWLP_USER);
  115. if (uMsg == WM_INITDIALOG)
  116. {
  117. CPropPage *pThat = IToClass(CPropPage, dwSize, lParam);
  118. pThis = pThat->m_pThis;
  119. pThis->m_hPage = hDlg;
  120. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pThis);
  121. }
  122. else if (!pThis)
  123. {
  124. return(FALSE);
  125. }
  126. return(pThis->RealPageProc(uMsg, wParam, lParam));
  127. }
  128. UINT CALLBACK CPropPage::PageRelease(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  129. {
  130. if (uMsg == PSPCB_RELEASE)
  131. {
  132. CPropPage *pThat = IToClass(CPropPage, dwSize, ppsp);
  133. CPropPage *pThis = pThat->m_pThis;
  134. delete pThis;
  135. }
  136. return(TRUE);
  137. }
  138. INT_PTR CPropPage::RealPageProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  139. {
  140. return(FALSE);
  141. }