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.

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