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.

152 lines
3.6 KiB

  1. #include "shellprv.h"
  2. #include "filetype.h"
  3. #include "ftprop.h"
  4. #include "ids.h"
  5. HRESULT CreateFileTypePage(HPROPSHEETPAGE *phpsp)
  6. {
  7. *phpsp = NULL;
  8. HRESULT hr;
  9. CFTPropDlg* pPropDlg = new CFTPropDlg();
  10. if (pPropDlg)
  11. {
  12. PROPSHEETPAGE psp;
  13. psp.dwSize = sizeof(psp);
  14. psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK;
  15. psp.hInstance = g_hinst;
  16. psp.pfnCallback = CFTDlg::BaseDlgPropSheetCallback;
  17. psp.pszTemplate = MAKEINTRESOURCE(DLG_FILETYPEOPTIONS);
  18. psp.pfnDlgProc = CFTDlg::BaseDlgWndProc;
  19. psp.lParam = (LPARAM)pPropDlg;
  20. *phpsp = CreatePropertySheetPage(&psp);
  21. if (*phpsp)
  22. {
  23. pPropDlg->AddRef();
  24. hr = S_OK;
  25. }
  26. else
  27. {
  28. hr = E_OUTOFMEMORY;
  29. }
  30. pPropDlg->Release();
  31. }
  32. else
  33. {
  34. hr = E_OUTOFMEMORY;
  35. }
  36. return hr;
  37. }
  38. class CFileTypes : public IShellPropSheetExt
  39. {
  40. public:
  41. CFileTypes() : _cRef(1) {}
  42. // IUnknown
  43. STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  44. STDMETHODIMP_(ULONG) AddRef(void);
  45. STDMETHODIMP_(ULONG) Release(void);
  46. // IShellPropSheetExt
  47. STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE pAddPageProc, LPARAM lParam);
  48. STDMETHODIMP ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pReplacePageFunc, LPARAM lParam);
  49. private:
  50. LONG _cRef;
  51. };
  52. STDMETHODIMP CFileTypes::QueryInterface(REFIID riid, void **ppv)
  53. {
  54. static const QITAB qit[] =
  55. {
  56. QITABENT(CFileTypes, IShellPropSheetExt), // IID_IShellPropSheetExt
  57. { 0 },
  58. };
  59. return QISearch(this, qit, riid, ppv);
  60. }
  61. STDMETHODIMP_(ULONG) CFileTypes::AddRef()
  62. {
  63. return InterlockedIncrement(&_cRef);
  64. }
  65. STDMETHODIMP_(ULONG) CFileTypes::Release()
  66. {
  67. ASSERT( 0 != _cRef );
  68. ULONG cRef = InterlockedDecrement(&_cRef);
  69. if ( 0 == cRef )
  70. {
  71. delete this;
  72. }
  73. return cRef;
  74. }
  75. // IShellPropSheetExt::AddPages
  76. STDMETHODIMP CFileTypes::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam)
  77. {
  78. HPROPSHEETPAGE hpsp;
  79. // Make sure the FileIconTable is init properly. If brought in
  80. // by inetcpl we need to set this true...
  81. FileIconInit(TRUE);
  82. // We need to run the unicode version on NT, to avoid all bugs
  83. // that occur with the ANSI version (due to unicode-to-ansi
  84. // conversions of file names).
  85. HRESULT hr = CreateFileTypePage(&hpsp);
  86. if (SUCCEEDED(hr) && !pfnAddPage(hpsp, lParam))
  87. {
  88. DestroyPropertySheetPage(hpsp);
  89. hr = E_FAIL;
  90. }
  91. return hr;
  92. }
  93. // IShellPropSheetExt::ReplacePage
  94. STDMETHODIMP CFileTypes::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplaceWith, LPARAM lParam)
  95. {
  96. HRESULT hr = E_NOTIMPL;
  97. if (EXPPS_FILETYPES == uPageID)
  98. {
  99. HPROPSHEETPAGE hpsp;
  100. // We need to run the unicode version on NT, to avoid all bugs
  101. // that occur with the ANSI version (due to unicode-to-ansi
  102. // conversions of file names).
  103. hr = CreateFileTypePage(&hpsp);
  104. if (SUCCEEDED(hr) && !pfnReplaceWith(hpsp, lParam))
  105. {
  106. hr = E_FAIL;
  107. }
  108. }
  109. return hr;
  110. }
  111. STDAPI CFileTypes_CreateInstance(IUnknown* punkOuter, REFIID riid, void **ppv)
  112. {
  113. HRESULT hr;
  114. CFileTypes * pft = new CFileTypes;
  115. if (pft)
  116. {
  117. hr = pft->QueryInterface(riid, ppv);
  118. pft->Release();
  119. }
  120. else
  121. {
  122. *ppv = NULL;
  123. hr = E_OUTOFMEMORY;
  124. }
  125. return hr;
  126. }