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.

1541 lines
49 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: srch.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. #include <htmlhelp.h>
  16. typedef void (__stdcall * PFnCIShutdown)(void);
  17. PFnCIShutdown g_pCIShutdown = 0;
  18. void MyCIShutdown()
  19. {
  20. if ( 0 == g_pCIShutdown )
  21. {
  22. #ifdef _WIN64
  23. char const * pcCIShutdown = "?CIShutdown@@YAXXZ";
  24. #else
  25. char const * pcCIShutdown = "?CIShutdown@@YGXXZ";
  26. #endif
  27. g_pCIShutdown = (PFnCIShutdown) GetProcAddress( GetModuleHandle( L"query.dll" ), pcCIShutdown );
  28. if ( 0 == g_pCIShutdown )
  29. return;
  30. }
  31. g_pCIShutdown();
  32. } //MyCIShutdown
  33. CSearchApp App;
  34. int WINAPI WinMain(
  35. HINSTANCE hInstance,
  36. HINSTANCE hPrevInstance,
  37. LPSTR pcCmdLine,
  38. int nCmdShow)
  39. {
  40. int iRet = 0;
  41. CTranslateSystemExceptions xlate;
  42. TRY
  43. {
  44. App.Init(hInstance,nCmdShow,pcCmdLine);
  45. }
  46. CATCH(CException, e)
  47. {
  48. // hardcode these strings -- may be out of memory!
  49. MessageBox( 0, L"Unable to start the application.", L"srch.exe",
  50. MB_OK | MB_ICONEXCLAMATION);
  51. iRet = -1;
  52. }
  53. END_CATCH;
  54. if (0 == iRet)
  55. iRet = App.MessageLoop();
  56. srchDebugOut ((DEB_TRACE,"falling out of WinMain()\n"));
  57. TRY
  58. {
  59. MyCIShutdown();
  60. App.Shutdown( hInstance );
  61. }
  62. CATCH(CException, e)
  63. {
  64. }
  65. END_CATCH;
  66. return iRet;
  67. } //WinMain
  68. int CSearchApp::MessageLoop()
  69. {
  70. // toss out all the init code that we'll never need again
  71. SetProcessWorkingSetSize( GetCurrentProcess(), (SIZE_T) -1, (SIZE_T) -1 );
  72. MSG msg;
  73. while (GetMessage(&msg,0,0,0))
  74. {
  75. if ( ( 0 == _hdlgCurrent ) ||
  76. ( !IsDialogMessage( _hdlgCurrent, &msg ) ) )
  77. {
  78. if (!TranslateMDISysAccel(_hMDIClientWnd,&msg) &&
  79. !TranslateAccelerator(_hAppWnd,_hAccTable,&msg))
  80. {
  81. if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_F1))
  82. _ShowHelp( HH_DISPLAY_TOPIC, 0 );
  83. TranslateMessage(&msg);
  84. DispatchMessage(&msg);
  85. }
  86. }
  87. }
  88. return (int)msg.wParam;
  89. } //MessageLoop
  90. LRESULT WINAPI MainWndProc(
  91. HWND hwnd,
  92. UINT msg,
  93. WPARAM wParam,
  94. LPARAM lParam)
  95. {
  96. return App.WndProc(hwnd,msg,wParam,lParam);
  97. } //MainWndProc
  98. CSearchApp::CSearchApp():
  99. _hInst(0),
  100. _hMDIClientWnd(0),
  101. _hAppWnd(0),
  102. _hStatusBarWnd(0),
  103. _hToolBarWnd(0),
  104. _hdlgCurrent(0),
  105. _hAccTable(0),
  106. _hbrushBtnFace(0),
  107. _hbrushBtnHilite(0),
  108. _hbrushHilite(0),
  109. _hbrushWindow(0),
  110. _hfontApp(0),
  111. _hfontBrowse(0),
  112. _fHelp(FALSE),
  113. _iAppCmdShow(0),
  114. _iStartupState(0),
  115. _iMDIStartupState(0),
  116. _scBrowseLastError(0),
  117. _sortDir(0),
  118. _lcid(0),
  119. _fToolBarOn(FALSE),
  120. _fStatusBarOn(FALSE),
  121. _fForceUseCI(FALSE),
  122. _ulDialect(0),
  123. _ulLimit(0),
  124. _ulFirstRows(0),
  125. _sortDirINI(0),
  126. _lcidINI(0),
  127. _fToolBarOnINI(FALSE),
  128. _fStatusBarOnINI(FALSE),
  129. _fForceUseCIINI(FALSE),
  130. _ulDialectINI(0),
  131. _ulLimitINI(0),
  132. _ulFirstRowsINI(0)
  133. {
  134. RtlZeroMemory( &_NumberFmt, sizeof( NUMBERFMT ) );
  135. RtlZeroMemory( &_NumberFmtFloat, sizeof( NUMBERFMT ) );
  136. RtlZeroMemory( &_lfApp, sizeof( LOGFONT ) );
  137. RtlZeroMemory( &_lfBrowse, sizeof( LOGFONT ) );
  138. *_awcAppFont = 0;
  139. *_awcBrowseFont = 0;
  140. *_awcAppPath = 0;
  141. *_awcHelpFile = 0;
  142. *_awcSort = 0;
  143. *_awcSortINI = 0;
  144. *_awcDefaultQuery = 0;
  145. } //CSearchApp
  146. void CSearchApp::Init(
  147. HINSTANCE hInstance,
  148. int nCmdShow,
  149. LPSTR pcCmdLine)
  150. {
  151. HRESULT hr = CoInitialize( 0 );
  152. if ( FAILED( hr ) )
  153. THROW( CException( hr ) );
  154. InitCommonControls();
  155. INITCOMMONCONTROLSEX icex;
  156. icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  157. icex.dwICC = ICC_USEREX_CLASSES;
  158. InitCommonControlsEx(&icex);
  159. _iAppCmdShow = nCmdShow;
  160. _hInst = hInstance;
  161. _InitApplication();
  162. _InitInstance(pcCmdLine);
  163. } //Init
  164. void CSearchApp::Shutdown( HINSTANCE hInst )
  165. {
  166. UnregisterClass( APP_CLASS, hInst );
  167. UnregisterClass( SEARCH_CLASS, hInst );
  168. UnregisterClass( BROWSE_CLASS, hInst );
  169. UnregisterClass( LIST_VIEW_CLASS, hInst );
  170. if ( 0 != _hfontApp )
  171. DeleteObject( _hfontApp );
  172. if ( 0 != _hfontBrowse )
  173. DeleteObject( _hfontBrowse );
  174. FreeNumberFormatInfo( _NumberFmt );
  175. FreeNumberFormatInfo( _NumberFmtFloat );
  176. _xCmdCreator.Free();
  177. CoUninitialize();
  178. } //Shutdown
  179. CSearchApp::~CSearchApp()
  180. {
  181. } //~CSearchApp
  182. BOOL WINAPI AboutDlgProc(
  183. HWND hdlg,
  184. UINT msg,
  185. WPARAM wParam,
  186. LPARAM lParam)
  187. {
  188. BOOL fRet = FALSE;
  189. switch (msg)
  190. {
  191. case WM_INITDIALOG :
  192. CenterDialog(hdlg);
  193. fRet = TRUE;
  194. break;
  195. case WM_COMMAND :
  196. EndDialog(hdlg,TRUE);
  197. break;
  198. }
  199. return fRet;
  200. } //AboutDlgProc
  201. #if 0
  202. BOOL WINAPI BrowseToolDlgProc(
  203. HWND hdlg,
  204. UINT msg,
  205. WPARAM wParam,
  206. LPARAM lParam)
  207. {
  208. BOOL fRet = FALSE;
  209. UINT uiID;
  210. WCHAR awcCmd[MAX_PATH];
  211. DWORD dwSize;
  212. int fStrip;
  213. switch (msg)
  214. {
  215. case WM_INITDIALOG :
  216. dwSize = sizeof awcCmd / sizeof awcCmd[0];
  217. if (!GetReg(CISEARCH_REG_BROWSE,awcCmd,&dwSize))
  218. wcscpy(awcCmd,BROWSER);
  219. fStrip = GetRegInt(CISEARCH_REG_BROWSESTRIP,FALSE);
  220. SetDlgItemText(hdlg,ID_BR_EDIT,L"");
  221. EnableWindow(GetDlgItem(hdlg,ID_BR_EDIT),FALSE);
  222. EnableWindow(GetDlgItem(hdlg,ID_BR_STRIP),FALSE);
  223. if (!_wcsicmp(awcCmd,BROWSER))
  224. CheckRadioButton(hdlg,ID_BR_BROWSER,ID_BR_CUSTOM,ID_BR_BROWSER);
  225. else if (!_wcsicmp(awcCmd,BROWSER_SLICK))
  226. CheckRadioButton(hdlg,ID_BR_BROWSER,ID_BR_CUSTOM,ID_BR_SLICK);
  227. else if (!_wcsicmp(awcCmd,BROWSER_SLICK_SEARCH))
  228. CheckRadioButton(hdlg,ID_BR_BROWSER,ID_BR_CUSTOM,ID_BR_SLICK_SEARCH);
  229. else
  230. {
  231. CheckRadioButton(hdlg,ID_BR_BROWSER,ID_BR_CUSTOM,ID_BR_CUSTOM);
  232. SetDlgItemText(hdlg,ID_BR_EDIT,awcCmd);
  233. EnableWindow(GetDlgItem(hdlg,ID_BR_EDIT),TRUE);
  234. EnableWindow(GetDlgItem(hdlg,ID_BR_STRIP),TRUE);
  235. CheckDlgButton(hdlg,ID_BR_STRIP,fStrip);
  236. }
  237. CenterDialog(hdlg);
  238. fRet = TRUE;
  239. break;
  240. case WM_COMMAND :
  241. uiID = MyWmCommandID(wParam,lParam);
  242. switch (uiID)
  243. {
  244. case ID_BR_BROWSER:
  245. case ID_BR_SLICK:
  246. case ID_BR_SLICK_SEARCH:
  247. case ID_BR_CUSTOM:
  248. SetDlgItemText(hdlg,ID_BR_EDIT,L"");
  249. EnableWindow(GetDlgItem(hdlg,ID_BR_EDIT),ID_BR_CUSTOM == uiID);
  250. EnableWindow(GetDlgItem(hdlg,ID_BR_STRIP),ID_BR_CUSTOM == uiID);
  251. CheckRadioButton(hdlg,ID_BR_BROWSER,ID_BR_CUSTOM,uiID);
  252. if (ID_BR_CUSTOM == uiID)
  253. {
  254. SetFocus(GetDlgItem(hdlg,ID_BR_EDIT));
  255. MySendEMSetSel(GetDlgItem(hdlg,ID_BR_EDIT),0,(UINT) -1);
  256. }
  257. break;
  258. case IDOK:
  259. fStrip = FALSE;
  260. if (IsDlgButtonChecked(hdlg,ID_BR_BROWSER))
  261. wcscpy(awcCmd,BROWSER);
  262. else if (IsDlgButtonChecked(hdlg,ID_BR_SLICK))
  263. wcscpy(awcCmd,BROWSER_SLICK);
  264. else if (IsDlgButtonChecked(hdlg,ID_BR_SLICK_SEARCH))
  265. wcscpy(awcCmd,BROWSER_SLICK_SEARCH);
  266. else
  267. {
  268. GetDlgItemText(hdlg,ID_BR_EDIT,awcCmd,sizeof awcCmd);
  269. fStrip = IsDlgButtonChecked(hdlg,ID_BR_STRIP);
  270. }
  271. if (0 == awcCmd[0])
  272. wcscpy(awcCmd,BROWSER);
  273. SetReg(CISEARCH_REG_BROWSE,awcCmd);
  274. SetRegInt(CISEARCH_REG_BROWSESTRIP,fStrip);
  275. // fall through!
  276. case IDCANCEL:
  277. EndDialog(hdlg,IDOK == uiID);
  278. break;
  279. }
  280. break;
  281. }
  282. return fRet;
  283. } //BrowseToolDlgProc
  284. #endif
  285. void CSearchApp::_SizeMDIAndBars(
  286. BOOL fMove,
  287. int iDX,
  288. int iDY )
  289. {
  290. if (_hMDIClientWnd)
  291. {
  292. int iMdiDY = iDY;
  293. int iMdiY = 0;
  294. if (_fToolBarOn)
  295. {
  296. RECT rc;
  297. GetWindowRect( _hToolBarWnd, &rc );
  298. iMdiY = rc.bottom - rc.top;
  299. iMdiDY -= iMdiY;
  300. }
  301. if (_fStatusBarOn)
  302. {
  303. RECT rc;
  304. GetWindowRect( _hStatusBarWnd, &rc );
  305. iMdiDY -= ( rc.bottom - rc.top );
  306. }
  307. MoveWindow( _hMDIClientWnd, 0, iMdiY, iDX, iMdiDY, TRUE );
  308. }
  309. if ( _fStatusBarOn && !fMove )
  310. InvalidateRect( _hStatusBarWnd, 0, TRUE );
  311. } //_SizeMDIAndBars
  312. void CSearchApp::_SaveProfileData()
  313. {
  314. _SaveWindowState(FALSE);
  315. _SaveWindowState(TRUE);
  316. if ( _ulLimit != _ulLimitINI )
  317. SetRegInt( CISEARCH_REG_LIMIT, _ulLimit );
  318. if ( _ulFirstRows != _ulFirstRowsINI )
  319. SetRegInt( CISEARCH_REG_FIRSTROWS, _ulFirstRows );
  320. if ( _ulDialect != _ulDialectINI )
  321. SetRegInt( CISEARCH_REG_DIALECT, _ulDialect );
  322. if (_fToolBarOn != _fToolBarOnINI)
  323. SetRegInt(CISEARCH_REG_TOOLBAR,_fToolBarOn);
  324. if (_fStatusBarOn != _fStatusBarOnINI)
  325. SetRegInt(CISEARCH_REG_STATUSBAR,_fStatusBarOn);
  326. if (_fForceUseCI != _fForceUseCIINI)
  327. SetRegInt(CISEARCH_REG_FORCEUSECI,_fForceUseCI);
  328. if (_sortDir != _sortDirINI)
  329. SetRegInt(CISEARCH_REG_SORTDIR,_sortDir);
  330. if ( _wcsicmp( _awcSortINI, _awcSort ) )
  331. SetReg( CISEARCH_REG_SORTPROP, _awcSort );
  332. if ( _lcid != _lcidINI )
  333. SetRegLCID( CISEARCH_REG_LOCALE, _lcid );
  334. _MarshallFont(_lfApp,_awcAppFont,CISEARCH_REG_FONT);
  335. _MarshallFont(_lfBrowse,_awcBrowseFont,CISEARCH_REG_BROWSEFONT);
  336. } //_SaveProfileData
  337. void CSearchApp::_UnMarshallFont(
  338. LOGFONT &lf,
  339. WCHAR *pwcFont,
  340. WCHAR *pwcRegEntry)
  341. {
  342. DWORD dwSize = MAX_PATH;
  343. if (GetReg(pwcRegEntry,pwcFont,&dwSize))
  344. {
  345. int iItalic,iUnderline,iStrikeOut,iCharSet,iQuality,iPitchAndFamily;
  346. swscanf(pwcFont,L"%d,%d,%d,%d,%d,%d,%d,%d,%d",&lf.lfHeight,
  347. &lf.lfWidth,&lf.lfWeight,&iItalic,&iUnderline,
  348. &iStrikeOut,&iCharSet,&iQuality,&iPitchAndFamily);
  349. WCHAR *pwc = pwcFont;
  350. for (int i = 0; *pwc && i < 9; pwc++)
  351. if (*pwc == ',')
  352. i++;
  353. wcscpy(lf.lfFaceName,pwc);
  354. lf.lfItalic = (BYTE) iItalic;
  355. lf.lfUnderline = (BYTE) iUnderline;
  356. lf.lfStrikeOut = (BYTE) iStrikeOut;
  357. lf.lfCharSet = (BYTE) iCharSet;
  358. lf.lfQuality = (BYTE) iQuality;
  359. lf.lfPitchAndFamily = (BYTE) iPitchAndFamily;
  360. }
  361. } //_UnMarshallFont
  362. void CSearchApp::_MarshallFont(
  363. LOGFONT &lf,
  364. WCHAR *pwcOriginal,
  365. WCHAR *pwcRegEntry)
  366. {
  367. WCHAR awcTmp[MAX_PATH];
  368. swprintf(awcTmp,L"%d,%d,%d,%d,%d,%d,%d,%d,%d,%ws",lf.lfHeight,
  369. lf.lfWidth,lf.lfWeight,(int) lf.lfItalic,
  370. (int) lf.lfUnderline,(int) lf.lfStrikeOut,
  371. (int) lf.lfCharSet,(int) lf.lfQuality,
  372. (int) lf.lfPitchAndFamily,lf.lfFaceName);
  373. if (wcscmp(pwcOriginal,awcTmp))
  374. SetReg(pwcRegEntry,awcTmp);
  375. } //_MarshallFont
  376. void CSearchApp::_ReadDefaultFonts()
  377. {
  378. _UnMarshallFont(_lfApp,_awcAppFont,CISEARCH_REG_FONT);
  379. _UnMarshallFont(_lfBrowse,_awcBrowseFont,CISEARCH_REG_BROWSEFONT);
  380. } //_ReadDefaultFont
  381. LRESULT CSearchApp::WndProc(
  382. HWND hwnd,
  383. UINT msg,
  384. WPARAM wParam,
  385. LPARAM lParam)
  386. {
  387. LRESULT lRet = 0;
  388. UINT uiStatus,uiFmt;
  389. RECT rc;
  390. CLIENTCREATESTRUCT ccs;
  391. CHOOSEFONT chf;
  392. HDC hdc;
  393. HWND hwndActive;
  394. WCHAR * pwcBuf;
  395. LONG l;
  396. BOOL bOn;
  397. HMENU hSysMenu;
  398. WCHAR awcWindowClass[60],*pwcAboutBonus;
  399. UINT uiID,uiFlags,uiCmd;
  400. switch (msg)
  401. {
  402. case WM_ENTERIDLE :
  403. if ((wParam == MSGF_MENU) && (GetKeyState(VK_F1) & 0x8000))
  404. {
  405. _fHelp = TRUE;
  406. PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
  407. }
  408. break;
  409. case WM_NOTIFY :
  410. lRet = ToolBarNotify( hwnd, msg, wParam, lParam, App.Instance() );
  411. break;
  412. case WM_MENUSELECT :
  413. {
  414. UINT uiFlags = MyMenuSelectFlags( wParam, lParam );
  415. UINT uiCmd = MyMenuSelectCmd( wParam, lParam );
  416. HMENU hmenu = MyMenuSelectHMenu( wParam, lParam );
  417. if (_fStatusBarOn)
  418. {
  419. UINT uiID = 0;
  420. if ( 0xffff == uiFlags && 0 == hmenu )
  421. uiID = (UINT) -1;
  422. else if ( MFT_SEPARATOR == uiFlags )
  423. uiID = 0;
  424. else if ( MF_POPUP == uiFlags )
  425. uiID = 0;
  426. else
  427. {
  428. uiID = uiCmd;
  429. if ( uiID >= IDM_WINDOWCHILD )
  430. if (uiID < (IDM_WINDOWCHILD + 20))
  431. uiID = IDS_IDM_WINDOWCHILD;
  432. else
  433. uiID = 0;
  434. }
  435. if ( -1 == uiID )
  436. {
  437. SendMessage( _hStatusBarWnd, SB_SIMPLE, FALSE, 0 );
  438. }
  439. else
  440. {
  441. SendMessage( _hStatusBarWnd, SB_SIMPLE, TRUE, 0 );
  442. if ( 0 != uiID )
  443. {
  444. WCHAR awc[ 200 ];
  445. LoadString( _hInst, uiID, awc, sizeof awc / sizeof WCHAR );
  446. SendMessage( _hStatusBarWnd, SB_SETTEXT, 255,
  447. (LPARAM) awc );
  448. }
  449. }
  450. }
  451. break;
  452. }
  453. case WM_COMMAND :
  454. {
  455. uiID = MyWmCommandID(wParam,lParam);
  456. switch (uiID)
  457. {
  458. case IDM_STATUS_BAR :
  459. case IDM_ICON_BAR :
  460. uiStatus = GetMenuState(GetMenu(hwnd),uiID,MF_BYCOMMAND);
  461. bOn = ! (uiStatus & MF_CHECKED);
  462. if (uiID == IDM_STATUS_BAR)
  463. {
  464. _fStatusBarOn = bOn;
  465. ShowWindow(_hStatusBarWnd,bOn ? SW_SHOW : SW_HIDE);
  466. }
  467. else
  468. {
  469. _fToolBarOn = bOn;
  470. ShowWindow(_hToolBarWnd,bOn ? SW_SHOW : SW_HIDE);
  471. }
  472. CheckMenuItem(GetMenu(hwnd),uiID,bOn ? MF_CHECKED : MF_UNCHECKED);
  473. GetClientRect(hwnd,&rc);
  474. _SizeMDIAndBars( FALSE, rc.right, rc.bottom );
  475. break;
  476. case IDM_FONT :
  477. {
  478. BOOL fApp = IsSpecificClass(GetActiveMDI(),SEARCH_CLASS);
  479. LOGFONT *pLogFont = fApp ? &_lfApp : &_lfBrowse;
  480. HFONT &rhFont = fApp ? _hfontApp : _hfontBrowse;
  481. hdc = GetDC(hwnd);
  482. memset(&chf,0,sizeof CHOOSEFONT);
  483. chf.lStructSize = sizeof CHOOSEFONT;
  484. chf.hwndOwner = hwnd;
  485. chf.hDC = hdc;
  486. chf.lpLogFont = pLogFont;
  487. chf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
  488. chf.nFontType = SCREEN_FONTTYPE;
  489. if (ChooseFont(&chf))
  490. {
  491. HFONT hOldFont = rhFont;
  492. HFONT hNewFont = CreateFontIndirect(pLogFont);
  493. if (hNewFont)
  494. {
  495. rhFont = hNewFont;
  496. _SendToSpecificChildren(fApp ? SEARCH_CLASS :
  497. BROWSE_CLASS,
  498. wmNewFont,
  499. (WPARAM) hNewFont,0);
  500. if (hOldFont)
  501. DeleteObject(hOldFont);
  502. }
  503. }
  504. ReleaseDC(hwnd,hdc);
  505. }
  506. break;
  507. case IDM_OPEN :
  508. SendMessage(hwnd,wmOpenCatalog,TRUE,0);
  509. break;
  510. case IDM_ABOUT :
  511. {
  512. CResString strApp( IDS_APPNAME );
  513. CResString strBonus( IDS_ABOUT_BONUS );
  514. ShellAbout(hwnd,
  515. strApp.Get(),
  516. strBonus.Get(),
  517. LoadIcon(_hInst,L"SrchIcon"));
  518. break;
  519. }
  520. //case IDM_BROWSE_TOOL :
  521. // DoModalDialog(BrowseToolDlgProc,hwnd,L"BrowseToolBox",0);
  522. // break;
  523. case IDM_EXIT :
  524. SendMessage(hwnd,WM_CLOSE,0,0);
  525. break;
  526. case IDM_TILE :
  527. SendMessage(_hMDIClientWnd,WM_MDITILE,MDITILE_HORIZONTAL,0);
  528. break;
  529. case IDM_CASCADE :
  530. SendMessage(_hMDIClientWnd,WM_MDICASCADE,0,0);
  531. break;
  532. case IDM_ARRANGE :
  533. SendMessage(_hMDIClientWnd,WM_MDIICONARRANGE,0,0);
  534. break;
  535. case IDM_EDITUNDO:
  536. PassOnToEdit(EM_UNDO,0,0);
  537. break;
  538. case IDM_EDITCOPY:
  539. PassOnToEdit(WM_COPY,0,0);
  540. _SendToActiveMDI(wmMenuCommand,uiID,1L);
  541. break;
  542. case IDM_EDITPASTE:
  543. PassOnToEdit(WM_PASTE,0,0);
  544. break;
  545. case IDM_EDITCUT:
  546. PassOnToEdit(WM_CUT,0,0);
  547. break;
  548. case IDM_EDITCLEAR:
  549. PassOnToEdit(EM_REPLACESEL,0,(LPARAM) L"");
  550. break;
  551. case ACC_CTRLSPACE :
  552. if ((hwndActive = GetActiveMDI()) &&
  553. (hSysMenu = GetSystemMenu(hwndActive,FALSE)))
  554. PostMessage(hwndActive,WM_SYSCOMMAND,SC_KEYMENU,(DWORD) '-');
  555. else
  556. MessageBeep(0);
  557. break;
  558. case ACC_ALTR :
  559. case ACC_ALTQ :
  560. case ACC_TAB :
  561. case ACC_SHIFTTAB :
  562. _SendToActiveMDI(wmAccelerator,uiID,0);
  563. break;
  564. case IDM_CLOSE :
  565. _SendToActiveMDI(WM_CLOSE,0,0);
  566. break;
  567. case IDM_HELP_CONTENTS :
  568. _ShowHelp( HH_DISPLAY_TOPIC, 0 );
  569. break;
  570. case IDM_SEARCH :
  571. case IDM_SEARCHCLASSDEF :
  572. case IDM_SEARCHFUNCDEF :
  573. case IDM_NEWSEARCH :
  574. case IDM_BROWSE :
  575. case IDM_NEXT_HIT :
  576. case IDM_PREVIOUS_HIT :
  577. case IDM_WRITE_RESULTS :
  578. case IDM_SCOPE_AND_DEPTH :
  579. case IDM_FILTER_SCOPE :
  580. case IDM_LOCALE_NEUTRAL:
  581. case IDM_LOCALE_CHINESE_TRADITIONAL:
  582. case IDM_LOCALE_CHINESE_SIMPLIFIED:
  583. case IDM_LOCALE_CHINESE_HONGKONG:
  584. case IDM_LOCALE_CHINESE_SINGAPORE:
  585. case IDM_LOCALE_CHINESE_MACAU:
  586. case IDM_LOCALE_DUTCH_DUTCH:
  587. case IDM_LOCALE_ENGLISH_CAN:
  588. case IDM_LOCALE_ENGLISH_US:
  589. case IDM_LOCALE_ENGLISH_UK:
  590. case IDM_LOCALE_FINNISH_DEFAULT:
  591. case IDM_LOCALE_FARSI_DEFAULT:
  592. case IDM_LOCALE_FRENCH_FRENCH:
  593. case IDM_LOCALE_FRENCH_CANADIAN:
  594. case IDM_LOCALE_GERMAN_GERMAN:
  595. case IDM_LOCALE_GREEK_DEFAULT:
  596. case IDM_LOCALE_HEBREW_DEFAULT:
  597. case IDM_LOCALE_HINDI_DEFAULT:
  598. case IDM_LOCALE_ITALIAN_ITALIAN:
  599. case IDM_LOCALE_JAPANESE_DEFAULT:
  600. case IDM_LOCALE_KOREAN_KOREAN:
  601. // case IDM_LOCALE_KOREAN_JOHAB:
  602. case IDM_LOCALE_POLISH_DEFAULT:
  603. case IDM_LOCALE_ROMANIAN_DEFAULT:
  604. case IDM_LOCALE_RUSSIAN_DEFAULT:
  605. case IDM_LOCALE_SPANISH_CASTILIAN:
  606. case IDM_LOCALE_SPANISH_MEXICAN:
  607. case IDM_LOCALE_SPANISH_MODERN:
  608. case IDM_LOCALE_SWAHILI_DEFAULT:
  609. case IDM_LOCALE_SWEDISH_DEFAULT:
  610. case IDM_LOCALE_THAI_DEFAULT:
  611. case IDM_LOCALE_TURKISH_DEFAULT:
  612. case IDM_LOCALE_UKRAINIAN_DEFAULT:
  613. case IDM_LOCALE_VIETNAMESE_DEFAULT:
  614. case IDM_DISPLAY_PROPS:
  615. case IDM_CATALOG_STATUS:
  616. case IDM_MASTER_MERGE:
  617. case IDM_FORCE_USE_CI:
  618. case IDM_EDITCOPYALL :
  619. case IDM_DIALECT_1 :
  620. case IDM_DIALECT_2 :
  621. case IDM_DIALECT_3 :
  622. case IDM_LIMIT_10 :
  623. case IDM_LIMIT_300 :
  624. case IDM_LIMIT_NONE :
  625. case IDM_FIRSTROWS_5 :
  626. case IDM_FIRSTROWS_15 :
  627. case IDM_FIRSTROWS_NONE :
  628. _SendToActiveMDI(wmMenuCommand,uiID,1L);
  629. break;
  630. default :
  631. lRet = DefFrameProc(hwnd,_hMDIClientWnd,msg,wParam,lParam);
  632. break;
  633. }
  634. break;
  635. }
  636. case wmOpenCatalog:
  637. {
  638. BOOL fDialog = (BOOL) wParam;
  639. if ( !fDialog ||
  640. DoModalDialog( ScopeDlgProc,
  641. hwnd,
  642. L"ScopeBox",
  643. (LPARAM) &_xCatList ) )
  644. {
  645. _MakeMDI( _xCatList.Get(),
  646. SEARCH_CLASS,
  647. 0,0,
  648. (LPARAM) _xCatList.Get());
  649. }
  650. break;
  651. }
  652. case WM_DRAWITEM :
  653. _SendToActiveMDI(msg, wParam, lParam );
  654. break;
  655. case WM_SIZE :
  656. SendMessage( _hToolBarWnd, msg, wParam, lParam );
  657. SendMessage( _hStatusBarWnd, msg, wParam, lParam );
  658. _SizeMDIAndBars( FALSE, LOWORD( lParam ), HIWORD( lParam ) );
  659. break;
  660. case WM_MOVE :
  661. GetClientRect( hwnd, &rc );
  662. _SizeMDIAndBars( TRUE, rc.right, rc.bottom );
  663. break;
  664. case WM_SYSCOLORCHANGE :
  665. case WM_SETTINGCHANGE :
  666. _hbrushBtnFace = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) );
  667. _hbrushBtnHilite = CreateSolidBrush( GetSysColor( COLOR_BTNHIGHLIGHT ) );
  668. _hbrushHilite = CreateSolidBrush( GetSysColor( COLOR_HIGHLIGHT ) );
  669. _hbrushWindow = CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  670. SendMessage( App.StatusBarWindow(), msg, wParam, lParam );
  671. SendMessage( App.ToolBarWindow(), msg, wParam, lParam );
  672. _SendToMDIChildren( msg, wParam, lParam );
  673. lRet = DefFrameProc( hwnd, _hMDIClientWnd, msg, wParam, lParam );
  674. break;
  675. case WM_SYSCOMMAND :
  676. if (wParam == SC_CLOSE)
  677. SendMessage( hwnd, WM_CLOSE, 0, 0 );
  678. else
  679. lRet = DefFrameProc( hwnd, _hMDIClientWnd, msg, wParam, lParam );
  680. break;
  681. case WM_CLOSE :
  682. _SaveProfileData();
  683. _SendToMDIChildren( wmAppClosing, 0, 0 );
  684. DestroyWindow(hwnd);
  685. break;
  686. case WM_ENDSESSION :
  687. _SaveProfileData();
  688. lRet = DefFrameProc(hwnd,_hMDIClientWnd,msg,wParam,lParam);
  689. break;
  690. case WM_CREATE :
  691. {
  692. ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd),WINDOWMENU);
  693. ccs.idFirstChild = IDM_WINDOWCHILD;
  694. _hMDIClientWnd = CreateWindowEx( WS_EX_CLIENTEDGE,
  695. L"mdiclient",0,
  696. WS_CHILD|WS_CLIPCHILDREN,
  697. 0,0,0,0,
  698. hwnd,(HMENU) 0xcac,_hInst,
  699. (LPSTR) &ccs);
  700. ShowWindow(_hMDIClientWnd,SW_SHOW);
  701. PostMessage(hwnd,wmSetState,_iStartupState,0);
  702. break;
  703. }
  704. case wmSetState :
  705. if (_iAppCmdShow != SW_SHOWNORMAL)
  706. ShowWindow(hwnd,_iAppCmdShow);
  707. else if (wParam == 1)
  708. ShowWindow(hwnd,SW_SHOWMAXIMIZED);
  709. else
  710. ShowWindow(hwnd,SW_SHOW);
  711. break;
  712. case WM_DESTROY :
  713. SaveWindowRect( hwnd, CISEARCH_REG_POSITION );
  714. // HtmlHelp( hwnd, _awcHelpFile, HH_CLOSE_ALL, 0 );
  715. PostQuitMessage(0);
  716. break;
  717. case WM_INITMENU :
  718. {
  719. HMENU hmenu = (HMENU) wParam;
  720. // Disable all those that may conditionally be enabled later
  721. EnableMenuItem(hmenu,IDM_EDITUNDO,MF_GRAYED);
  722. EnableMenuItem(hmenu,IDM_EDITCUT,MF_GRAYED);
  723. EnableMenuItem(hmenu,IDM_EDITCOPY,MF_GRAYED);
  724. EnableMenuItem(hmenu,IDM_EDITCLEAR,MF_GRAYED);
  725. EnableMenuItem(hmenu,IDM_EDITPASTE,MF_GRAYED);
  726. EnableMenuItem(hmenu,IDM_BROWSE,MF_GRAYED);
  727. EnableMenuItem(hmenu,IDM_NEXT_HIT,MF_GRAYED);
  728. EnableMenuItem(hmenu,IDM_PREVIOUS_HIT,MF_GRAYED);
  729. EnableMenuItem( hmenu, IDM_DIALECT_1, MF_GRAYED );
  730. EnableMenuItem( hmenu, IDM_DIALECT_2, MF_GRAYED );
  731. EnableMenuItem( hmenu, IDM_DIALECT_3, MF_GRAYED );
  732. EnableMenuItem( hmenu, IDM_LIMIT_10, MF_GRAYED );
  733. EnableMenuItem( hmenu, IDM_LIMIT_300, MF_GRAYED );
  734. EnableMenuItem( hmenu, IDM_LIMIT_NONE, MF_GRAYED );
  735. EnableMenuItem( hmenu, IDM_FIRSTROWS_5, MF_GRAYED );
  736. EnableMenuItem( hmenu, IDM_FIRSTROWS_15, MF_GRAYED );
  737. EnableMenuItem( hmenu, IDM_FIRSTROWS_NONE, MF_GRAYED );
  738. for ( ULONG i = 0; i < cLocaleEntries; i++ )
  739. {
  740. int option = aLocaleEntries[ i ].iMenuOption;
  741. EnableMenuItem( hmenu, option, MF_GRAYED );
  742. }
  743. EnableMenuItem(hmenu,IDM_SEARCH,MF_GRAYED);
  744. EnableMenuItem(hmenu,IDM_SEARCHCLASSDEF,MF_GRAYED);
  745. EnableMenuItem(hmenu,IDM_SEARCHFUNCDEF,MF_GRAYED);
  746. EnableMenuItem(hmenu,IDM_NEWSEARCH,MF_GRAYED);
  747. EnableMenuItem(hmenu,IDM_WRITE_RESULTS,MF_GRAYED);
  748. EnableMenuItem(hmenu,IDM_SCOPE_AND_DEPTH,MF_GRAYED);
  749. EnableMenuItem(hmenu,IDM_FILTER_SCOPE,MF_GRAYED);
  750. EnableMenuItem(hmenu,IDM_DISPLAY_PROPS,MF_GRAYED);
  751. EnableMenuItem(hmenu,IDM_CATALOG_STATUS,MF_GRAYED);
  752. EnableMenuItem(hmenu,IDM_MASTER_MERGE,MF_GRAYED);
  753. EnableMenuItem(hmenu,IDM_FORCE_USE_CI,MF_GRAYED);
  754. EnableMenuItem(hmenu,IDM_EDITCOPYALL,MF_GRAYED);
  755. if (_CountMDIChildren())
  756. uiStatus = MF_ENABLED;
  757. else
  758. uiStatus = MF_GRAYED;
  759. EnableMenuItem(hmenu,IDM_TILE,uiStatus);
  760. EnableMenuItem(hmenu,IDM_CASCADE,uiStatus);
  761. EnableMenuItem(hmenu,IDM_ARRANGE,uiStatus);
  762. EnableMenuItem(hmenu,IDM_CLOSE,uiStatus);
  763. // Enable/Disable Edit Menu options
  764. if (hwndActive = GetFocus())
  765. {
  766. GetClassName(hwndActive,
  767. awcWindowClass,
  768. (sizeof awcWindowClass / sizeof WCHAR) - 1);
  769. if ( (!_wcsicmp(awcWindowClass,L"Edit")) ||
  770. (!_wcsicmp(awcWindowClass,BROWSE_CLASS)) )
  771. {
  772. if (SendMessage (hwndActive,EM_CANUNDO,0,0))
  773. uiStatus = MF_ENABLED;
  774. else
  775. uiStatus = MF_GRAYED;
  776. EnableMenuItem(hmenu,IDM_EDITUNDO,uiStatus);
  777. l = (LONG)SendMessage(hwndActive,EM_GETSEL,0,0);
  778. uiStatus = (HIWORD(l) == LOWORD(l)) ? MF_GRAYED : MF_ENABLED;
  779. EnableMenuItem(hmenu,IDM_EDITCOPY,uiStatus);
  780. if ( _wcsicmp(awcWindowClass,BROWSE_CLASS) )
  781. {
  782. EnableMenuItem(hmenu,IDM_EDITCUT,uiStatus);
  783. EnableMenuItem(hmenu,IDM_EDITCLEAR,uiStatus);
  784. }
  785. uiStatus = MF_GRAYED;
  786. if (OpenClipboard(hwnd))
  787. {
  788. uiFmt = 0;
  789. while ((uiFmt = EnumClipboardFormats(uiFmt)) &&
  790. (uiStatus == MF_GRAYED))
  791. if (uiFmt == CF_UNICODETEXT)
  792. uiStatus = MF_ENABLED;
  793. CloseClipboard();
  794. }
  795. if ( _wcsicmp(awcWindowClass,BROWSE_CLASS) )
  796. EnableMenuItem(hmenu,IDM_EDITPASTE,uiStatus);
  797. }
  798. _SendToActiveMDI(wmInitMenu,wParam,0);
  799. }
  800. break;
  801. }
  802. default:
  803. lRet = DefFrameProc(hwnd,_hMDIClientWnd,msg,wParam,lParam);
  804. break;
  805. }
  806. return lRet;
  807. } //WndProc
  808. void CSearchApp::_InitApplication()
  809. {
  810. WNDCLASS wc;
  811. BOOL bRet = FALSE;
  812. _strTrue.Load( IDS_BOOL_TRUE );
  813. _strFalse.Load( IDS_BOOL_FALSE );
  814. _strAttrib.Load( IDS_ATTRIB_INIT );
  815. _strBlob.Load( IDS_BLOB_FORMAT );
  816. _strYes.Load( IDS_YES );
  817. _strNo.Load( IDS_NO );
  818. _hbrushBtnFace = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) );
  819. _hbrushBtnHilite = CreateSolidBrush( GetSysColor( COLOR_BTNHIGHLIGHT ) );
  820. _hbrushHilite = CreateSolidBrush( GetSysColor( COLOR_HIGHLIGHT ) );
  821. _hbrushWindow = CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  822. // Main Window
  823. wc.style = 0;
  824. wc.lpfnWndProc = MainWndProc;
  825. wc.cbClsExtra = 0;
  826. wc.cbWndExtra = 0;
  827. wc.hInstance = _hInst;
  828. wc.hIcon = LoadIcon(_hInst,L"SearchIcon");
  829. wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  830. wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
  831. wc.lpszMenuName = L"SrchMenu";
  832. wc.lpszClassName = APP_CLASS;
  833. if (RegisterClass(&wc) == 0)
  834. THROW(CException(E_FAIL));
  835. // Search window
  836. wc.hbrBackground = _hbrushBtnFace;
  837. wc.hIcon = LoadIcon(_hInst,L"SearchWindowIcon");
  838. wc.cbWndExtra = sizeof ULONG_PTR;
  839. wc.lpszMenuName = 0;
  840. wc.lpfnWndProc = SearchWndProc;
  841. wc.lpszClassName = SEARCH_CLASS;
  842. if (RegisterClass(&wc) == 0)
  843. THROW(CException(E_FAIL));
  844. // Browse window
  845. wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
  846. wc.hIcon = LoadIcon(_hInst,L"BrowseWindowIcon");
  847. wc.lpfnWndProc = BrowseWndProc;
  848. wc.lpszClassName = BROWSE_CLASS;
  849. wc.style = CS_DBLCLKS;
  850. if ( RegisterClass(&wc) == 0)
  851. THROW(CException(E_FAIL));
  852. // List window
  853. // to be replaced by ListView
  854. wc.style = CS_DBLCLKS;
  855. wc.hIcon = 0;
  856. wc.cbWndExtra = sizeof ULONG_PTR;
  857. wc.lpfnWndProc = ListViewWndProc;
  858. wc.lpszClassName = LIST_VIEW_CLASS;
  859. if (RegisterClass(&wc) == 0)
  860. THROW(CException(E_FAIL));
  861. } //_InitApplication
  862. void CSearchApp::_CreateFonts()
  863. {
  864. memset(&_lfApp,0,sizeof(LOGFONT));
  865. _lfApp.lfWeight = FW_NORMAL;
  866. _lfApp.lfHeight = -11;
  867. _lfApp.lfCharSet = ANSI_CHARSET;
  868. _lfApp.lfOutPrecision = OUT_DEFAULT_PRECIS;
  869. _lfApp.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  870. _lfApp.lfQuality = PROOF_QUALITY;
  871. _lfApp.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
  872. wcscpy( _lfApp.lfFaceName, L"MS SHELL DLG" ); //L"HELV");
  873. _lfBrowse = _lfApp;
  874. _lfBrowse.lfPitchAndFamily = FF_MODERN | FIXED_PITCH;
  875. wcscpy(_lfBrowse.lfFaceName,L"COURIER");
  876. _ReadDefaultFonts();
  877. _hfontApp = CreateFontIndirect((LPLOGFONT) &_lfApp);
  878. _hfontBrowse = CreateFontIndirect((LPLOGFONT) &_lfBrowse);
  879. if (!( _hfontApp && _hfontBrowse ))
  880. THROW(CException(E_FAIL));
  881. } //_CreateFonts
  882. void CSearchApp::_GetPaths()
  883. {
  884. WCHAR awc[MAX_PATH+1],*pc;
  885. GetModuleFileName(_hInst,awc,MAX_PATH);
  886. UINT ui = (UINT) wcslen(awc);
  887. wcscpy(_awcAppPath,awc);
  888. for (pc = _awcAppPath + ui; pc > _awcAppPath; pc--)
  889. {
  890. if (*pc == '/' || *pc == '\\' || *pc == ':')
  891. {
  892. *(++pc) = '\0';
  893. break;
  894. }
  895. }
  896. wcscpy(_awcHelpFile,_awcAppPath);
  897. wcscat(_awcHelpFile,CISEARCH_HELPFILE);
  898. } //_GetPaths
  899. void Usage()
  900. {
  901. SearchError( 0, IDS_ERR_USAGE, L"srch.exe" );
  902. PostQuitMessage( 0 );
  903. } //Usage
  904. void CSearchApp::_InitInstance(LPSTR pcCmdLineArg)
  905. {
  906. LoadNumberFormatInfo( _NumberFmt );
  907. _NumberFmt.NumDigits = 0; // override: none after the decimal point!
  908. LoadNumberFormatInfo( _NumberFmtFloat );
  909. BOOL fScopeSpecified = FALSE;
  910. CLSID clsidCISimpleCommandCreator = CLSID_CISimpleCommandCreator;
  911. HRESULT hr = CoCreateInstance( clsidCISimpleCommandCreator,
  912. NULL,
  913. CLSCTX_INPROC_SERVER,
  914. IID_ISimpleCommandCreator,
  915. _xCmdCreator.GetQIPointer() );
  916. if ( FAILED( hr ) )
  917. THROW( CException( hr ) );
  918. SScopeCatalogMachine defaults;
  919. defaults.fDeep = TRUE;
  920. wcscpy( defaults.awcMachine, L"." );
  921. wcscpy( defaults.awcScope, L"\\" );
  922. defaults.awcCatalog[0] = 0;
  923. ULONG cwcMachine = sizeof defaults.awcMachine / sizeof WCHAR;
  924. ULONG cwcCatalog = sizeof defaults.awcCatalog / sizeof WCHAR;
  925. SCODE sc = LocateCatalogs( L"\\",
  926. 0,
  927. defaults.awcMachine,
  928. &cwcMachine,
  929. defaults.awcCatalog,
  930. &cwcCatalog );
  931. LPWSTR pwcCmdLine = 0;
  932. int argc;
  933. LPWSTR * argv = CommandLineToArgvW( GetCommandLineW(), &argc );
  934. BOOL fNamedArgs = FALSE;
  935. for ( int i = 1; i < argc; i++ )
  936. {
  937. if ( L'-' == argv[i][0] || L'/' == argv[i][0] )
  938. {
  939. fNamedArgs = TRUE;
  940. WCHAR wc = (WCHAR) toupper( (char) argv[i][1] );
  941. if ( ':' != argv[i][2] )
  942. Usage();
  943. if ( 'C' == wc )
  944. {
  945. WCHAR * pwcCatalog = argv[i] + 3;
  946. if ( wcslen( pwcCatalog ) >= MAX_PATH )
  947. Usage();
  948. wcscpy( defaults.awcCatalog, pwcCatalog );
  949. }
  950. else if ( 'M' == wc )
  951. {
  952. WCHAR * pwcMachine = argv[i] + 3;
  953. if ( wcslen( pwcMachine ) >= MAX_PATH )
  954. Usage();
  955. wcscpy( defaults.awcMachine, pwcMachine );
  956. }
  957. else if ( 'P' == wc )
  958. {
  959. WCHAR * pwcScope = argv[i] + 3;
  960. if ( wcslen( pwcScope ) >= MAX_PATH )
  961. Usage();
  962. wcscpy( defaults.awcScope, pwcScope );
  963. }
  964. else if ( 'Q' == wc )
  965. {
  966. WCHAR * pwcQuery = argv[i] + 3;
  967. if ( wcslen( pwcQuery ) >= MAX_PATH )
  968. Usage();
  969. wcscpy( _awcDefaultQuery, pwcQuery );
  970. }
  971. else
  972. Usage();
  973. }
  974. else if ( 0 != pwcCmdLine )
  975. Usage();
  976. else
  977. {
  978. if ( wcslen( argv[i] ) >= MAX_PATH )
  979. Usage();
  980. pwcCmdLine = argv[i];
  981. }
  982. }
  983. if ( pwcCmdLine && pwcCmdLine[0] )
  984. {
  985. if ( fNamedArgs )
  986. Usage();
  987. // make sure drive / unc is '\' terminated
  988. // look for machine;catalog;scope or
  989. // catalog;scope or
  990. // catalog; or
  991. // scope
  992. WCHAR *pwcM = 0; // machine
  993. WCHAR *pwcC = 0; // catalog
  994. WCHAR *pwcS = 0; // scope
  995. WCHAR *pwc = wcschr( pwcCmdLine, L';' );
  996. if ( pwc )
  997. {
  998. *pwc++ = 0;
  999. WCHAR *pwc2 = wcschr( pwc, L';' );
  1000. if ( pwc2 )
  1001. {
  1002. *pwc2++ = 0;
  1003. pwcM = pwcCmdLine;
  1004. pwcC = pwc;
  1005. pwcS = pwc2;
  1006. }
  1007. else
  1008. {
  1009. pwcC = pwcCmdLine;
  1010. pwcS = pwc;
  1011. }
  1012. }
  1013. else
  1014. {
  1015. pwcS = pwcCmdLine;
  1016. }
  1017. if ( *pwcS )
  1018. {
  1019. if ( ( _wcsicmp( pwcS, L"catalog" ) ) &&
  1020. ( _wcsicmp( pwcS, L"\\" ) ) )
  1021. {
  1022. int len = wcslen( pwcS );
  1023. if (pwcS[len - 1] != L'\\')
  1024. {
  1025. pwcS[len] = L'\\';
  1026. pwcS[len + 1] = 0;
  1027. }
  1028. if ( pwcS[0] != '\\' || pwcS[1] != '\\')
  1029. {
  1030. WCHAR *pwcFinal;
  1031. GetFullPathName(pwcS,
  1032. sizeof defaults.awcScope / sizeof WCHAR,
  1033. defaults.awcScope,
  1034. &pwcFinal);
  1035. }
  1036. else wcscpy(defaults.awcScope,pwcS);
  1037. }
  1038. else wcscpy(defaults.awcScope,pwcS);
  1039. }
  1040. else wcscpy(defaults.awcScope,L"\\"); // entire catalog
  1041. if ( pwcM )
  1042. wcscpy( defaults.awcMachine, pwcM );
  1043. if ( pwcC )
  1044. wcscpy( defaults.awcCatalog, pwcC );
  1045. }
  1046. if ( 0 != defaults.awcCatalog[0] )
  1047. fScopeSpecified = TRUE;
  1048. GlobalFree( argv );
  1049. // Populate _xCatList - Note: This doesn't handle distributed queries.
  1050. // But that's OK -- it's just a test tool.
  1051. _xCatList.SetSize( wcslen( defaults.awcMachine ) +
  1052. wcslen( defaults.awcCatalog ) +
  1053. wcslen( defaults.awcScope ) +
  1054. 1 + // depth
  1055. 4 + // delimiters
  1056. 1 // null terminator
  1057. );
  1058. wcscpy( _xCatList.Get(), defaults.awcMachine );
  1059. wcscat( _xCatList.Get(), L"," );
  1060. wcscat( _xCatList.Get(), defaults.awcCatalog );
  1061. wcscat( _xCatList.Get(), L"," );
  1062. wcscat( _xCatList.Get(), defaults.awcScope );
  1063. wcscat( _xCatList.Get(), L"," );
  1064. wcscat( _xCatList.Get(), defaults.fDeep ? L"d" : L"s" );
  1065. wcscat( _xCatList.Get(), L";" );
  1066. _GetPaths();
  1067. _CreateFonts();
  1068. _iStartupState = GetWindowState(TRUE);
  1069. _iMDIStartupState = GetWindowState(FALSE);
  1070. _fToolBarOn = _fToolBarOnINI = (BOOL) GetRegInt(CISEARCH_REG_TOOLBAR,1);
  1071. _fStatusBarOn = _fStatusBarOnINI = (BOOL) GetRegInt(CISEARCH_REG_STATUSBAR,1);
  1072. _fForceUseCI = _fForceUseCIINI = (BOOL) GetRegInt(CISEARCH_REG_FORCEUSECI,1);
  1073. _sortDir = _sortDirINI = (BOOL) GetRegInt(CISEARCH_REG_SORTDIR,SORT_UP);
  1074. _ulDialect = _ulDialectINI = (ULONG) GetRegInt( CISEARCH_REG_DIALECT, ISQLANG_V1 );
  1075. _ulLimit = _ulLimitINI = (ULONG) GetRegInt( CISEARCH_REG_LIMIT, 0 );
  1076. _ulFirstRows = _ulFirstRowsINI = (ULONG) GetRegInt( CISEARCH_REG_FIRSTROWS, 0 );
  1077. DWORD dw = sizeof _awcSortINI / sizeof _awcSortINI[0];
  1078. if (! GetReg( CISEARCH_REG_SORTPROP, _awcSortINI, &dw ) )
  1079. wcscpy( _awcSortINI, DEFAULT_SORT_PROPERTIES );
  1080. wcscpy( _awcSort, _awcSortINI );
  1081. _lcid = _lcidINI = GetRegLCID( CISEARCH_REG_LOCALE, MAKELCID( MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL),
  1082. SORT_DEFAULT ) );
  1083. _hAccTable = LoadAccelerators(_hInst,L"SrchAcc");
  1084. int left,top,right,bottom;
  1085. LoadWindowRect( &left, &top, &right, &bottom, CISEARCH_REG_POSITION );
  1086. CResString strApp( IDS_APPNAME );
  1087. if ((_hAppWnd = CreateWindow(APP_CLASS, strApp.Get(),
  1088. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  1089. left,top,right,bottom,
  1090. 0,0,_hInst,0)) &&
  1091. (_hStatusBarWnd = CreateStatusWindow( SBARS_SIZEGRIP |
  1092. (_fStatusBarOn ? WS_VISIBLE : 0) |
  1093. WS_CHILD,
  1094. L"",
  1095. _hAppWnd,
  1096. 0 ) ) &&
  1097. (_hToolBarWnd = CreateTBar( _hAppWnd, _hInst ) ) )
  1098. {
  1099. UpdateWindow(_hAppWnd);
  1100. if (_fStatusBarOn)
  1101. CheckMenuItem(GetMenu(_hAppWnd),IDM_STATUS_BAR,MF_CHECKED);
  1102. if (_fToolBarOn)
  1103. CheckMenuItem(GetMenu(_hAppWnd),IDM_ICON_BAR,MF_CHECKED);
  1104. if (_fForceUseCI)
  1105. CheckMenuItem(GetMenu(_hAppWnd),IDM_FORCE_USE_CI,MF_CHECKED);
  1106. PostMessage(_hAppWnd,wmOpenCatalog,!fScopeSpecified,0);
  1107. }
  1108. else
  1109. {
  1110. THROW(CException(E_FAIL));
  1111. }
  1112. } //_InitInstance
  1113. HWND CSearchApp::_MakeMDI(
  1114. WCHAR const *pwcTitle,
  1115. WCHAR *pwcClass,
  1116. UINT uiState,
  1117. DWORD dwStyle,
  1118. LPARAM lParam)
  1119. {
  1120. HWND hwndActive;
  1121. if ((hwndActive = GetActiveMDI()) && IsZoomed(hwndActive))
  1122. uiState = 1;
  1123. else if (!_CountMDIChildren())
  1124. uiState = (UINT) _iMDIStartupState;
  1125. MDICREATESTRUCT mcs;
  1126. mcs.szTitle = pwcTitle;
  1127. mcs.szClass = pwcClass;
  1128. mcs.hOwner = _hInst;
  1129. mcs.x = mcs.cx = mcs.y = mcs.cy = CW_USEDEFAULT;
  1130. if (1 == uiState)
  1131. mcs.style = WS_MAXIMIZE;
  1132. else if (2 == uiState)
  1133. mcs.style = WS_MINIMIZE;
  1134. else
  1135. mcs.style = 0;
  1136. mcs.style |= dwStyle;
  1137. mcs.lParam = lParam;
  1138. return (HWND) SendMessage(_hMDIClientWnd,WM_MDICREATE,0,(LPARAM) &mcs);
  1139. } //_MakeMDI
  1140. int CSearchApp::_SaveWindowState(
  1141. BOOL fApp)
  1142. {
  1143. int iState=0,i;
  1144. HWND h;
  1145. WCHAR *pwc,awcBuf[30];
  1146. if (fApp)
  1147. {
  1148. pwc = L"main";
  1149. h = _hAppWnd;
  1150. i = _iStartupState;
  1151. }
  1152. else
  1153. {
  1154. pwc = L"mdi";
  1155. h = GetActiveMDI();
  1156. i = _iMDIStartupState;
  1157. }
  1158. if (h)
  1159. {
  1160. if (IsZoomed(h))
  1161. iState = 1;
  1162. else
  1163. iState = 0;
  1164. int z = fApp ? _iStartupState : _iMDIStartupState;
  1165. if (iState != z)
  1166. {
  1167. if (fApp)
  1168. _iStartupState = iState;
  1169. else
  1170. _iMDIStartupState = iState;
  1171. wcscpy(awcBuf,pwc);
  1172. wcscat(awcBuf,L"-state");
  1173. SetRegInt(awcBuf,iState);
  1174. }
  1175. }
  1176. return iState;
  1177. } //_SaveWindowState
  1178. int CSearchApp::_CountMDIChildren(void)
  1179. {
  1180. HWND hwndActive;
  1181. int cItems = 0;
  1182. if ((_hMDIClientWnd) &&
  1183. (hwndActive = GetActiveMDI()))
  1184. do
  1185. cItems++;
  1186. while (hwndActive = GetNextWindow(hwndActive,GW_HWNDNEXT));
  1187. return cItems;
  1188. } //_CountMDIChildren
  1189. int CSearchApp::_CountMDISearch(void)
  1190. {
  1191. HWND h;
  1192. int cItems = 0;
  1193. if ((_hMDIClientWnd) &&
  1194. (h = GetActiveMDI()))
  1195. {
  1196. do
  1197. {
  1198. if (IsSpecificClass(h,SEARCH_CLASS))
  1199. cItems++;
  1200. }
  1201. while (h = GetNextWindow(h,GW_HWNDNEXT));
  1202. }
  1203. return cItems;
  1204. } //_CountMDISearch
  1205. LRESULT CSearchApp::_SendToMDIChildren(
  1206. UINT msg,
  1207. WPARAM wParam,
  1208. LPARAM lParam)
  1209. {
  1210. HWND h;
  1211. LRESULT l = 0;
  1212. if ((_hMDIClientWnd) &&
  1213. (h = GetActiveMDI()))
  1214. {
  1215. do
  1216. l = SendMessage(h,msg,wParam,lParam);
  1217. while (h = GetNextWindow(h,GW_HWNDNEXT));
  1218. }
  1219. return l;
  1220. } //_SendToMDIChildren
  1221. LRESULT CSearchApp::_SendToSpecificChildren(
  1222. WCHAR *pwcClass,
  1223. UINT msg,
  1224. WPARAM wParam,
  1225. LPARAM lParam)
  1226. {
  1227. HWND h;
  1228. LRESULT l = 0;
  1229. if ((_hMDIClientWnd) &&
  1230. (h = GetActiveMDI()))
  1231. do
  1232. if (IsSpecificClass(h,pwcClass))
  1233. l = SendMessage(h,msg,wParam,lParam);
  1234. while (h = GetNextWindow(h,GW_HWNDNEXT));
  1235. return l;
  1236. } //_SendToSpecificChildren
  1237. LRESULT CSearchApp::_SendToActiveMDI(
  1238. UINT msg,
  1239. WPARAM wParam,
  1240. LPARAM lParam)
  1241. {
  1242. HWND hwndActive;
  1243. LRESULT l = 0;
  1244. if ((_hMDIClientWnd) &&
  1245. (hwndActive = GetActiveMDI()))
  1246. l = SendMessage(hwndActive,msg,wParam,lParam);
  1247. return l;
  1248. } //_SendToActiveMDI
  1249. void CSearchApp::_ShowHelp(UINT uiCmnd,DWORD dw)
  1250. {
  1251. if (!HtmlHelp(_hAppWnd,_awcHelpFile,uiCmnd,dw))
  1252. SearchError(_hAppWnd,IDS_ERR_CANT_OPEN_HELP,_awcHelpFile);
  1253. } //_ShowHelp
  1254. const SLocaleEntry aLocaleEntries[] =
  1255. {
  1256. { IDM_LOCALE_NEUTRAL,
  1257. MAKELCID( MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT ) },
  1258. { IDM_LOCALE_CHINESE_TRADITIONAL,
  1259. MAKELCID( MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), SORT_DEFAULT ) },
  1260. { IDM_LOCALE_CHINESE_SIMPLIFIED,
  1261. MAKELCID( MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_DEFAULT ) },
  1262. { IDM_LOCALE_CHINESE_HONGKONG,
  1263. MAKELCID( MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_HONGKONG), SORT_DEFAULT ) },
  1264. { IDM_LOCALE_CHINESE_SINGAPORE,
  1265. MAKELCID( MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE), SORT_DEFAULT ) },
  1266. { IDM_LOCALE_CHINESE_MACAU,
  1267. MAKELCID( MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_MACAU), SORT_DEFAULT ) },
  1268. { IDM_LOCALE_DUTCH_DUTCH,
  1269. MAKELCID( MAKELANGID( LANG_DUTCH, SUBLANG_DUTCH), SORT_DEFAULT ) },
  1270. { IDM_LOCALE_ENGLISH_CAN,
  1271. MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_CAN), SORT_DEFAULT ) },
  1272. { IDM_LOCALE_ENGLISH_US,
  1273. MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT ) },
  1274. { IDM_LOCALE_ENGLISH_UK,
  1275. MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_UK), SORT_DEFAULT ) },
  1276. { IDM_LOCALE_FINNISH_DEFAULT,
  1277. MAKELCID( MAKELANGID( LANG_FINNISH, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1278. { IDM_LOCALE_FARSI_DEFAULT,
  1279. MAKELCID( MAKELANGID( LANG_FARSI, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1280. { IDM_LOCALE_FRENCH_FRENCH,
  1281. MAKELCID( MAKELANGID( LANG_FRENCH, SUBLANG_FRENCH), SORT_DEFAULT ) },
  1282. { IDM_LOCALE_FRENCH_CANADIAN,
  1283. MAKELCID( MAKELANGID( LANG_FRENCH, SUBLANG_FRENCH_CANADIAN), SORT_DEFAULT ) },
  1284. { IDM_LOCALE_GERMAN_GERMAN,
  1285. MAKELCID( MAKELANGID( LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT ) },
  1286. { IDM_LOCALE_GREEK_DEFAULT,
  1287. MAKELCID( MAKELANGID( LANG_GREEK, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1288. { IDM_LOCALE_HEBREW_DEFAULT,
  1289. MAKELCID( MAKELANGID( LANG_HEBREW, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1290. { IDM_LOCALE_HINDI_DEFAULT,
  1291. MAKELCID( MAKELANGID( LANG_HINDI, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1292. { IDM_LOCALE_ITALIAN_ITALIAN,
  1293. MAKELCID( MAKELANGID( LANG_ITALIAN, SUBLANG_ITALIAN), SORT_DEFAULT ) },
  1294. { IDM_LOCALE_JAPANESE_DEFAULT,
  1295. MAKELCID( MAKELANGID( LANG_JAPANESE, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1296. { IDM_LOCALE_KOREAN_KOREAN,
  1297. MAKELCID( MAKELANGID( LANG_KOREAN, SUBLANG_KOREAN), SORT_DEFAULT ) },
  1298. // { IDM_LOCALE_KOREAN_JOHAB,
  1299. // MAKELCID( MAKELANGID( LANG_KOREAN, SUBLANG_KOREAN_JOHAB), SORT_DEFAULT ) },
  1300. { IDM_LOCALE_POLISH_DEFAULT,
  1301. MAKELCID( MAKELANGID( LANG_POLISH, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1302. { IDM_LOCALE_ROMANIAN_DEFAULT,
  1303. MAKELCID( MAKELANGID( LANG_ROMANIAN, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1304. { IDM_LOCALE_RUSSIAN_DEFAULT,
  1305. MAKELCID( MAKELANGID( LANG_RUSSIAN, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1306. { IDM_LOCALE_SPANISH_CASTILIAN,
  1307. MAKELCID( MAKELANGID( LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT ) },
  1308. { IDM_LOCALE_SPANISH_MEXICAN,
  1309. MAKELCID( MAKELANGID( LANG_SPANISH, SUBLANG_SPANISH_MEXICAN), SORT_DEFAULT ) },
  1310. { IDM_LOCALE_SPANISH_MODERN,
  1311. MAKELCID( MAKELANGID( LANG_SPANISH, SUBLANG_SPANISH_MODERN), SORT_DEFAULT ) },
  1312. { IDM_LOCALE_SWAHILI_DEFAULT,
  1313. MAKELCID( MAKELANGID( LANG_SWAHILI, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1314. { IDM_LOCALE_SWEDISH_DEFAULT,
  1315. MAKELCID( MAKELANGID( LANG_SWEDISH, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1316. { IDM_LOCALE_THAI_DEFAULT,
  1317. MAKELCID( MAKELANGID( LANG_THAI, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1318. { IDM_LOCALE_TURKISH_DEFAULT,
  1319. MAKELCID( MAKELANGID( LANG_TURKISH, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1320. { IDM_LOCALE_UKRAINIAN_DEFAULT,
  1321. MAKELCID( MAKELANGID( LANG_UKRAINIAN, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1322. { IDM_LOCALE_VIETNAMESE_DEFAULT,
  1323. MAKELCID( MAKELANGID( LANG_VIETNAMESE, SUBLANG_DEFAULT), SORT_DEFAULT ) },
  1324. };
  1325. const ULONG cLocaleEntries = sizeof aLocaleEntries / sizeof SLocaleEntry;