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.

215 lines
5.2 KiB

  1. // ShrPgSMB.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ShrPgSMB.h"
  5. #include "compdata.h"
  6. #include "filesvc.h"
  7. #include "CacheSet.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSharePageGeneralSMB property page
  15. IMPLEMENT_DYNCREATE(CSharePageGeneralSMB, CSharePageGeneral)
  16. CSharePageGeneralSMB::CSharePageGeneralSMB() :
  17. CSharePageGeneral(CSharePageGeneralSMB::IDD),
  18. m_fEnableCacheFlag( FALSE ),
  19. m_dwFlags( 0 ),
  20. m_fEnableCachingButton (TRUE)
  21. {
  22. //{{AFX_DATA_INIT(CSharePageGeneralSMB)
  23. // NOTE: the ClassWizard will add member initialization here
  24. //}}AFX_DATA_INIT
  25. }
  26. CSharePageGeneralSMB::~CSharePageGeneralSMB()
  27. {
  28. }
  29. void CSharePageGeneralSMB::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CSharePageGeneral::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CSharePageGeneralSMB)
  33. DDX_Control(pDX, IDC_CACHING, m_cacheBtn);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CSharePageGeneralSMB, CSharePageGeneral)
  37. //{{AFX_MSG_MAP(CSharePageGeneralSMB)
  38. ON_BN_CLICKED(IDC_CACHING, OnCaching)
  39. ON_MESSAGE(WM_HELP, OnHelp)
  40. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CSharePageGeneralSMB message handlers
  45. BOOL CSharePageGeneralSMB::Load( CFileMgmtComponentData* pFileMgmtData, LPDATAOBJECT piDataObject )
  46. {
  47. ASSERT( NULL == m_pFileMgmtData && NULL != pFileMgmtData && NULL != piDataObject );
  48. if ( CSharePageGeneral::Load (pFileMgmtData, piDataObject) )
  49. {
  50. NET_API_STATUS retval = m_pFileMgmtData->GetFileServiceProvider(
  51. m_transport)->ReadShareFlags(
  52. m_strMachineName,
  53. m_strShareName,
  54. &m_dwFlags );
  55. switch (retval)
  56. {
  57. case NERR_Success:
  58. m_fEnableCacheFlag = TRUE;
  59. break;
  60. case NERR_InvalidAPI:
  61. case ERROR_INVALID_LEVEL:
  62. m_fEnableCachingButton = FALSE;
  63. break;
  64. default:
  65. m_fEnableCachingButton = FALSE;
  66. break;
  67. }
  68. }
  69. else
  70. return FALSE;
  71. return TRUE;
  72. }
  73. BOOL CSharePageGeneralSMB::OnApply()
  74. {
  75. if (m_dwShareType & STYPE_IPC)
  76. return TRUE;
  77. // UpdateData (TRUE) has already been called by OnKillActive () just before OnApply ()
  78. if ( m_fEnableCacheFlag && IsModified () )
  79. {
  80. NET_API_STATUS retval =
  81. m_pFileMgmtData->GetFileServiceProvider(m_transport)->WriteShareFlags(
  82. m_strMachineName,
  83. m_strShareName,
  84. m_dwFlags );
  85. if (0L == retval)
  86. {
  87. return CSharePageGeneral::OnApply();
  88. }
  89. else
  90. {
  91. CString introMsg;
  92. VERIFY (introMsg.LoadString (IDS_CANT_SAVE_CHANGES));
  93. DisplayNetMsgError (introMsg, retval);
  94. }
  95. }
  96. else
  97. return CSharePageGeneral::OnApply();
  98. return FALSE;
  99. }
  100. void CSharePageGeneralSMB::DisplayNetMsgError (CString introMsg, NET_API_STATUS dwErr)
  101. {
  102. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  103. LPVOID lpMsgBuf = 0;
  104. HMODULE hNetMsgDLL = ::LoadLibrary (L"netmsg.dll");
  105. if ( hNetMsgDLL )
  106. {
  107. ::FormatMessage (
  108. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE,
  109. hNetMsgDLL,
  110. dwErr,
  111. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  112. (LPTSTR) &lpMsgBuf, 0, NULL);
  113. // Display the string.
  114. CString caption;
  115. VERIFY (caption.LoadString (AFX_IDS_APP_TITLE));
  116. introMsg += L" ";
  117. introMsg += (LPTSTR) lpMsgBuf;
  118. CThemeContextActivator activator;
  119. MessageBox (introMsg, caption, MB_ICONWARNING | MB_OK);
  120. // Free the buffer.
  121. ::LocalFree (lpMsgBuf);
  122. ::FreeLibrary (hNetMsgDLL);
  123. }
  124. }
  125. void CSharePageGeneralSMB::OnCaching()
  126. {
  127. CCacheSettingsDlg dlg (this, INOUT m_dwFlags);
  128. CThemeContextActivator activator;
  129. if ( IDOK == dlg.DoModal () )
  130. {
  131. SetModified (TRUE);
  132. }
  133. }
  134. BOOL CSharePageGeneralSMB::OnInitDialog()
  135. {
  136. CSharePageGeneral::OnInitDialog();
  137. m_cacheBtn.EnableWindow (m_fEnableCachingButton);
  138. if (m_dwShareType & STYPE_IPC)
  139. {
  140. m_editShareName.SetReadOnly(TRUE);
  141. m_editPath.SetReadOnly(TRUE);
  142. m_editDescription.SetReadOnly(TRUE);
  143. m_checkBoxMaxAllowed.EnableWindow(FALSE);
  144. m_checkboxAllowSpecific.EnableWindow(FALSE);
  145. GetDlgItem(IDC_SHRPROP_EDIT_USERS)->EnableWindow(FALSE);
  146. GetDlgItem(IDC_SHRPROP_SPIN_USERS)->EnableWindow(FALSE);
  147. m_cacheBtn.EnableWindow(FALSE);
  148. (GetParent()->GetDlgItem(IDCANCEL))->EnableWindow(FALSE);
  149. }
  150. return TRUE; // return TRUE unless you set the focus to a control
  151. // EXCEPTION: OCX Property Pages should return FALSE
  152. }
  153. static DWORD rgCSCUIHelpIds[] =
  154. {
  155. IDC_CACHING, 1019, //IDH_SHARE_CACHING_BTN,
  156. 0, 0
  157. };
  158. /////////////////////////////////////////////////////////////////////
  159. // Help
  160. BOOL CSharePageGeneralSMB::OnHelp(WPARAM wParam, LPARAM lParam)
  161. {
  162. LPHELPINFO lphi = (LPHELPINFO) lParam;
  163. if ( HELPINFO_WINDOW == lphi->iContextType ) // a control
  164. {
  165. if ( IDC_CACHING == lphi->iCtrlId )
  166. {
  167. return ::WinHelp ((HWND) lphi->hItemHandle, L"cscui.hlp",
  168. HELP_WM_HELP,
  169. (DWORD_PTR) rgCSCUIHelpIds);
  170. }
  171. }
  172. return CSharePageGeneral::OnHelp (wParam, lParam);
  173. }
  174. BOOL CSharePageGeneralSMB::OnContextHelp(WPARAM wParam, LPARAM lParam)
  175. {
  176. int ctrlID = ::GetDlgCtrlID ((HWND) wParam);
  177. if ( IDC_CACHING == ctrlID )
  178. {
  179. return ::WinHelp ((HWND) wParam, L"cscui.hlp", HELP_CONTEXTMENU,
  180. (DWORD_PTR) rgCSCUIHelpIds);
  181. }
  182. return CSharePageGeneral::OnContextHelp (wParam, lParam);
  183. }