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.

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