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.

1543 lines
54 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000
  5. //
  6. // File: CmdDlg.cxx
  7. //
  8. // Contents: Dialogs for all context menu commands
  9. //
  10. // History: 26-Nov-1996 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <CIARes.h>
  16. #include <CmdDlg.hxx>
  17. #include <Catalog.hxx>
  18. #include <cierror.h>
  19. #include <catadmin.hxx>
  20. #include <shlobj.h>
  21. extern "C"
  22. {
  23. #include <lmcons.h>
  24. }
  25. //
  26. // Local prototypes
  27. //
  28. BOOL GetDlgItemXArrayText( HWND hwndDlg, USHORT idCtrl, XArray<WCHAR> & xawcText );
  29. BOOL BrowseForDirectory( HWND hwndParent,
  30. LPCTSTR pszInitialDir,
  31. LPTSTR pszBuf,
  32. int cchBuf,
  33. LPCTSTR pszDialogTitle,
  34. BOOL bRemoveTrailingBackslash );
  35. void SetSliderPositions(HWND hwndDlg, WORD wIndexingPos, WORD wQueryingPos);
  36. INT_PTR APIENTRY AddScopeDlg( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam )
  37. {
  38. BOOL fRet = FALSE;
  39. switch ( message )
  40. {
  41. case WM_HELP:
  42. {
  43. HELPINFO *phi = (HELPINFO *) lParam;
  44. ciaDebugOut(( DEB_ITRACE, "AddScopeDlg WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  45. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  46. phi->iCtrlId, phi->dwContextId ));
  47. if ( HELPINFO_WINDOW == phi->iContextType )
  48. {
  49. switch ( phi->iCtrlId )
  50. {
  51. case IDDI_STATIC:
  52. break;
  53. default :
  54. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  55. break;
  56. }
  57. }
  58. break;
  59. }
  60. case WM_CONTEXTMENU:
  61. {
  62. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  63. break;
  64. }
  65. case WM_INITDIALOG:
  66. SetWindowLongPtr( hwndDlg, DWLP_USER, lParam );
  67. SendDlgItemMessage( hwndDlg, IDDI_INCLUDE, BM_SETCHECK, BST_CHECKED, 0 );
  68. EnableWindow( GetDlgItem( hwndDlg, IDDI_USER_NAME ), FALSE );
  69. EnableWindow( GetDlgItem( hwndDlg, IDDI_PASSWORD ), FALSE );
  70. EnableWindow( GetDlgItem( hwndDlg, IDOK ), FALSE );
  71. ciaDebugOut(( DEB_TRACE, "AddScope (WM_INITDIALOG) - 0x%x\n", lParam ));
  72. fRet = TRUE;
  73. break;
  74. case WM_COMMAND:
  75. switch ( LOWORD( wParam ) )
  76. {
  77. case IDDI_USER_NAME:
  78. case IDDI_PASSWORD:
  79. {
  80. if ( EN_CHANGE == HIWORD(wParam) )
  81. {
  82. XArray<WCHAR> xawcTemp;
  83. //
  84. // Only user name needs to be filled. Password can be empty.
  85. //
  86. if ( GetDlgItemXArrayText( hwndDlg, IDDI_USER_NAME, xawcTemp ) )
  87. EnableWindow( GetDlgItem( hwndDlg, IDOK ), xawcTemp.Count() > 0 );
  88. }
  89. break;
  90. }
  91. case IDDI_DIRPATH:
  92. {
  93. if ( EN_CHANGE == HIWORD(wParam) )
  94. {
  95. XArray<WCHAR> xawcPath;
  96. if ( GetDlgItemXArrayText( hwndDlg, IDDI_DIRPATH, xawcPath ) &&
  97. xawcPath.Count() >= 2 &&
  98. xawcPath[0] == L'\\' && xawcPath[1] == L'\\' )
  99. {
  100. WCHAR * pwcsSlash = wcschr( xawcPath.GetPointer() + 2, L'\\' );
  101. // Assuming the machinename portion can be no longer than MAX_PATH
  102. if ( 0 != pwcsSlash && *(pwcsSlash+1) != L'\0' &&
  103. (pwcsSlash - xawcPath.GetPointer() - 2) <= MAX_PATH )
  104. {
  105. EnableWindow( GetDlgItem( hwndDlg, IDDI_USER_NAME ), TRUE );
  106. SetDlgItemText( hwndDlg, IDDI_USER_NAME, L"" );
  107. EnableWindow( GetDlgItem( hwndDlg, IDDI_PASSWORD ), TRUE );
  108. SetDlgItemText( hwndDlg, IDDI_PASSWORD, L"" );
  109. EnableWindow( GetDlgItem( hwndDlg, IDDI_ALIAS), FALSE );
  110. // username/pwd are not essential!
  111. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  112. }
  113. else
  114. {
  115. EnableWindow( GetDlgItem( hwndDlg, IDDI_USER_NAME ), FALSE );
  116. EnableWindow( GetDlgItem( hwndDlg, IDDI_PASSWORD ), FALSE );
  117. EnableWindow( GetDlgItem( hwndDlg, IDDI_ALIAS), FALSE );
  118. EnableWindow( GetDlgItem( hwndDlg, IDOK ), FALSE );
  119. }
  120. }
  121. else
  122. {
  123. EnableWindow( GetDlgItem( hwndDlg, IDDI_USER_NAME ), FALSE );
  124. EnableWindow( GetDlgItem( hwndDlg, IDDI_PASSWORD ), FALSE );
  125. EnableWindow( GetDlgItem( hwndDlg, IDDI_ALIAS), TRUE );
  126. EnableWindow( GetDlgItem( hwndDlg, IDOK ), xawcPath.Count() > 0 );
  127. }
  128. }
  129. fRet = TRUE;
  130. break;
  131. }
  132. case IDDI_INCLUDE:
  133. case IDDI_EXCLUDE:
  134. {
  135. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  136. break;
  137. }
  138. case IDDI_BROWSE:
  139. {
  140. // Disable the button so users can't launch multiple dialogs simultaneously
  141. EnableWindow(GetDlgItem( hwndDlg, IDDI_BROWSE ), FALSE);
  142. if ( BN_CLICKED == HIWORD( wParam ) )
  143. {
  144. XArray<WCHAR> xawcPath;
  145. if ( GetDlgItemXArrayText( hwndDlg, IDDI_DIRPATH, xawcPath ) )
  146. {
  147. if ( xawcPath.IsNull() )
  148. {
  149. xawcPath.Init( 2 );
  150. xawcPath[0] = L'\\';
  151. xawcPath[1] = 0;
  152. }
  153. WCHAR awc[MAX_PATH];
  154. if ( BrowseForDirectory( GetParent(hwndDlg), // Parent
  155. xawcPath.GetPointer(), // Current path
  156. awc, // New path goes here...
  157. MAX_PATH,
  158. 0, // Title
  159. TRUE ) ) // Remove trailing slash
  160. {
  161. SetWindowText( GetDlgItem( hwndDlg, IDDI_DIRPATH ), awc );
  162. }
  163. EnableWindow(GetDlgItem( hwndDlg, IDDI_BROWSE ), TRUE);
  164. // Set focus on dialog so user can continue working...
  165. SetFocus(hwndDlg);
  166. }
  167. }
  168. fRet = TRUE;
  169. break;
  170. }
  171. case IDOK:
  172. {
  173. XArray<WCHAR> xawcPath;
  174. XArray<WCHAR> xawcAlias;
  175. XArray<WCHAR> xawcLogon;
  176. XArray<WCHAR> xawcPassword;
  177. //
  178. // Consider adding code to validate path. Warn user if path is invalid.
  179. // We don't really want to do this as it's a common admin scenario to
  180. // add paths that don't exist.
  181. //
  182. if ( GetDlgItemXArrayText( hwndDlg, IDDI_DIRPATH, xawcPath ) )
  183. {
  184. //
  185. // Local or remote?
  186. //
  187. if ( IsWindowEnabled( GetDlgItem( hwndDlg, IDDI_ALIAS ) ) )
  188. {
  189. GetDlgItemXArrayText( hwndDlg, IDDI_ALIAS, xawcAlias );
  190. }
  191. else
  192. {
  193. GetDlgItemXArrayText( hwndDlg, IDDI_USER_NAME, xawcLogon );
  194. GetDlgItemXArrayText( hwndDlg, IDDI_PASSWORD, xawcPassword );
  195. }
  196. BOOL fInclude = ( BST_CHECKED == IsDlgButtonChecked( hwndDlg, IDDI_INCLUDE ) );
  197. Win4Assert( fInclude == ( BST_UNCHECKED == IsDlgButtonChecked( hwndDlg, IDDI_EXCLUDE ) ));
  198. CCatalog * pCat= (CCatalog *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  199. SCODE sc = pCat->AddScope( xawcPath.GetPointer(),
  200. xawcAlias.GetPointer(),
  201. !fInclude,
  202. xawcLogon.GetPointer(),
  203. xawcPassword.GetPointer() ? xawcPassword.GetPointer() : L"" );
  204. if ( !xawcPassword.IsNull() )
  205. {
  206. SecureZeroMemory( xawcPassword.GetPointer(),
  207. xawcPassword.SizeOf() );
  208. }
  209. if ( SUCCEEDED(sc) )
  210. EndDialog( hwndDlg, TRUE );
  211. else
  212. {
  213. WCHAR * pBuf = 0;
  214. //
  215. // Convert Win32 errors back from HRESULT
  216. //
  217. if ( (sc & (FACILITY_WIN32 << 16)) == (FACILITY_WIN32 << 16) )
  218. sc &= ~( 0x80000000 | (FACILITY_WIN32 << 16) );
  219. ULONG cchAvailMessage = 1024;
  220. if ( !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE |
  221. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  222. GetModuleHandle(L"query.dll"),
  223. sc,
  224. 0,
  225. (WCHAR *)&pBuf,
  226. 0,
  227. 0 ) &&
  228. !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE |
  229. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  230. GetModuleHandle(L"kernel32.dll"),
  231. sc,
  232. 0,
  233. (WCHAR *)&pBuf,
  234. 0,
  235. 0 )
  236. )
  237. {
  238. MessageBox(hwndDlg, STRINGRESOURCE( srCMUnexpectedError ),
  239. STRINGRESOURCE( srCMInvalidScope ), MB_ICONHAND);
  240. }
  241. else
  242. {
  243. MessageBox(hwndDlg, pBuf,
  244. STRINGRESOURCE( srCMInvalidScope ), MB_ICONHAND);
  245. LocalFree( pBuf );
  246. }
  247. }
  248. }
  249. fRet = TRUE;
  250. break;
  251. }
  252. case IDCANCEL:
  253. ciaDebugOut(( DEB_ITRACE, "AddScope (WM_COMMAND, IDCANCEL) - 0x%x\n",
  254. GetWindowLongPtr( hwndDlg, DWLP_USER ) ));
  255. EndDialog( hwndDlg, FALSE );
  256. }
  257. }
  258. return fRet;
  259. }
  260. // Modify the directory settings
  261. INT_PTR APIENTRY ModifyScopeDlg( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam )
  262. {
  263. BOOL fRet = FALSE;
  264. switch ( message )
  265. {
  266. case WM_HELP:
  267. {
  268. HELPINFO *phi = (HELPINFO *) lParam;
  269. ciaDebugOut(( DEB_ITRACE, "ModifyScopeDlg WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  270. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  271. phi->iCtrlId, phi->dwContextId ));
  272. if ( HELPINFO_WINDOW == phi->iContextType )
  273. {
  274. switch ( phi->iCtrlId )
  275. {
  276. case IDDI_STATIC:
  277. break;
  278. default :
  279. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  280. break;
  281. }
  282. }
  283. break;
  284. }
  285. case WM_CONTEXTMENU:
  286. {
  287. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  288. break;
  289. }
  290. case WM_INITDIALOG:
  291. {
  292. CScope *pScope = (CScope *)lParam;
  293. SetWindowLongPtr( hwndDlg, DWLP_USER, lParam );
  294. SendDlgItemMessage( hwndDlg, IDDI_INCLUDE, BM_SETCHECK, BST_CHECKED, 0 );
  295. SendDlgItemMessage( hwndDlg, IDDI_INCLUDE, BM_SETCHECK,
  296. pScope->IsIncluded() ? BST_CHECKED : BST_UNCHECKED, 0);
  297. SendDlgItemMessage( hwndDlg, IDDI_EXCLUDE, BM_SETCHECK,
  298. pScope->IsIncluded() ? BST_UNCHECKED : BST_CHECKED, 0);
  299. SetDlgItemText( hwndDlg, IDDI_DIRPATH, pScope->GetPath() );
  300. if (0 != pScope->GetAlias())
  301. SetDlgItemText( hwndDlg, IDDI_ALIAS, pScope->GetAlias() );
  302. WCHAR szBuffer[UNLEN + 1];
  303. Win4Assert(UNLEN >= PWLEN);
  304. szBuffer[0] = 0;
  305. pScope->GetUsername(szBuffer);
  306. SetDlgItemText( hwndDlg, IDDI_USER_NAME, szBuffer );
  307. szBuffer[0] = 0;
  308. pScope->GetPassword(szBuffer);
  309. SetDlgItemText( hwndDlg, IDDI_PASSWORD, szBuffer );
  310. ciaDebugOut(( DEB_ITRACE, "ModifyScope (WM_INITDIALOG) - 0x%x\n", lParam ));
  311. fRet = TRUE;
  312. break;
  313. }
  314. case WM_COMMAND:
  315. switch ( LOWORD( wParam ) )
  316. {
  317. case IDDI_USER_NAME:
  318. case IDDI_PASSWORD:
  319. {
  320. if ( EN_CHANGE == HIWORD(wParam) )
  321. {
  322. XArray<WCHAR> xawcTemp;
  323. //
  324. // Only user name needs to be filled. Password can be empty.
  325. //
  326. if ( GetDlgItemXArrayText( hwndDlg, IDDI_USER_NAME, xawcTemp ) )
  327. EnableWindow( GetDlgItem( hwndDlg, IDOK ), xawcTemp.Count() > 0 );
  328. }
  329. break;
  330. }
  331. // make sure to enable OK button on modify when this is touched
  332. // irrespective of the change.
  333. case IDDI_ALIAS:
  334. if ( EN_CHANGE == HIWORD(wParam) )
  335. EnableWindow( GetDlgItem(hwndDlg, IDOK), TRUE );
  336. break;
  337. case IDDI_DIRPATH:
  338. {
  339. if ( EN_CHANGE == HIWORD(wParam) )
  340. {
  341. XArray<WCHAR> xawcPath;
  342. if ( GetDlgItemXArrayText( hwndDlg, IDDI_DIRPATH, xawcPath ) &&
  343. xawcPath.Count() >= 2 &&
  344. xawcPath[0] == L'\\' && xawcPath[1] == L'\\' )
  345. {
  346. WCHAR * pwcsSlash = wcschr( xawcPath.GetPointer() + 2, L'\\' );
  347. // Assuming the machinename portion can be no longer than MAX_PATH
  348. if ( 0 != pwcsSlash && *(pwcsSlash+1) != L'\0' &&
  349. (pwcsSlash - xawcPath.GetPointer() - 2) <= MAX_PATH )
  350. {
  351. EnableWindow( GetDlgItem( hwndDlg, IDDI_USER_NAME ), TRUE );
  352. SetDlgItemText( hwndDlg, IDDI_USER_NAME, L"" );
  353. EnableWindow( GetDlgItem( hwndDlg, IDDI_PASSWORD ), TRUE );
  354. SetDlgItemText( hwndDlg, IDDI_PASSWORD, L"" );
  355. EnableWindow( GetDlgItem( hwndDlg, IDDI_ALIAS), FALSE );
  356. // username/pwd are not essential!
  357. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  358. }
  359. else
  360. {
  361. EnableWindow( GetDlgItem( hwndDlg, IDDI_USER_NAME ), FALSE );
  362. EnableWindow( GetDlgItem( hwndDlg, IDDI_PASSWORD ), FALSE );
  363. EnableWindow( GetDlgItem( hwndDlg, IDDI_ALIAS), FALSE );
  364. EnableWindow( GetDlgItem( hwndDlg, IDOK ), FALSE );
  365. }
  366. }
  367. else
  368. {
  369. EnableWindow( GetDlgItem( hwndDlg, IDDI_USER_NAME ), FALSE );
  370. EnableWindow( GetDlgItem( hwndDlg, IDDI_PASSWORD ), FALSE );
  371. EnableWindow( GetDlgItem( hwndDlg, IDDI_ALIAS), TRUE );
  372. EnableWindow( GetDlgItem( hwndDlg, IDOK ), xawcPath.Count() > 0 );
  373. }
  374. }
  375. fRet = TRUE;
  376. break;
  377. }
  378. case IDDI_INCLUDE:
  379. case IDDI_EXCLUDE:
  380. {
  381. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  382. break;
  383. }
  384. case IDDI_BROWSE:
  385. {
  386. // Disable the button so users can't launch multiple dialogs simultaneously
  387. EnableWindow(GetDlgItem( hwndDlg, IDDI_BROWSE ), FALSE);
  388. if ( BN_CLICKED == HIWORD( wParam ) )
  389. {
  390. XArray<WCHAR> xawcPath;
  391. if ( GetDlgItemXArrayText( hwndDlg, IDDI_DIRPATH, xawcPath ) )
  392. {
  393. if ( xawcPath.IsNull() )
  394. {
  395. xawcPath.Init( 2 );
  396. xawcPath[0] = L'\\';
  397. xawcPath[1] = 0;
  398. }
  399. WCHAR awc[MAX_PATH];
  400. if ( BrowseForDirectory( GetParent(hwndDlg), // Parent
  401. xawcPath.GetPointer(), // Current path
  402. awc, // New path goes here...
  403. MAX_PATH,
  404. 0, // Title
  405. TRUE ) ) // Remove trailing slash
  406. {
  407. SetWindowText( GetDlgItem( hwndDlg, IDDI_DIRPATH ), awc );
  408. }
  409. EnableWindow(GetDlgItem( hwndDlg, IDDI_BROWSE ), TRUE);
  410. // Set focus on dialog so user can continue working...
  411. SetFocus(hwndDlg);
  412. }
  413. }
  414. fRet = TRUE;
  415. break;
  416. }
  417. case IDOK:
  418. {
  419. XArray<WCHAR> xawcPath;
  420. XArray<WCHAR> xawcAlias;
  421. XArray<WCHAR> xawcLogon;
  422. XArray<WCHAR> xawcPassword;
  423. //
  424. // Consider adding code to validate path. Warn user if path is invalid.
  425. // We don't really want to do this as it's a common admin scenario to
  426. // add paths that don't exist.
  427. //
  428. if ( GetDlgItemXArrayText( hwndDlg, IDDI_DIRPATH, xawcPath ) )
  429. {
  430. //
  431. // Local or remote?
  432. //
  433. if ( IsWindowEnabled( GetDlgItem( hwndDlg, IDDI_ALIAS ) ) )
  434. {
  435. GetDlgItemXArrayText( hwndDlg, IDDI_ALIAS, xawcAlias );
  436. }
  437. else
  438. {
  439. GetDlgItemXArrayText( hwndDlg, IDDI_USER_NAME, xawcLogon );
  440. GetDlgItemXArrayText( hwndDlg, IDDI_PASSWORD, xawcPassword );
  441. }
  442. BOOL fInclude = ( BST_CHECKED == IsDlgButtonChecked( hwndDlg, IDDI_INCLUDE ) );
  443. Win4Assert( fInclude == ( BST_UNCHECKED == IsDlgButtonChecked( hwndDlg, IDDI_EXCLUDE ) ));
  444. CScope * pScope= (CScope *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  445. SCODE sc = pScope->GetCatalog().ModifyScope( *pScope,
  446. xawcPath.GetPointer(),
  447. xawcAlias.GetPointer(),
  448. !fInclude,
  449. xawcLogon.GetPointer(),
  450. xawcPassword.GetPointer() ? xawcPassword.GetPointer() : L"" );
  451. if ( !xawcPassword.IsNull() )
  452. {
  453. SecureZeroMemory( xawcPassword.GetPointer(),
  454. xawcPassword.SizeOf() );
  455. }
  456. if ( SUCCEEDED(sc) )
  457. EndDialog( hwndDlg, TRUE );
  458. else
  459. {
  460. WCHAR * pBuf = 0;
  461. //
  462. // Convert Win32 errors back from HRESULT
  463. //
  464. if ( (sc & (FACILITY_WIN32 << 16)) == (FACILITY_WIN32 << 16) )
  465. sc &= ~( 0x80000000 | (FACILITY_WIN32 << 16) );
  466. ULONG cchAvailMessage = 1024;
  467. if ( !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE |
  468. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  469. GetModuleHandle(L"query.dll"),
  470. sc,
  471. 0,
  472. (WCHAR *)&pBuf,
  473. 0,
  474. 0 ) &&
  475. !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE |
  476. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  477. GetModuleHandle(L"kernel32.dll"),
  478. sc,
  479. 0,
  480. (WCHAR *)&pBuf,
  481. 0,
  482. 0 )
  483. )
  484. {
  485. MessageBox(hwndDlg, STRINGRESOURCE( srCMUnexpectedError ),
  486. STRINGRESOURCE( srCMInvalidScope ), MB_ICONHAND);
  487. }
  488. else
  489. {
  490. MessageBox(hwndDlg, pBuf,
  491. STRINGRESOURCE( srCMInvalidScope ), MB_ICONHAND);
  492. LocalFree( pBuf );
  493. }
  494. }
  495. }
  496. fRet = TRUE;
  497. break;
  498. }
  499. case IDCANCEL:
  500. ciaDebugOut(( DEB_ITRACE, "ModifyScope (WM_COMMAND, IDCANCEL) - 0x%x\n",
  501. GetWindowLongPtr( hwndDlg, DWLP_USER ) ));
  502. EndDialog( hwndDlg, FALSE );
  503. }
  504. }
  505. return fRet;
  506. }
  507. INT_PTR APIENTRY WksTunePerfDlg( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam )
  508. {
  509. BOOL fRet = FALSE;
  510. static DWORD dwUsage, dwIndexPos, dwQueryPos;
  511. switch (message)
  512. {
  513. case WM_HELP:
  514. {
  515. HELPINFO *phi = (HELPINFO *) lParam;
  516. ciaDebugOut(( DEB_ITRACE, "WksTunePerfDlg WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  517. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  518. phi->iCtrlId, phi->dwContextId ));
  519. if ( HELPINFO_WINDOW == phi->iContextType )
  520. {
  521. switch ( phi->iCtrlId )
  522. {
  523. case IDDI_STATIC:
  524. break;
  525. default :
  526. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  527. break;
  528. }
  529. }
  530. break;
  531. }
  532. case WM_CONTEXTMENU:
  533. {
  534. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  535. break;
  536. }
  537. case WM_INITDIALOG:
  538. {
  539. ciaDebugOut(( DEB_ITRACE, "WksTunePerfDlg (WM_INITDIALOG) - 0x%x\n", lParam ));
  540. SetWindowLongPtr( hwndDlg, DWLP_USER, (LONG_PTR)lParam );
  541. // Initialize the dialog.
  542. CCatalogs *pCats = (CCatalogs *)lParam;
  543. pCats->GetSavedServiceUsage(dwUsage, dwIndexPos, dwQueryPos);
  544. switch (dwUsage)
  545. {
  546. case wUsedOften:
  547. SendDlgItemMessage( hwndDlg, IDDI_USEDOFTEN, BM_SETCHECK, BST_CHECKED, 0 );
  548. pCats->SaveServicePerformanceSettings(wHighPos, wMidPos);
  549. break;
  550. case wUsedOccasionally:
  551. SendDlgItemMessage( hwndDlg, IDDI_USEDOCCASIONALLY, BM_SETCHECK, BST_CHECKED, 0 );
  552. pCats->SaveServicePerformanceSettings(wLowPos, wLowPos);
  553. break;
  554. case wNeverUsed:
  555. SendDlgItemMessage( hwndDlg, IDDI_NEVERUSED, BM_SETCHECK, BST_CHECKED, 0 );
  556. break;
  557. case wCustom:
  558. SendDlgItemMessage( hwndDlg, IDDI_CUSTOMIZE, BM_SETCHECK, BST_CHECKED, 0 );
  559. pCats->SaveServicePerformanceSettings((WORD)dwIndexPos, (WORD)dwQueryPos);
  560. break;
  561. case wDedicatedServer:
  562. default:
  563. Win4Assert(!"How did we get here?");
  564. break;
  565. }
  566. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), dwUsage == wCustom);
  567. fRet = TRUE;
  568. }
  569. break;
  570. case WM_COMMAND:
  571. {
  572. CCatalogs *pCats = (CCatalogs *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  573. switch ( LOWORD( wParam ) )
  574. {
  575. case IDDI_USEDOFTEN:
  576. if (BN_CLICKED == HIWORD(wParam))
  577. {
  578. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), FALSE);
  579. pCats->SaveServicePerformanceSettings(wHighPos, wMidPos);
  580. dwUsage = wUsedOften;
  581. }
  582. break;
  583. case IDDI_USEDOCCASIONALLY:
  584. if (BN_CLICKED == HIWORD(wParam))
  585. {
  586. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), FALSE);
  587. pCats->SaveServicePerformanceSettings(wMidPos, wLowPos);
  588. dwUsage = wUsedOccasionally;
  589. }
  590. break;
  591. case IDDI_NEVERUSED:
  592. if (BN_CLICKED == HIWORD(wParam))
  593. {
  594. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), FALSE);
  595. dwUsage = wNeverUsed;
  596. }
  597. break;
  598. case IDDI_CUSTOMIZE:
  599. if (BN_CLICKED == HIWORD(wParam))
  600. {
  601. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), TRUE);
  602. dwUsage = wCustom;
  603. pCats->SaveServicePerformanceSettings((WORD)dwIndexPos, (WORD)dwQueryPos);
  604. }
  605. break;
  606. case IDDI_ADVANCED:
  607. {
  608. pCats->SetServiceUsage(dwUsage);
  609. DialogBoxParam( ghInstance, // Application instance
  610. MAKEINTRESOURCE( IDD_ADVANCED_INFO ), // Dialog box
  611. hwndDlg, // main frame window
  612. AdvPerfTuneDlg, // Dialog box function
  613. (LPARAM)pCats ); // User parameter
  614. break;
  615. }
  616. case IDOK:
  617. {
  618. fRet = TRUE;
  619. if (wNeverUsed == dwUsage)
  620. {
  621. int iResult;
  622. iResult = MessageBox( GetFocus(), STRINGRESOURCE( srCMShutdownService ),
  623. STRINGRESOURCE( srCMShutdownServiceTitle ),
  624. MB_YESNO | /* MB_HELP | */
  625. MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL );
  626. switch ( iResult )
  627. {
  628. case IDYES:
  629. {
  630. SCODE sc = pCats->DisableService();
  631. if (FAILED(sc))
  632. {
  633. MessageBox( GetFocus(), STRINGRESOURCE( srCMCantShutdownService ),
  634. STRINGRESOURCE( srCMShutdownServiceTitle ),
  635. MB_OK | /* MB_HELP | */
  636. MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL );
  637. }
  638. // Fall through and close the dialog.
  639. }
  640. case IDNO:
  641. default:
  642. // Do nothing. Just close the dialog
  643. EndDialog( hwndDlg, TRUE );
  644. break;
  645. }
  646. break;
  647. }
  648. SCODE sc = pCats->TuneServicePerformance();
  649. if (FAILED(sc))
  650. {
  651. // Inform user that performance tuning didn't go through.
  652. // The only reason this happens is if the registry params couldn't be set, which
  653. // should be a rare occurrence.
  654. MessageBox( GetFocus(), STRINGRESOURCE( srCMCantSaveSettings ),
  655. STRINGRESOURCE( srCMTunePerformance ),
  656. MB_OK | /* MB_HELP | */
  657. MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL );
  658. // About the only reason I can think of that could cause registry
  659. // save to fail is if the registry was messed up. In that case, does it
  660. // matter if we only saved part of what we wanted to save? Or should we be
  661. // careful enough to remember the old settings and restore the registry to
  662. // previous state in case we get here?
  663. // No real reason to roll back. There is no actually data loss or confusion.
  664. }
  665. if ( wNeverUsed != dwUsage )
  666. {
  667. pCats->EnableService();
  668. }
  669. // The Advanced dialog takes care of setting custom settings
  670. // We don't want to set them here because dwIndexPos and dwQueryPos
  671. // have not been refreshed from registry since Adv dlg wrote them.
  672. if ( dwUsage != wCustom)
  673. {
  674. sc = pCats->SaveServiceUsage(dwUsage, dwIndexPos, dwQueryPos);
  675. }
  676. // Not much to do if SaveServiceUsage fails. Just move on.
  677. EndDialog( hwndDlg, TRUE );
  678. break;
  679. }
  680. case IDCANCEL:
  681. ciaDebugOut(( DEB_TRACE, "WksTunePerfDlg (WM_COMMAND, IDCANCEL) - 0x%x\n",
  682. GetWindowLongPtr( hwndDlg, DWLP_USER ) ));
  683. EndDialog( hwndDlg, FALSE );
  684. }
  685. } // wm_command
  686. } // message
  687. return fRet;
  688. }
  689. INT_PTR APIENTRY SrvTunePerfDlg( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam )
  690. {
  691. BOOL fRet = FALSE;
  692. static DWORD dwUsage, dwOldUsage, dwIndexPos, dwQueryPos;
  693. switch (message)
  694. {
  695. case WM_HELP:
  696. {
  697. HELPINFO *phi = (HELPINFO *) lParam;
  698. ciaDebugOut(( DEB_ITRACE, "SrvTunePerfDlg WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  699. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  700. phi->iCtrlId, phi->dwContextId ));
  701. if ( HELPINFO_WINDOW == phi->iContextType )
  702. {
  703. switch ( phi->iCtrlId )
  704. {
  705. case IDDI_STATIC:
  706. break;
  707. default :
  708. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  709. break;
  710. }
  711. }
  712. break;
  713. }
  714. case WM_CONTEXTMENU:
  715. {
  716. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  717. break;
  718. }
  719. case WM_INITDIALOG:
  720. {
  721. ciaDebugOut(( DEB_ITRACE, "SrvTunePerfDlg (WM_INITDIALOG) - 0x%x\n", lParam ));
  722. SetWindowLongPtr( hwndDlg, DWLP_USER, (LONG_PTR)lParam );
  723. // Initialize the dialog.
  724. CCatalogs *pCats = (CCatalogs *)lParam;
  725. pCats->GetSavedServiceUsage(dwUsage, dwIndexPos, dwQueryPos);
  726. dwOldUsage = dwUsage;
  727. switch (dwUsage)
  728. {
  729. case wDedicatedServer:
  730. SendDlgItemMessage( hwndDlg, IDDI_DEDICATED, BM_SETCHECK, BST_CHECKED, 0 );
  731. pCats->SaveServicePerformanceSettings(wHighPos, wHighPos);
  732. break;
  733. case wUsedOften:
  734. SendDlgItemMessage( hwndDlg, IDDI_USEDOFTEN, BM_SETCHECK, BST_CHECKED, 0 );
  735. pCats->SaveServicePerformanceSettings(wHighPos, wMidPos);
  736. break;
  737. case wUsedOccasionally:
  738. SendDlgItemMessage( hwndDlg, IDDI_USEDOCCASIONALLY, BM_SETCHECK, BST_CHECKED, 0 );
  739. pCats->SaveServicePerformanceSettings(wMidPos, wLowPos);
  740. break;
  741. case wCustom:
  742. SendDlgItemMessage( hwndDlg, IDDI_CUSTOMIZE, BM_SETCHECK, BST_CHECKED, 0 );
  743. pCats->SaveServicePerformanceSettings((WORD)dwIndexPos, (WORD)dwQueryPos);
  744. break;
  745. case wNeverUsed:
  746. SendDlgItemMessage( hwndDlg, IDDI_NEVERUSED, BM_SETCHECK, BST_CHECKED, 0 );
  747. break;
  748. default:
  749. Win4Assert(!"How did we get here?");
  750. break;
  751. }
  752. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), dwUsage == wCustom);
  753. fRet = TRUE;
  754. }
  755. break;
  756. case WM_COMMAND:
  757. {
  758. CCatalogs *pCats = (CCatalogs *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  759. switch ( LOWORD( wParam ) )
  760. {
  761. case IDDI_DEDICATED:
  762. if (BN_CLICKED == HIWORD(wParam))
  763. {
  764. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), FALSE);
  765. pCats->SaveServicePerformanceSettings(wHighPos, wHighPos);
  766. dwUsage = wDedicatedServer;
  767. }
  768. break;
  769. case IDDI_USEDOFTEN:
  770. if (BN_CLICKED == HIWORD(wParam))
  771. {
  772. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), FALSE);
  773. pCats->SaveServicePerformanceSettings(wHighPos, wMidPos);
  774. dwUsage = wUsedOften;
  775. }
  776. break;
  777. case IDDI_USEDOCCASIONALLY:
  778. if (BN_CLICKED == HIWORD(wParam))
  779. {
  780. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), FALSE);
  781. pCats->SaveServicePerformanceSettings(wMidPos, wLowPos);
  782. dwUsage = wUsedOccasionally;
  783. }
  784. break;
  785. case IDDI_NEVERUSED:
  786. if (BN_CLICKED == HIWORD(wParam))
  787. {
  788. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), FALSE);
  789. dwUsage = wNeverUsed;
  790. }
  791. break;
  792. case IDDI_CUSTOMIZE:
  793. if (BN_CLICKED == HIWORD(wParam))
  794. {
  795. EnableWindow(GetDlgItem(hwndDlg, IDDI_ADVANCED), TRUE);
  796. pCats->SaveServicePerformanceSettings((WORD)dwIndexPos, (WORD)dwQueryPos);
  797. dwUsage = wCustom;
  798. }
  799. break;
  800. case IDDI_ADVANCED:
  801. {
  802. pCats->SetServiceUsage(dwUsage);
  803. DialogBoxParam( ghInstance, // Application instance
  804. MAKEINTRESOURCE( IDD_ADVANCED_INFO ), // Dialog box
  805. hwndDlg, // main frame window
  806. AdvPerfTuneDlg, // Dialog box function
  807. (LPARAM)pCats ); // User parameter
  808. break;
  809. }
  810. case IDOK:
  811. {
  812. fRet = TRUE;
  813. // only pop up the messagebox if old dwUsage != wNeverUsed
  814. if (wNeverUsed == dwUsage)
  815. {
  816. if ( wNeverUsed != dwOldUsage )
  817. {
  818. int iResult;
  819. iResult = MessageBox( GetFocus(), STRINGRESOURCE( srCMShutdownService ),
  820. STRINGRESOURCE( srCMShutdownServiceTitle ),
  821. MB_YESNO | /* MB_HELP | */
  822. MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL );
  823. switch ( iResult )
  824. {
  825. case IDYES:
  826. {
  827. SCODE sc = pCats->DisableService();
  828. if (FAILED(sc))
  829. {
  830. MessageBox( GetFocus(), STRINGRESOURCE( srCMCantShutdownService ),
  831. STRINGRESOURCE( srCMShutdownServiceTitle ),
  832. MB_OK | /* MB_HELP | */
  833. MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL );
  834. }
  835. else
  836. {
  837. pCats->SaveServiceUsage(dwUsage, dwIndexPos, dwQueryPos);
  838. }
  839. // Fall through and close the dialog.
  840. }
  841. case IDNO:
  842. default:
  843. // Do nothing. Just close the dialog
  844. EndDialog( hwndDlg, TRUE );
  845. break;
  846. }
  847. break;
  848. }
  849. else
  850. {
  851. EndDialog( hwndDlg, FALSE );
  852. break;
  853. }
  854. }
  855. SCODE sc = pCats->TuneServicePerformance();
  856. if (FAILED(sc))
  857. {
  858. // Inform user that performance tuning didn't go through.
  859. // The only reason this happens is if the registry params couldn't be set, which
  860. // should be a rare occurrence.
  861. MessageBox( GetFocus(), STRINGRESOURCE( srCMCantSaveSettings ),
  862. STRINGRESOURCE( srCMTunePerformance ),
  863. MB_OK | /* MB_HELP | */
  864. MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL );
  865. // About the only reason I can think of that could cause registry
  866. // save to fail is if the registry was messed up. In that case, does it
  867. // matter if we only saved part of what we wanted to save? Or should we be
  868. // careful enough to remember the old settings and restore the registry to
  869. // previous state in case we get here?
  870. // No real reason to roll back. There is no actually data loss or confusion.
  871. //
  872. }
  873. if ( wNeverUsed != dwUsage )
  874. {
  875. pCats->EnableService();
  876. }
  877. // The Advanced dialog takes care of setting custom settings
  878. // We don't want to set them here because dwIndexPos and dwQueryPos
  879. // have not been refreshed from registry since Adv dlg wrote them.
  880. if ( dwUsage != wCustom)
  881. {
  882. sc = pCats->SaveServiceUsage(dwUsage, dwIndexPos, dwQueryPos);
  883. }
  884. // Not much to do if SaveServiceUsage fails. Just move on.
  885. EndDialog( hwndDlg, TRUE );
  886. break;
  887. }
  888. case IDCANCEL:
  889. ciaDebugOut(( DEB_TRACE, "SrvTunePerfDlg (WM_COMMAND, IDCANCEL) - 0x%x\n",
  890. GetWindowLongPtr( hwndDlg, DWLP_USER ) ));
  891. EndDialog( hwndDlg, FALSE );
  892. }
  893. } // wm_command
  894. } // message
  895. return fRet;
  896. }
  897. INT_PTR APIENTRY AdvPerfTuneDlg( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam )
  898. {
  899. BOOL fRet = FALSE;
  900. switch (message)
  901. {
  902. case WM_HELP:
  903. {
  904. HELPINFO *phi = (HELPINFO *) lParam;
  905. ciaDebugOut(( DEB_ITRACE, "AdvPerfTuneDlg WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  906. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  907. phi->iCtrlId, phi->dwContextId ));
  908. if ( HELPINFO_WINDOW == phi->iContextType )
  909. {
  910. switch ( phi->iCtrlId )
  911. {
  912. case IDDI_STATIC:
  913. case IDDI_LOWLOAD:
  914. case IDDI_HIGHLOAD:
  915. case IDDI_LAZY:
  916. case IDDI_INSTANT:
  917. break;
  918. default :
  919. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  920. break;
  921. }
  922. }
  923. break;
  924. }
  925. case WM_CONTEXTMENU:
  926. {
  927. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  928. break;
  929. }
  930. case WM_INITDIALOG:
  931. {
  932. // Prepare the controls
  933. SendDlgItemMessage(hwndDlg, IDDI_SLIDER_INDEXING, TBM_SETRANGE, TRUE, MAKELONG(wLowPos, wHighPos));
  934. SendDlgItemMessage(hwndDlg, IDDI_SLIDER_QUERYING, TBM_SETRANGE, TRUE, MAKELONG(wLowPos, wHighPos));
  935. // Set the dialog based on lParam
  936. DWORD dwUsage, dwIndexingPos, dwQueryingPos;
  937. CCatalogs *pCats = (CCatalogs *)lParam;
  938. pCats->GetSavedServiceUsage(dwUsage, dwIndexingPos, dwQueryingPos);
  939. SetSliderPositions(hwndDlg, (WORD)dwIndexingPos, (WORD)dwQueryingPos);
  940. SetWindowLongPtr( hwndDlg, DWLP_USER, (LONG_PTR)lParam );
  941. fRet = TRUE;
  942. }
  943. break;
  944. case WM_COMMAND:
  945. switch (LOWORD(wParam))
  946. {
  947. case IDOK:
  948. {
  949. fRet = TRUE;
  950. WORD wIdxPos = (WORD)SendDlgItemMessage(hwndDlg, IDDI_SLIDER_INDEXING, TBM_GETPOS, 0, 0);
  951. WORD wQryPos = (WORD)SendDlgItemMessage(hwndDlg, IDDI_SLIDER_QUERYING, TBM_GETPOS, 0, 0);
  952. CCatalogs *pCats = (CCatalogs *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  953. pCats->SaveServicePerformanceSettings(wIdxPos, wQryPos);
  954. pCats->SaveServiceUsage(wCustom, wIdxPos, wQryPos);
  955. EndDialog( hwndDlg, TRUE );
  956. break;
  957. }
  958. case IDCANCEL:
  959. ciaDebugOut(( DEB_TRACE, "AdvPerfTuneDlg (WM_COMMAND, IDCANCEL) - 0x%x\n",
  960. GetWindowLongPtr( hwndDlg, DWLP_USER ) ));
  961. EndDialog( hwndDlg, FALSE );
  962. }
  963. }
  964. return fRet;
  965. }
  966. void SetSliderPositions(HWND hwndDlg, WORD wIndexingPos, WORD wQueryingPos)
  967. {
  968. SendDlgItemMessage(hwndDlg, IDDI_SLIDER_INDEXING, TBM_SETPOS, TRUE, (LONG)wIndexingPos);
  969. SendDlgItemMessage(hwndDlg, IDDI_SLIDER_QUERYING, TBM_SETPOS, TRUE, (LONG)wQueryingPos);
  970. }
  971. INT_PTR APIENTRY AddCatalogDlg( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam )
  972. {
  973. BOOL fRet = FALSE;
  974. switch ( message )
  975. {
  976. case WM_HELP:
  977. {
  978. HELPINFO *phi = (HELPINFO *) lParam;
  979. ciaDebugOut(( DEB_ITRACE, "AddCatalogDlg WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  980. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  981. phi->iCtrlId, phi->dwContextId ));
  982. if ( HELPINFO_WINDOW == phi->iContextType )
  983. {
  984. switch ( phi->iCtrlId )
  985. {
  986. case IDDI_STATIC:
  987. break;
  988. default :
  989. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  990. break;
  991. }
  992. }
  993. break;
  994. }
  995. case WM_CONTEXTMENU:
  996. {
  997. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  998. break;
  999. }
  1000. case WM_INITDIALOG:
  1001. ciaDebugOut(( DEB_ITRACE, "AddCatalogDlg (WM_INITDIALOG) - 0x%x\n", lParam ));
  1002. SetWindowLongPtr( hwndDlg, DWLP_USER, lParam );
  1003. fRet = TRUE;
  1004. break;
  1005. case WM_COMMAND:
  1006. switch ( LOWORD( wParam ) )
  1007. {
  1008. case IDDI_CATNAME2:
  1009. case IDDI_CATPATH:
  1010. if ( EN_CHANGE == HIWORD(wParam) )
  1011. {
  1012. //
  1013. // If both fields have data, then enable OK button.
  1014. //
  1015. WCHAR wcsTest[10];
  1016. if ( 0 == GetDlgItemText( hwndDlg, IDDI_CATNAME2, wcsTest, sizeof(wcsTest) / sizeof(WCHAR) ) ||
  1017. 0 == GetDlgItemText( hwndDlg, IDDI_CATPATH, wcsTest, sizeof(wcsTest) / sizeof(WCHAR) ) )
  1018. {
  1019. EnableWindow( GetDlgItem( hwndDlg, IDOK ), FALSE );
  1020. }
  1021. else
  1022. {
  1023. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  1024. }
  1025. }
  1026. fRet = TRUE;
  1027. break;
  1028. case IDDI_BROWSE:
  1029. {
  1030. if ( BN_CLICKED == HIWORD( wParam ) )
  1031. {
  1032. // Disable the button so users can't launch multiple dialogs simultaneously
  1033. EnableWindow(GetDlgItem( hwndDlg, IDDI_BROWSE ), FALSE);
  1034. XArray<WCHAR> xawcPath;
  1035. if ( GetDlgItemXArrayText( hwndDlg, IDDI_CATPATH, xawcPath ) )
  1036. {
  1037. if ( xawcPath.IsNull() )
  1038. {
  1039. xawcPath.Init( 2 );
  1040. xawcPath[0] = L'\\';
  1041. xawcPath[1] = 0;
  1042. }
  1043. WCHAR awc[MAX_PATH];
  1044. if ( BrowseForDirectory( GetParent(hwndDlg), // Parent
  1045. xawcPath.GetPointer(), // Current path
  1046. awc, // New path goes here...
  1047. MAX_PATH,
  1048. 0, // Title
  1049. TRUE ) ) // Remove trailing slash
  1050. {
  1051. SetWindowText( GetDlgItem( hwndDlg, IDDI_CATPATH ), awc );
  1052. }
  1053. // Re-enable the button
  1054. EnableWindow(GetDlgItem( hwndDlg, IDDI_BROWSE ), TRUE);
  1055. // Set focus on dialog so user can continue working...
  1056. SetFocus(hwndDlg);
  1057. }
  1058. }
  1059. fRet = TRUE;
  1060. break;
  1061. }
  1062. case IDOK:
  1063. {
  1064. XArray<WCHAR> xawcCatName;
  1065. XArray<WCHAR> xawcPath;
  1066. if ( GetDlgItemXArrayText( hwndDlg, IDDI_CATNAME2, xawcCatName ) &&
  1067. GetDlgItemXArrayText( hwndDlg, IDDI_CATPATH, xawcPath ) )
  1068. {
  1069. CCatalogs * pCats= (CCatalogs *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1070. TRY
  1071. {
  1072. SCODE sc = pCats->AddCatalog( xawcCatName.GetPointer(),
  1073. xawcPath.GetPointer() );
  1074. if (FAILED(sc))
  1075. {
  1076. MessageBox(hwndDlg,
  1077. STRINGRESOURCE( srNCError ),
  1078. STRINGRESOURCE( srNCErrorT ),
  1079. MB_ICONHAND);
  1080. }
  1081. else
  1082. {
  1083. MessageBox( hwndDlg,
  1084. STRINGRESOURCE( srNC ),
  1085. STRINGRESOURCE( srNCT ),
  1086. MB_OK | MB_ICONWARNING );
  1087. EndDialog( hwndDlg, TRUE );
  1088. }
  1089. }
  1090. CATCH( CException, e )
  1091. {
  1092. WCHAR * pBuf = 0;
  1093. SCODE sc = GetOleError(e);
  1094. //
  1095. // Convert Win32 errors back from HRESULT
  1096. //
  1097. if ( (sc & (FACILITY_WIN32 << 16)) == (FACILITY_WIN32 << 16) )
  1098. sc &= ~( 0x80000000 | (FACILITY_WIN32 << 16) );
  1099. if ( !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE |
  1100. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  1101. GetModuleHandle(L"query.dll"),
  1102. sc,
  1103. GetSystemDefaultLCID(),
  1104. (WCHAR *)&pBuf,
  1105. 0,
  1106. 0 ) &&
  1107. !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE |
  1108. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  1109. GetModuleHandle(L"kernel32.dll"),
  1110. sc,
  1111. GetSystemDefaultLCID(),
  1112. (WCHAR *)&pBuf,
  1113. 0,
  1114. 0 ) )
  1115. {
  1116. StringResource srGenericError = { MSG_GENERIC_ERROR };
  1117. srGenericError.Init( ghInstance );
  1118. unsigned cc = wcslen( STRINGRESOURCE(srGenericError) ) +
  1119. 11; // 0xnnnnnnnn + null
  1120. XArray<WCHAR> xawcText( cc );
  1121. wsprintf( xawcText.Get(),
  1122. STRINGRESOURCE(srGenericError),
  1123. GetOleError( e ) );
  1124. MessageBox( hwndDlg,
  1125. xawcText.Get(),
  1126. STRINGRESOURCE( srIndexServerCmpManage ),
  1127. MB_OK | MB_ICONERROR );
  1128. }
  1129. else
  1130. {
  1131. MessageBox( hwndDlg,
  1132. pBuf,
  1133. STRINGRESOURCE( srIndexServerCmpManage ),
  1134. MB_OK | MB_ICONERROR );
  1135. LocalFree( pBuf );
  1136. }
  1137. }
  1138. END_CATCH
  1139. }
  1140. fRet = TRUE;
  1141. break;
  1142. }
  1143. case IDCANCEL:
  1144. ciaDebugOut(( DEB_TRACE, "AddCatalogDlg (WM_COMMAND, IDCANCEL) - 0x%x\n",
  1145. GetWindowLongPtr( hwndDlg, DWLP_USER ) ));
  1146. EndDialog( hwndDlg, FALSE );
  1147. }
  1148. }
  1149. return fRet;
  1150. }
  1151. BOOL GetDlgItemXArrayText( HWND hwndDlg, USHORT idCtrl, XArray<WCHAR> & xawcText )
  1152. {
  1153. Win4Assert( 0 == xawcText.Count() );
  1154. xawcText.Init( 5 ); // Start with some default size.
  1155. while ( TRUE )
  1156. {
  1157. unsigned cc = GetDlgItemText( hwndDlg, idCtrl, xawcText.GetPointer(), xawcText.Count() );
  1158. if ( 0 == cc )
  1159. {
  1160. xawcText.Free();
  1161. break;
  1162. }
  1163. if ( cc != (xawcText.Count() - 1) )
  1164. break;
  1165. cc = xawcText.Count() * 2;
  1166. xawcText.Free();
  1167. xawcText.Init( cc );
  1168. }
  1169. if ( !xawcText.IsNull() && 0 == xawcText[0] )
  1170. xawcText.Free();
  1171. return TRUE;
  1172. }
  1173. // Used to initialize the browse directory dialog with the start root
  1174. int InitStartDir( HWND hwnd,
  1175. UINT uMsg,
  1176. LPARAM lParam,
  1177. LPARAM lpData)
  1178. {
  1179. // we just capture Init Message
  1180. if (BFFM_INITIALIZED == uMsg)
  1181. {
  1182. // we expect lpData to be our start path
  1183. SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, lpData);
  1184. }
  1185. return 0;
  1186. }
  1187. //----------------------------------------------------------------------------
  1188. // Procedure BrowseForDirectory
  1189. //
  1190. // Purpose Displays a dialog that lets the user choose a directory
  1191. // name, either local or UNC.
  1192. //
  1193. // Parameters hwndParent Parent window for the dialog
  1194. // pszInitialDir Directory to use as the default
  1195. // pszBuf Where to store the answer
  1196. // chBuf Number of characters in this buffer
  1197. // szDialogTitle Title for the dialog
  1198. //
  1199. // Returns nonzero if successful, zero if not. If successful, pszBuf
  1200. // will be filled with the full pathname of the chosen directory.
  1201. //
  1202. // History 10/06/95 KenSh Created
  1203. // 10/09/95 KenSh Use lCustData member instead of global
  1204. // 10/28/98 KrishnaN Using Shell's folder browser
  1205. //
  1206. //----------------------------------------------------------------------------
  1207. BOOL BrowseForDirectory(
  1208. HWND hwndParent,
  1209. LPCTSTR pszInitialDir,
  1210. LPTSTR pszBuf,
  1211. int cchBuf,
  1212. LPCTSTR pszDialogTitle,
  1213. BOOL bRemoveTrailingBackslash )
  1214. {
  1215. // Get the necessary interfaces at the beginning. If we fail, we can return
  1216. // immediately.
  1217. // Caller is responsible for cleaning up the pidl returned by the shell
  1218. // NOTE: Docs don't explicitly mention if SHGetMalloc refcounts it. It is
  1219. // COMmon sense that it does, and NT sources supports it. So Release it after use.
  1220. XInterface<IMalloc> xMalloc;
  1221. SCODE sc = SHGetMalloc(xMalloc.GetPPointer());
  1222. if (FAILED(sc))
  1223. {
  1224. // We need to cleaup pidl, but can't get a ptr to the shell task
  1225. // allocator. What else can we do besides displaying an error?
  1226. MessageBox(hwndParent, STRINGRESOURCE( srCMUnexpectedError ),
  1227. STRINGRESOURCE( srIndexServerCmpManage ), MB_ICONHAND);
  1228. return FALSE;
  1229. }
  1230. BROWSEINFO bi;
  1231. RtlZeroMemory(&bi, sizeof BROWSEINFO);
  1232. bi.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS;
  1233. TCHAR szInitialDir[MAX_PATH];
  1234. pszBuf[0] = L'\0';
  1235. // Prepare the initial directory... add a backslash if it's
  1236. // a 2-character path
  1237. wcsncpy( szInitialDir, pszInitialDir, sizeof szInitialDir / sizeof TCHAR );
  1238. szInitialDir[ (sizeof szInitialDir / sizeof TCHAR) - 1 ] = 0;
  1239. if( !szInitialDir[2] )
  1240. {
  1241. szInitialDir[2] = L'\\';
  1242. szInitialDir[3] = L'\0';
  1243. }
  1244. WCHAR awcTitle[200];
  1245. if( pszDialogTitle )
  1246. bi.lpszTitle = pszDialogTitle;
  1247. else
  1248. {
  1249. LoadString( ghInstance,
  1250. MSG_DIRECTORY_TITLE,
  1251. awcTitle,
  1252. sizeof awcTitle / sizeof WCHAR );
  1253. bi.lpszTitle = awcTitle;
  1254. }
  1255. bi.hwndOwner = hwndParent;
  1256. Win4Assert(cchBuf >= MAX_PATH);
  1257. bi.pszDisplayName = pszBuf;
  1258. if (pszInitialDir)
  1259. {
  1260. // engage these params only if we have an initial directory
  1261. bi.lpfn = InitStartDir;
  1262. bi.lParam = (LPARAM)szInitialDir;
  1263. }
  1264. LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
  1265. BOOL fOk = (BOOL)(0 != pidl);
  1266. fOk = fOk && SHGetPathFromIDList(pidl, pszBuf);
  1267. xMalloc->Free((void *)pidl);
  1268. return fOk;
  1269. }