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.

976 lines
26 KiB

  1. /*++
  2. Copyright (c) 1990-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. find.c
  5. Abstract:
  6. This module implements the Win32 find dialog.
  7. Revision History:
  8. --*/
  9. // precompiled headers
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. #include "find.h"
  13. #include "util.h"
  14. #ifdef UNICODE
  15. ////////////////////////////////////////////////////////////////////////////
  16. //
  17. // FindTextA
  18. //
  19. // ANSI entry point for FindText when this code is built UNICODE.
  20. //
  21. ////////////////////////////////////////////////////////////////////////////
  22. HWND WINAPI FindTextA(
  23. LPFINDREPLACEA pFRA)
  24. {
  25. return (CreateFindReplaceDlg((LPFINDREPLACEW)pFRA, DLGT_FIND, COMDLG_ANSI));
  26. }
  27. #else
  28. ////////////////////////////////////////////////////////////////////////////
  29. //
  30. // FindTextW
  31. //
  32. // Stub UNICODE function for FindText when this code is built ANSI.
  33. //
  34. ////////////////////////////////////////////////////////////////////////////
  35. HWND WINAPI FindTextW(
  36. LPFINDREPLACEW pFRW)
  37. {
  38. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  39. return (FALSE);
  40. }
  41. #endif
  42. ////////////////////////////////////////////////////////////////////////////
  43. //
  44. // FindText
  45. //
  46. // The FindText function creates a system-defined modeless dialog box
  47. // that enables the user to find text within a document.
  48. //
  49. ////////////////////////////////////////////////////////////////////////////
  50. HWND WINAPI FindText(
  51. LPFINDREPLACE pFR)
  52. {
  53. return ( CreateFindReplaceDlg(pFR, DLGT_FIND, COMDLG_WIDE) );
  54. }
  55. #ifdef UNICODE
  56. ////////////////////////////////////////////////////////////////////////////
  57. //
  58. // ReplaceTextA
  59. //
  60. // ANSI entry point for ReplaceText when this code is built UNICODE.
  61. //
  62. ////////////////////////////////////////////////////////////////////////////
  63. HWND WINAPI ReplaceTextA(
  64. LPFINDREPLACEA pFRA)
  65. {
  66. return (CreateFindReplaceDlg((LPFINDREPLACEW)pFRA, DLGT_REPLACE, COMDLG_ANSI));
  67. }
  68. #else
  69. ////////////////////////////////////////////////////////////////////////////
  70. //
  71. // ReplaceTextW
  72. //
  73. // Stub UNICODE function for ReplaceText when this code is built ANSI.
  74. //
  75. ////////////////////////////////////////////////////////////////////////////
  76. HWND WINAPI ReplaceTextW(
  77. LPFINDREPLACEW pFRW)
  78. {
  79. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  80. return (FALSE);
  81. }
  82. #endif
  83. ////////////////////////////////////////////////////////////////////////////
  84. //
  85. // ReplaceText
  86. //
  87. // The ReplaceText function creates a system-defined modeless dialog box
  88. // that enables the user to find and replace text within a document.
  89. //
  90. ////////////////////////////////////////////////////////////////////////////
  91. HWND WINAPI ReplaceText(
  92. LPFINDREPLACE pFR)
  93. {
  94. return ( CreateFindReplaceDlg(pFR, DLGT_REPLACE, COMDLG_WIDE) );
  95. }
  96. ////////////////////////////////////////////////////////////////////////////
  97. //
  98. // CreateFindReplaceDlg
  99. //
  100. // Creates FindText modeless dialog.
  101. //
  102. // pFR - ptr to FINDREPLACE structure set up by user
  103. // DlgType - type of dialog to create (DLGT_FIND, DLGT_REPLACE)
  104. // ApiType - type of FINDREPLACE ptr (COMDLG_ANSI or COMDLG_WIDE)
  105. //
  106. // Returns success => HANDLE to created dlg
  107. // failure => HNULL = ((HANDLE) 0)
  108. //
  109. ////////////////////////////////////////////////////////////////////////////
  110. HWND CreateFindReplaceDlg(
  111. LPFINDREPLACE pFR,
  112. UINT DlgType,
  113. UINT ApiType)
  114. {
  115. HWND hWndDlg; // handle to created modeless dialog
  116. HANDLE hDlgTemplate; // handle to loaded dialog resource
  117. LPCDLGTEMPLATE lpDlgTemplate; // pointer to loaded resource block
  118. #ifdef UNICODE
  119. UINT uiWOWFlag = 0;
  120. #endif
  121. if (!pFR)
  122. {
  123. StoreExtendedError(CDERR_INITIALIZATION);
  124. return (FALSE);
  125. }
  126. if (!SetupOK(pFR, DlgType, ApiType))
  127. {
  128. return (HNULL);
  129. }
  130. if (!(hDlgTemplate = GetDlgTemplate(pFR, DlgType, ApiType)))
  131. {
  132. return (FALSE);
  133. }
  134. if (lpDlgTemplate = (LPCDLGTEMPLATE)LockResource(hDlgTemplate))
  135. {
  136. PFINDREPLACEINFO pFRI;
  137. if (pFRI = (PFINDREPLACEINFO)LocalAlloc(LPTR, sizeof(FINDREPLACEINFO)))
  138. {
  139. //
  140. // CLEAR extended error on new instantiation.
  141. //
  142. StoreExtendedError(0);
  143. if (pFR->Flags & FR_ENABLEHOOK)
  144. {
  145. glpfnFindHook = GETHOOKFN(pFR);
  146. }
  147. pFRI->pFR = pFR;
  148. pFRI->ApiType = ApiType;
  149. pFRI->DlgType = DlgType;
  150. #ifdef UNICODE
  151. if (IS16BITWOWAPP(pFR))
  152. {
  153. uiWOWFlag = SCDLG_16BIT;
  154. }
  155. hWndDlg = CreateDialogIndirectParamAorW( g_hinst,
  156. lpDlgTemplate,
  157. pFR->hwndOwner,
  158. FindReplaceDlgProc,
  159. (LPARAM)pFRI,
  160. uiWOWFlag );
  161. #else
  162. hWndDlg = CreateDialogIndirectParam( g_hinst,
  163. lpDlgTemplate,
  164. pFR->hwndOwner,
  165. FindReplaceDlgProc,
  166. (LPARAM)pFRI );
  167. #endif
  168. if (!hWndDlg)
  169. {
  170. glpfnFindHook = 0;
  171. LocalFree(pFRI);
  172. }
  173. }
  174. else
  175. {
  176. StoreExtendedError(CDERR_MEMALLOCFAILURE);
  177. return (NULL);
  178. }
  179. }
  180. else
  181. {
  182. StoreExtendedError(CDERR_LOCKRESFAILURE);
  183. return (HNULL);
  184. }
  185. return (hWndDlg);
  186. }
  187. ////////////////////////////////////////////////////////////////////////////
  188. //
  189. // SetupOK
  190. //
  191. // Checks setup for unmet preconditions.
  192. //
  193. // pFR ptr to FINDREPLACE structure
  194. // DlgType dialog type (either FIND or REPLACE)
  195. // ApiType findreplace type (either COMDLG_ANSI or COMDLG_UNICODE)
  196. //
  197. // Returns TRUE - success
  198. // FALSE - failure
  199. //
  200. ////////////////////////////////////////////////////////////////////////////
  201. BOOL SetupOK(
  202. LPFINDREPLACE pFR,
  203. UINT DlgType,
  204. UINT ApiType)
  205. {
  206. LANGID LangID = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
  207. //
  208. // Sanity
  209. //
  210. if (!pFR)
  211. {
  212. return (FALSE);
  213. }
  214. if (pFR->lStructSize != sizeof(FINDREPLACE))
  215. {
  216. StoreExtendedError(CDERR_STRUCTSIZE);
  217. return (FALSE);
  218. }
  219. //
  220. // Verify window handle and text pointers.
  221. //
  222. if (!IsWindow(pFR->hwndOwner))
  223. {
  224. StoreExtendedError(CDERR_DIALOGFAILURE);
  225. return (FALSE);
  226. }
  227. if (!pFR->lpstrFindWhat ||
  228. ((DlgType == DLGT_REPLACE) && !pFR->lpstrReplaceWith) ||
  229. !pFR->wFindWhatLen)
  230. {
  231. StoreExtendedError(FRERR_BUFFERLENGTHZERO);
  232. return (FALSE);
  233. }
  234. //
  235. // Verify lpfnHook has a ptr if ENABLED.
  236. //
  237. if (pFR->Flags & FR_ENABLEHOOK)
  238. {
  239. if (!pFR->lpfnHook)
  240. {
  241. StoreExtendedError(CDERR_NOHOOK);
  242. return (FALSE);
  243. }
  244. }
  245. else
  246. {
  247. pFR->lpfnHook = 0;
  248. }
  249. //
  250. // Get LangID
  251. //
  252. if (
  253. !(pFR->Flags & FR_ENABLETEMPLATE) &&
  254. !(pFR->Flags & FR_ENABLETEMPLATEHANDLE) )
  255. {
  256. LangID = GetDialogLanguage(pFR->hwndOwner, NULL);
  257. }
  258. //
  259. // Warning! Warning! Warning!
  260. //
  261. // We have to set g_tlsLangID before any call for CDLoadString
  262. //
  263. TlsSetValue(g_tlsLangID, (LPVOID) LangID);
  264. //
  265. // Load "CLOSE" text for Replace.
  266. //
  267. if ((DlgType == DLGT_REPLACE) &&
  268. !CDLoadString(g_hinst, iszClose, (LPTSTR)szClose, CCHCLOSE))
  269. {
  270. StoreExtendedError(CDERR_LOADSTRFAILURE);
  271. return (FALSE);
  272. }
  273. //
  274. // Setup unique msg# for talking to hwndOwner.
  275. //
  276. #ifdef UNICODE
  277. if (ApiType == COMDLG_ANSI)
  278. {
  279. if (!(wFRMessage = RegisterWindowMessageA((LPCSTR)FINDMSGSTRINGA)))
  280. {
  281. StoreExtendedError(CDERR_REGISTERMSGFAIL);
  282. return (FALSE);
  283. }
  284. }
  285. else
  286. #endif
  287. {
  288. if (!(wFRMessage = RegisterWindowMessage((LPCTSTR)FINDMSGSTRING)))
  289. {
  290. StoreExtendedError(CDERR_REGISTERMSGFAIL);
  291. return (FALSE);
  292. }
  293. }
  294. return (TRUE);
  295. }
  296. ////////////////////////////////////////////////////////////////////////////
  297. //
  298. // GetDlgTemplate
  299. //
  300. // Finds and loads the dialog template.
  301. //
  302. // pFR ptr to FINDREPLACE structure
  303. // ApiType findreplace type (either COMDLG_ANSI or COMDLG_UNICODE)
  304. //
  305. // Returns handle to dialog template - success
  306. // HNULL = ((HANDLE) 0) - failure
  307. //
  308. ////////////////////////////////////////////////////////////////////////////
  309. HANDLE GetDlgTemplate(
  310. LPFINDREPLACE pFR,
  311. UINT DlgType,
  312. UINT ApiType)
  313. {
  314. HANDLE hRes; // handle of res. block with dialog
  315. HANDLE hDlgTemplate; // handle to loaded dialog resource
  316. LANGID LangID;
  317. if (pFR->Flags & FR_ENABLETEMPLATE)
  318. {
  319. //
  320. // Find/Load TEMP NAME and INSTANCE from pFR.
  321. //
  322. #ifdef UNICODE
  323. if (ApiType == COMDLG_ANSI)
  324. {
  325. hRes = FindResourceA( (HMODULE)pFR->hInstance,
  326. (LPCSTR)pFR->lpTemplateName,
  327. (LPCSTR)RT_DIALOG );
  328. }
  329. else
  330. #endif
  331. {
  332. hRes = FindResource( pFR->hInstance,
  333. (LPCTSTR)pFR->lpTemplateName,
  334. (LPCTSTR)RT_DIALOG );
  335. }
  336. if (!hRes)
  337. {
  338. StoreExtendedError(CDERR_FINDRESFAILURE);
  339. return (HNULL);
  340. }
  341. if (!(hDlgTemplate = LoadResource(pFR->hInstance, hRes)))
  342. {
  343. StoreExtendedError(CDERR_LOADRESFAILURE);
  344. return (HNULL);
  345. }
  346. }
  347. else if (pFR->Flags & FR_ENABLETEMPLATEHANDLE)
  348. {
  349. //
  350. // Get whole PRELOADED resource handle from user.
  351. //
  352. if (!(hDlgTemplate = pFR->hInstance))
  353. {
  354. StoreExtendedError(CDERR_NOHINSTANCE);
  355. return (HNULL);
  356. }
  357. }
  358. else
  359. {
  360. //
  361. // Get STANDARD dialog from DLL instance block.
  362. //
  363. LangID = (LANGID) TlsGetValue(g_tlsLangID);
  364. if (DlgType == DLGT_FIND)
  365. {
  366. hRes = FindResourceExFallback( g_hinst,
  367. RT_DIALOG,
  368. MAKEINTRESOURCE(FINDDLGORD),
  369. LangID);
  370. }
  371. else
  372. {
  373. hRes = FindResourceExFallback( g_hinst,
  374. RT_DIALOG,
  375. MAKEINTRESOURCE(REPLACEDLGORD),
  376. LangID);
  377. }
  378. //
  379. // !!!!! definitely ORD here?
  380. //
  381. if (!hRes)
  382. {
  383. StoreExtendedError(CDERR_FINDRESFAILURE);
  384. return (HNULL);
  385. }
  386. if (!(hDlgTemplate = LoadResource(g_hinst, hRes)))
  387. {
  388. StoreExtendedError(CDERR_LOADRESFAILURE);
  389. return (HNULL);
  390. }
  391. }
  392. return (hDlgTemplate);
  393. }
  394. ////////////////////////////////////////////////////////////////////////////
  395. //
  396. // FindReplaceDlgProc
  397. //
  398. // Handles messages to FindText/ReplaceText dialogs.
  399. //
  400. // hDlg - handle to dialog
  401. // wMsg - window message
  402. // wParam - w parameter of message
  403. // lParam - l parameter of message
  404. //
  405. // Note: lparam contains ptr to FINDREPLACEINITPROC upon
  406. // initialization from CreateDialogIndirectParam...
  407. //
  408. // Returns: TRUE (or dlg fcn return vals) - success
  409. // FALSE - failure
  410. //
  411. ////////////////////////////////////////////////////////////////////////////
  412. BOOL_PTR CALLBACK FindReplaceDlgProc(
  413. HWND hDlg,
  414. UINT wMsg,
  415. WPARAM wParam,
  416. LPARAM lParam)
  417. {
  418. PFINDREPLACEINFO pFRI;
  419. LPFINDREPLACE pFR;
  420. BOOL_PTR bRet;
  421. //
  422. // If a hook exists, let hook function do procing.
  423. //
  424. if (pFRI = (PFINDREPLACEINFO)GetProp(hDlg, FINDREPLACEPROP))
  425. {
  426. if ((pFR = (LPFINDREPLACE)pFRI->pFR) &&
  427. (pFR->Flags & FR_ENABLEHOOK))
  428. {
  429. LPFRHOOKPROC lpfnHook = GETHOOKFN(pFR);
  430. if ((bRet = (*lpfnHook)(hDlg, wMsg, wParam, lParam)))
  431. {
  432. return (bRet);
  433. }
  434. }
  435. }
  436. else if (glpfnFindHook &&
  437. (wMsg != WM_INITDIALOG) &&
  438. (bRet = (* glpfnFindHook)(hDlg, wMsg, wParam, lParam)))
  439. {
  440. return (bRet);
  441. }
  442. //
  443. // Dispatch MSG to appropriate HANDLER.
  444. //
  445. switch (wMsg)
  446. {
  447. case ( WM_INITDIALOG ) :
  448. {
  449. //
  450. // Set Up P-Slot.
  451. //
  452. pFRI = (PFINDREPLACEINFO)lParam;
  453. SetProp(hDlg, FINDREPLACEPROP, (HANDLE)pFRI);
  454. glpfnFindHook = 0;
  455. //
  456. // Init dlg controls accordingly.
  457. //
  458. pFR = pFRI->pFR;
  459. InitControlsWithFlags(hDlg, pFR, pFRI->DlgType, pFRI->ApiType);
  460. //
  461. // If Hook function, do extra processing.
  462. //
  463. if (pFR->Flags & FR_ENABLEHOOK)
  464. {
  465. LPFRHOOKPROC lpfnHook = GETHOOKFN(pFR);
  466. bRet = (*lpfnHook)(hDlg, wMsg, wParam, (LPARAM)pFR);
  467. }
  468. else
  469. {
  470. bRet = TRUE;
  471. }
  472. if (bRet)
  473. {
  474. //
  475. // If the hook function returns FALSE, then we must call
  476. // these functions here.
  477. //
  478. ShowWindow(hDlg, SW_SHOWNORMAL);
  479. UpdateWindow(hDlg);
  480. }
  481. return (bRet);
  482. break;
  483. }
  484. case ( WM_COMMAND ) :
  485. {
  486. if (!pFRI || !pFR)
  487. {
  488. return (FALSE);
  489. }
  490. switch (GET_WM_COMMAND_ID (wParam, lParam))
  491. {
  492. //
  493. // FIND NEXT button clicked.
  494. //
  495. case ( IDOK ) :
  496. {
  497. UpdateTextAndFlags( hDlg,
  498. pFR,
  499. FR_FINDNEXT,
  500. pFRI->DlgType,
  501. pFRI->ApiType );
  502. NotifyUpdateTextAndFlags(pFR);
  503. break;
  504. }
  505. case ( IDCANCEL ) :
  506. case ( IDABORT ) :
  507. {
  508. EndDlgSession(hDlg, pFR);
  509. LocalFree(pFRI);
  510. break;
  511. }
  512. case ( psh1 ) :
  513. case ( psh2 ) :
  514. {
  515. UpdateTextAndFlags( hDlg,
  516. pFR,
  517. (wParam == psh1)
  518. ? FR_REPLACE
  519. : FR_REPLACEALL,
  520. pFRI->DlgType,
  521. pFRI->ApiType );
  522. if (NotifyUpdateTextAndFlags(pFR) == TRUE)
  523. {
  524. //
  525. // Change <Cancel> button to <Close> if function
  526. // returns TRUE.
  527. // IDCANCEL instead of psh1.
  528. SetWindowText( GetDlgItem(hDlg, IDCANCEL),
  529. (LPTSTR)szClose );
  530. }
  531. break;
  532. }
  533. case ( pshHelp ) :
  534. {
  535. //
  536. // Call HELP app.
  537. //
  538. #ifdef UNICODE
  539. if (pFRI->ApiType == COMDLG_ANSI)
  540. {
  541. if (msgHELPA && pFR->hwndOwner)
  542. {
  543. SendMessage( pFR->hwndOwner,
  544. msgHELPA,
  545. (WPARAM)hDlg,
  546. (LPARAM)pFR );
  547. }
  548. }
  549. else
  550. #endif
  551. {
  552. if (msgHELPW && pFR->hwndOwner)
  553. {
  554. SendMessage( pFR->hwndOwner,
  555. msgHELPW,
  556. (WPARAM)hDlg,
  557. (LPARAM)pFR );
  558. }
  559. }
  560. break;
  561. }
  562. case ( edt1 ) :
  563. {
  564. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
  565. {
  566. BOOL fAnythingToFind =
  567. (BOOL)SendDlgItemMessage( hDlg,
  568. edt1,
  569. WM_GETTEXTLENGTH,
  570. 0,
  571. 0L );
  572. EnableWindow(GetDlgItem(hDlg, IDOK), fAnythingToFind);
  573. if (pFRI->DlgType == DLGT_REPLACE)
  574. {
  575. EnableWindow(GetDlgItem(hDlg, psh1), fAnythingToFind);
  576. EnableWindow(GetDlgItem(hDlg, psh2), fAnythingToFind);
  577. }
  578. }
  579. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
  580. {
  581. EnableWindow( GetDlgItem(hDlg, IDOK),
  582. (BOOL)SendDlgItemMessage(
  583. hDlg,
  584. edt1,
  585. WM_GETTEXTLENGTH,
  586. 0,
  587. 0L ));
  588. }
  589. break;
  590. }
  591. default :
  592. {
  593. return (FALSE);
  594. }
  595. }
  596. break;
  597. }
  598. case ( WM_HELP ) :
  599. {
  600. if (IsWindowEnabled(hDlg))
  601. {
  602. WinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle,
  603. NULL,
  604. HELP_WM_HELP,
  605. (ULONG_PTR)(LPTSTR)aFindReplaceHelpIDs );
  606. }
  607. break;
  608. }
  609. case ( WM_CONTEXTMENU ) :
  610. {
  611. if (IsWindowEnabled(hDlg))
  612. {
  613. WinHelp( (HWND)wParam,
  614. NULL,
  615. HELP_CONTEXTMENU,
  616. (ULONG_PTR)(LPVOID)aFindReplaceHelpIDs );
  617. }
  618. break;
  619. }
  620. case ( WM_CLOSE ) :
  621. {
  622. SendMessage(hDlg, WM_COMMAND, GET_WM_COMMAND_MPS(IDCANCEL, 0, 0));
  623. return (TRUE);
  624. break;
  625. }
  626. default:
  627. {
  628. return (FALSE);
  629. break;
  630. }
  631. }
  632. return (TRUE);
  633. }
  634. ////////////////////////////////////////////////////////////////////////////
  635. //
  636. // EndDlgSession
  637. //
  638. // Cleans up upon destroying the dialog.
  639. //
  640. ////////////////////////////////////////////////////////////////////////////
  641. VOID EndDlgSession(
  642. HWND hDlg,
  643. LPFINDREPLACE pFR)
  644. {
  645. //
  646. // Need to terminate regardless of app testing order ... so:
  647. //
  648. //
  649. // No SUCCESS on termination.
  650. //
  651. pFR->Flags &= ~((DWORD)(FR_REPLACE | FR_FINDNEXT | FR_REPLACEALL));
  652. //
  653. // Tell caller dialog is about to terminate.
  654. //
  655. pFR->Flags |= FR_DIALOGTERM;
  656. NotifyUpdateTextAndFlags(pFR);
  657. if (IS16BITWOWAPP(pFR))
  658. {
  659. if ((pFR->Flags & FR_ENABLEHOOK) && (pFR->lpfnHook))
  660. {
  661. (*pFR->lpfnHook)(hDlg, WM_DESTROY, 0, 0);
  662. }
  663. }
  664. //
  665. // Free property slots.
  666. //
  667. RemoveProp(hDlg, FINDREPLACEPROP);
  668. DestroyWindow(hDlg);
  669. }
  670. ////////////////////////////////////////////////////////////////////////////
  671. //
  672. // InitControlsWithFlags
  673. //
  674. ////////////////////////////////////////////////////////////////////////////
  675. VOID InitControlsWithFlags(
  676. HWND hDlg,
  677. LPFINDREPLACE pFR,
  678. UINT DlgType,
  679. UINT ApiType)
  680. {
  681. HWND hCtl;
  682. //
  683. // Set EDIT control to FindText.
  684. //
  685. #ifdef UNICODE
  686. if (ApiType == COMDLG_ANSI)
  687. {
  688. SetDlgItemTextA(hDlg, edt1, (LPSTR)pFR->lpstrFindWhat);
  689. }
  690. else
  691. #endif
  692. {
  693. SetDlgItemText(hDlg, edt1, (LPTSTR)pFR->lpstrFindWhat);
  694. }
  695. SendMessage(hDlg, WM_COMMAND, GET_WM_COMMAND_MPS(edt1, 0, EN_CHANGE));
  696. //
  697. // Set HELP push button state.
  698. //
  699. if (!(pFR->Flags & FR_SHOWHELP))
  700. {
  701. ShowWindow(hCtl = GetDlgItem(hDlg, pshHelp), SW_HIDE);
  702. EnableWindow(hCtl, FALSE);
  703. }
  704. //
  705. // Dis/Enable check state of WHOLE WORD control.
  706. //
  707. if (pFR->Flags & FR_HIDEWHOLEWORD)
  708. {
  709. ShowWindow(hCtl = GetDlgItem(hDlg, chx1), SW_HIDE);
  710. EnableWindow(hCtl, FALSE);
  711. }
  712. else if (pFR->Flags & FR_NOWHOLEWORD)
  713. {
  714. EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
  715. }
  716. CheckDlgButton(hDlg, chx1, (pFR->Flags & FR_WHOLEWORD) ? TRUE: FALSE);
  717. //
  718. // Dis/Enable check state of MATCH CASE control.
  719. //
  720. if (pFR->Flags & FR_HIDEMATCHCASE)
  721. {
  722. ShowWindow(hCtl = GetDlgItem(hDlg, chx2), SW_HIDE);
  723. EnableWindow(hCtl, FALSE);
  724. }
  725. else if (pFR->Flags & FR_NOMATCHCASE)
  726. {
  727. EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
  728. }
  729. CheckDlgButton(hDlg, chx2, (pFR->Flags & FR_MATCHCASE) ? TRUE: FALSE);
  730. //
  731. // Dis/Enable check state of UP/DOWN buttons.
  732. //
  733. if (pFR->Flags & FR_HIDEUPDOWN)
  734. {
  735. ShowWindow(GetDlgItem(hDlg, grp1), SW_HIDE);
  736. ShowWindow(hCtl = GetDlgItem(hDlg, rad1), SW_HIDE);
  737. EnableWindow(hCtl, FALSE);
  738. ShowWindow(hCtl = GetDlgItem(hDlg, rad2), SW_HIDE);
  739. EnableWindow(hCtl, FALSE);
  740. }
  741. else if (pFR->Flags & FR_NOUPDOWN)
  742. {
  743. EnableWindow(GetDlgItem(hDlg, rad1), FALSE);
  744. EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
  745. }
  746. if (DlgType == DLGT_FIND)
  747. {
  748. //
  749. // Find Text only search direction setup.
  750. //
  751. CheckRadioButton( hDlg,
  752. rad1,
  753. rad2,
  754. (pFR->Flags & FR_DOWN ? rad2 : rad1) );
  755. }
  756. else
  757. {
  758. //
  759. // Replace Text only operations.
  760. //
  761. #ifdef UNICODE
  762. if (ApiType == COMDLG_ANSI)
  763. {
  764. SetDlgItemTextA(hDlg, edt2, (LPSTR)pFR->lpstrReplaceWith);
  765. }
  766. else
  767. #endif
  768. {
  769. SetDlgItemText(hDlg, edt2, pFR->lpstrReplaceWith);
  770. }
  771. SendMessage( hDlg,
  772. WM_COMMAND,
  773. GET_WM_COMMAND_MPS(edt2, 0, EN_CHANGE) );
  774. }
  775. }
  776. ////////////////////////////////////////////////////////////////////////////
  777. //
  778. // UpdateTextAndFlags
  779. //
  780. // chx1 is whether or not to match entire words
  781. // chx2 is whether or not case is relevant
  782. // chx3 is whether or not to wrap scans
  783. //
  784. ////////////////////////////////////////////////////////////////////////////
  785. VOID UpdateTextAndFlags(
  786. HWND hDlg,
  787. LPFINDREPLACE pFR,
  788. DWORD dwActionFlag,
  789. UINT DlgType,
  790. UINT ApiType)
  791. {
  792. //
  793. // Only clear flags that this routine sets. The hook and template
  794. // flags should not be anded off here.
  795. //
  796. pFR->Flags &= ~((DWORD)(FR_WHOLEWORD | FR_MATCHCASE | FR_REPLACE |
  797. FR_FINDNEXT | FR_REPLACEALL | FR_DOWN));
  798. if (IsDlgButtonChecked(hDlg, chx1))
  799. {
  800. pFR->Flags |= FR_WHOLEWORD;
  801. }
  802. if (IsDlgButtonChecked(hDlg, chx2))
  803. {
  804. pFR->Flags |= FR_MATCHCASE;
  805. }
  806. //
  807. // Set ACTION flag FR_{REPLACE,FINDNEXT,REPLACEALL}.
  808. //
  809. pFR->Flags |= dwActionFlag;
  810. #ifdef UNICODE
  811. if (ApiType == COMDLG_ANSI)
  812. {
  813. GetDlgItemTextA(hDlg, edt1, (LPSTR)pFR->lpstrFindWhat, pFR->wFindWhatLen);
  814. }
  815. else
  816. #endif
  817. {
  818. GetDlgItemText(hDlg, edt1, pFR->lpstrFindWhat, pFR->wFindWhatLen);
  819. }
  820. if (DlgType == DLGT_FIND)
  821. {
  822. //
  823. // Assume searching down. Check if UP button is NOT pressed, rather
  824. // than if DOWN button IS. So, if buttons have been hidden or
  825. // disabled, FR_DOWN flag will be set correctly.
  826. //
  827. if (!IsDlgButtonChecked(hDlg, rad1))
  828. {
  829. pFR->Flags |= FR_DOWN;
  830. }
  831. }
  832. else
  833. {
  834. #ifdef UNICODE
  835. if (ApiType == COMDLG_ANSI)
  836. {
  837. GetDlgItemTextA( hDlg,
  838. edt2,
  839. (LPSTR)pFR->lpstrReplaceWith,
  840. pFR->wReplaceWithLen );
  841. }
  842. else
  843. #endif
  844. {
  845. GetDlgItemText( hDlg,
  846. edt2,
  847. pFR->lpstrReplaceWith,
  848. pFR->wReplaceWithLen );
  849. }
  850. pFR->Flags |= FR_DOWN;
  851. }
  852. }
  853. ////////////////////////////////////////////////////////////////////////////
  854. //
  855. // NotifyUpdateTextAndFlags
  856. //
  857. ////////////////////////////////////////////////////////////////////////////
  858. LRESULT NotifyUpdateTextAndFlags(
  859. LPFINDREPLACE pFR)
  860. {
  861. if (IS16BITWOWAPP(pFR))
  862. {
  863. return ( SendMessage( pFR->hwndOwner,
  864. WM_NOTIFYWOW,
  865. WMNW_UPDATEFINDREPLACE,
  866. (DWORD_PTR)pFR ) );
  867. }
  868. return ( SendMessage(pFR->hwndOwner, wFRMessage, 0, (DWORD_PTR)pFR) );
  869. }