CP_Main.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. // CP_Main.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "MainFrm.h"
  6. #include "Misc.h"
  7. #include "SelectDB.h"
  8. #include ".\cp_main.h"
  9. #include "server.h"
  10. #include "Client.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // The one and only CCP_MainApp object
  18. CCP_MainApp theApp;
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CCP_MainApp
  21. BEGIN_MESSAGE_MAP(CCP_MainApp, CWinApp)
  22. //{{AFX_MSG_MAP(CCP_MainApp)
  23. // NOTE - the ClassWizard will add and remove mapping macros here.
  24. // DO NOT EDIT what you see in these blocks of generated code!
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CCP_MainApp construction
  29. CCP_MainApp::CCP_MainApp()
  30. {
  31. m_bAppRunning = false;
  32. m_bAppExiting = false;
  33. m_MainhWnd = NULL;
  34. m_pMainFrame = NULL;
  35. m_bShowingQuickPaste = false;
  36. m_bShowingOptions = false;
  37. m_bShowCopyProperties = false;
  38. m_bRemoveOldEntriesPending = false;
  39. m_IC_bCopy = false;
  40. m_GroupDefaultID = 0;
  41. m_GroupID = 0;
  42. m_GroupParentID = 0;
  43. m_GroupText = "History";
  44. m_FocusID = -1; // -1 == keep previous position, 0 == go to latest ID
  45. m_pDatabase = NULL;
  46. // Place all significant initialization in InitInstance
  47. m_bAsynchronousRefreshView = true;
  48. ::InitializeCriticalSection(&m_CriticalSection);
  49. m_hHookDll = NULL;
  50. m_MonitorFocusChanges = NULL;
  51. m_StopMonitoringFocusChanges = NULL;
  52. m_GetCurrentFocus = NULL;
  53. }
  54. CCP_MainApp::~CCP_MainApp()
  55. {
  56. if(m_hHookDll)
  57. FreeLibrary(m_hHookDll);
  58. ::DeleteCriticalSection(&m_CriticalSection);
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CCP_MainApp initialization
  62. BOOL CCP_MainApp::InitInstance()
  63. {
  64. LOG("InitInstance");
  65. AfxEnableControlContainer();
  66. m_hMutex = CreateMutex(NULL, FALSE, "Ditto Is Now Running");
  67. DWORD dwError = GetLastError();
  68. if(dwError == ERROR_ALREADY_EXISTS)
  69. {
  70. HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
  71. if(hWnd)
  72. ::SendMessage(hWnd, WM_SHOW_TRAY_ICON, TRUE, TRUE);
  73. return TRUE;
  74. }
  75. AfxOleInit();
  76. m_cfIgnoreClipboard = ::RegisterClipboardFormat("Clipboard Viewer Ignore");
  77. int nRet = CheckDBExists(CGetSetOptions::GetDBPath());
  78. if(nRet == FALSE)
  79. {
  80. AfxMessageBox("Error Opening Database.");
  81. return TRUE;
  82. }
  83. else if(nRet == ERROR_OPENING_DATABASE)
  84. {
  85. CString cs;
  86. cs.Format("Unable to initialize DAO/Jet db engine.\nSelect YES to download DAO from http://ditto-cp.sourceforge.net/dao_setup.exe\n\nRestart Ditto after installation of DAO.");
  87. if(MessageBox(NULL, cs, "Ditto", MB_YESNO) == IDYES)
  88. {
  89. ShellExecute(NULL, "open", "http://ditto-cp.sourceforge.net/dao_setup.exe", "", "", SW_SHOW);
  90. }
  91. return TRUE;
  92. }
  93. CMainFrame* pFrame = new CMainFrame;
  94. m_pMainWnd = m_pMainFrame = pFrame;
  95. // prevent no one having focus on startup
  96. TargetActiveWindow();
  97. pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
  98. pFrame->ShowWindow(SW_SHOW);
  99. pFrame->UpdateWindow();
  100. // prevent no one having focus on startup
  101. ReleaseFocus();
  102. return TRUE;
  103. }
  104. void CCP_MainApp::AfterMainCreate()
  105. {
  106. m_MainhWnd = m_pMainFrame->m_hWnd;
  107. ASSERT( ::IsWindow(m_MainhWnd) );
  108. g_Opt.SetMainHWND((long)m_MainhWnd);
  109. g_HotKeys.Init( m_MainhWnd );
  110. // create hotkeys here. They are automatically deleted on exit
  111. m_pDittoHotKey = new CHotKey("DittoHotKey",704); //704 is ctrl-tilda
  112. m_pCopyHotKey = new CHotKey("CopyHotKey");
  113. m_pPosOne = new CHotKey("Position1", 0, true);
  114. m_pPosTwo = new CHotKey("Position2", 0, true);
  115. m_pPosThree = new CHotKey("Position3", 0, true);
  116. m_pPosFour = new CHotKey("Position4", 0, true);
  117. m_pPosFive = new CHotKey("Position5", 0, true);
  118. m_pPosSix = new CHotKey("Position6", 0, true);
  119. m_pPosSeven = new CHotKey("Position7", 0, true);
  120. m_pPosEight = new CHotKey("Position8", 0, true);
  121. m_pPosNine = new CHotKey("Position9", 0, true);
  122. m_pPosTen = new CHotKey("Position10", 0, true);
  123. g_HotKeys.RegisterAll();
  124. // CopyThread initialization
  125. StartCopyThread();
  126. AfxBeginThread(MTServerThread, m_MainhWnd);
  127. m_bAppRunning = true;
  128. m_pcpSendRecieveError = NULL;
  129. }
  130. void CCP_MainApp::BeforeMainClose()
  131. {
  132. ASSERT( m_bAppRunning && !m_bAppExiting );
  133. m_bAppRunning = false;
  134. m_bAppExiting = true;
  135. g_HotKeys.UnregisterAll();
  136. StopCopyThread();
  137. }
  138. /*
  139. Re: Targeting the previous focus window
  140. We usually gain focus after the following messages:
  141. keyboard: WM_KEYUP(0x0101),WM_CHAR(0x0102),WM_HOTKEY(0x0312)
  142. mouse: WM_MOUSEFIRST(0x0200),WM_MOUSEMOVE(0x0200),WM_LBUTTONDOWN(0x0201)
  143. CMainFrame::PreTranslateMessage is used to intercept messages before
  144. they are processed (before we are actually given focus) in order to
  145. save the previous window that had focus.
  146. - It currently just handles "activating" mouse messages when showing.
  147. ShowQPasteWnd also has a call to "TargetActiveWindow" which handles
  148. finding the Target on hotkey activation.
  149. This works well for most window switching (mouse or hotkey), but does
  150. not work well for <Alt>-<Tab> or other window switching applications
  151. (e.g. the taskbar tray), since the previous window was only a means to
  152. switching and not the target itself.
  153. - one solution might be to always monitor the current foreground
  154. window using system hooks or a short (e.g. 1 sec) timer... though this
  155. *might* be cpu intensive (slow). I'm currently looking into using
  156. WH_CBT system hooks in a separate dll (see: robpitt's
  157. http://website.lineone.net/~codebox/focuslog.zip).
  158. */
  159. bool CCP_MainApp::TargetActiveWindow()
  160. {
  161. if(g_Opt.m_bUseHookDllForFocus)
  162. return true;
  163. HWND hOld = m_hTargetWnd;
  164. HWND hNew = ::GetForegroundWindow();
  165. if( hNew == m_hTargetWnd || !::IsWindow(hNew) || IsAppWnd(hNew) )
  166. return false;
  167. m_hTargetWnd = hNew;
  168. if( QPasteWnd() )
  169. QPasteWnd()->UpdateStatus(true);
  170. // Tracking / Debugging
  171. /*
  172. LOG( StrF(
  173. "Target Changed" \
  174. "\n\tOld = 0x%08x: \"%s\"" \
  175. "\n\tNew = 0x%08x: \"%s\"\n",
  176. hOld, (LPCTSTR) GetWndText(hOld),
  177. hNew, (LPCTSTR) GetWndText(hNew) ) );
  178. */
  179. return true;
  180. }
  181. bool CCP_MainApp::ActivateTarget()
  182. {
  183. if( !::IsWindow(m_hTargetWnd) || m_hTargetWnd == ::GetForegroundWindow() )
  184. return false;
  185. ::SetForegroundWindow( m_hTargetWnd );
  186. // ::SetFocus( m_hTargetWnd );
  187. return true;
  188. }
  189. bool CCP_MainApp::ReleaseFocus()
  190. {
  191. if( IsAppWnd(::GetForegroundWindow()) )
  192. return ActivateTarget();
  193. return false;
  194. }
  195. // sends Ctrl-V to the TargetWnd
  196. void CCP_MainApp::SendPaste(bool bActivateTarget)
  197. {
  198. if(bActivateTarget && !ActivateTarget())
  199. {
  200. SetStatus("SendPaste FAILED!",TRUE);
  201. return;
  202. }
  203. keybd_event(VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
  204. keybd_event('V', 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
  205. keybd_event('V', 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  206. keybd_event(VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  207. }
  208. // CopyThread
  209. void CCP_MainApp::StartCopyThread()
  210. {
  211. ASSERT( m_MainhWnd );
  212. CClipTypes* pTypes = LoadTypesFromDB();
  213. // initialize to:
  214. // - m_MainhWnd = send WM_CLIPBOARD_COPIED messages to m_MainhWnd
  215. // - true = use Asynchronous communication (PostMessage)
  216. // - true = enable copying on clipboard changes
  217. // - pTypes = the supported types to use
  218. m_CopyThread.Init( CCopyConfig( m_MainhWnd, true, true, pTypes ) );
  219. VERIFY( m_CopyThread.CreateThread(CREATE_SUSPENDED) );
  220. m_CopyThread.ResumeThread();
  221. }
  222. void CCP_MainApp::StopCopyThread()
  223. {
  224. EnableCbCopy(false);
  225. m_CopyThread.Quit();
  226. SaveCopyClips();
  227. }
  228. // returns the current Clipboard Viewer Connect state (though it might not yet
  229. // be actually connected -- check IsClipboardViewerConnected())
  230. bool CCP_MainApp::ToggleConnectCV()
  231. {
  232. bool bConnect = !GetConnectCV();
  233. SetConnectCV( bConnect );
  234. if( bConnect )
  235. m_pMainFrame->m_TrayIcon.SetIcon( IDR_MAINFRAME );
  236. else
  237. m_pMainFrame->m_TrayIcon.SetIcon( IDI_DITTO_NOCOPYCB );
  238. return bConnect;
  239. }
  240. // Sets a menu entry according to the current Clipboard Viewer Connection status
  241. // - the menu text indicates the available command (opposite the current state)
  242. // - a check mark appears in the rare cases that the menu text actually represents
  243. // the current state, e.g. if we are supposed to be connected, but we somehow
  244. // lose that connection, "Disconnect from Clipboard" will have a check next to it.
  245. void CCP_MainApp::UpdateMenuConnectCV( CMenu* pMenu, UINT nMenuID )
  246. {
  247. if( pMenu == NULL )
  248. return;
  249. bool bConnect = theApp.GetConnectCV();
  250. bool bIsConnected = theApp.IsClipboardViewerConnected();
  251. CString cs;
  252. if( bConnect )
  253. {
  254. cs = "Disconnect from Clipboard";
  255. pMenu->ModifyMenu(nMenuID, MF_BYCOMMAND, nMenuID, cs);
  256. // add a check mark if we are still disconnected (temporarily)
  257. if( !bIsConnected )
  258. pMenu->CheckMenuItem(nMenuID, MF_CHECKED);
  259. else
  260. pMenu->CheckMenuItem(nMenuID, MF_UNCHECKED);
  261. }
  262. else // CV is disconnected, so provide the option of connecting
  263. {
  264. cs = "Connect to Clipboard";
  265. pMenu->ModifyMenu(nMenuID, MF_BYCOMMAND, nMenuID, cs);
  266. // add a check mark if we are still connected (temporarily)
  267. if( bIsConnected )
  268. pMenu->CheckMenuItem(nMenuID, MF_CHECKED);
  269. else
  270. pMenu->CheckMenuItem(nMenuID, MF_UNCHECKED);
  271. }
  272. }
  273. // Allocates a new CClipTypes
  274. CClipTypes* CCP_MainApp::LoadTypesFromDB()
  275. {
  276. CClipTypes* pTypes = new CClipTypes;
  277. try
  278. {
  279. CTypesTable recset;
  280. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
  281. while(!recset.IsEOF())
  282. {
  283. pTypes->Add( GetFormatID(recset.m_TypeText) );
  284. recset.MoveNext();
  285. }
  286. recset.Close();
  287. }
  288. catch(CDaoException* e)
  289. {
  290. ASSERT(FALSE);
  291. e->Delete();
  292. }
  293. if( pTypes->GetSize() <= 0 )
  294. {
  295. pTypes->Add(CF_TEXT);
  296. pTypes->Add(RegisterClipboardFormat(CF_RTF));
  297. }
  298. return pTypes;
  299. }
  300. void CCP_MainApp::ReloadTypes()
  301. {
  302. CClipTypes* pTypes = LoadTypesFromDB();
  303. if( pTypes )
  304. m_CopyThread.SetSupportedTypes( pTypes );
  305. }
  306. long CCP_MainApp::SaveCopyClips()
  307. {
  308. long lID = 0;
  309. int count;
  310. CClipList* pClips = m_CopyThread.GetClips(); // we now own pClips
  311. if( !pClips )
  312. return 0;
  313. CClipList* pCopyOfClips = NULL;
  314. if(g_Opt.m_lAutoSendClientCount > 0)
  315. {
  316. //The thread will free these
  317. pCopyOfClips = new CClipList;
  318. if(pCopyOfClips != NULL)
  319. {
  320. *pCopyOfClips = *pClips;
  321. }
  322. }
  323. count = pClips->AddToDB( true );
  324. if( count > 0 )
  325. {
  326. lID = pClips->GetTail()->m_ID;
  327. OnCopyCompleted(lID, count);
  328. if(g_Opt.m_lAutoSendClientCount > 0)
  329. {
  330. AfxBeginThread(SendClientThread, pCopyOfClips);
  331. }
  332. }
  333. delete pClips;
  334. return lID;
  335. }
  336. void CCP_MainApp::RefreshView()
  337. {
  338. if( m_bShowingQuickPaste )
  339. {
  340. ASSERT( QPasteWnd() );
  341. if(m_bAsynchronousRefreshView)
  342. QPasteWnd()->PostMessage(WM_REFRESH_VIEW);
  343. else
  344. QPasteWnd()->SendMessage(WM_REFRESH_VIEW);
  345. }
  346. }
  347. void CCP_MainApp::OnPasteCompleted()
  348. {
  349. // the list only changes if UpdateTimeOnPaste is true (updated time)
  350. if( g_Opt.m_bUpdateTimeOnPaste )
  351. RefreshView();
  352. }
  353. void CCP_MainApp::OnCopyCompleted(long lLastID, int count)
  354. {
  355. if( count <= 0 )
  356. return;
  357. // queue a message to RemoveOldEntries
  358. Delayed_RemoveOldEntries( 60000 );
  359. // update copy statistics
  360. CGetSetOptions::SetTripCopyCount( -count );
  361. CGetSetOptions::SetTotalCopyCount( -count );
  362. // if we are in the History group, focus on the latest copy
  363. if( m_GroupID == 0 )
  364. m_FocusID = 0;
  365. RefreshView();
  366. ShowCopyProperties( lLastID );
  367. }
  368. // Internal Clipboard for cut/copy/paste items between Groups
  369. // if NULL, this uses the current QPaste selection
  370. void CCP_MainApp::IC_Cut( ARRAY* pIDs )
  371. {
  372. if( pIDs == NULL )
  373. {
  374. if( QPasteWnd() )
  375. QPasteWnd()->m_lstHeader.GetSelectionItemData( m_IC_IDs );
  376. else
  377. m_IC_IDs.SetSize(0);
  378. }
  379. else
  380. m_IC_IDs.Copy( *pIDs );
  381. m_IC_bCopy = false;
  382. if( QPasteWnd() )
  383. QPasteWnd()->UpdateStatus();
  384. }
  385. // if NULL, this uses the current QPaste selection
  386. void CCP_MainApp::IC_Copy( ARRAY* pIDs )
  387. {
  388. if( pIDs == NULL )
  389. {
  390. if( QPasteWnd() )
  391. QPasteWnd()->m_lstHeader.GetSelectionItemData( m_IC_IDs );
  392. else
  393. m_IC_IDs.SetSize(0);
  394. }
  395. else
  396. m_IC_IDs.Copy( *pIDs );
  397. m_IC_bCopy = true;
  398. if( QPasteWnd() )
  399. QPasteWnd()->UpdateStatus();
  400. }
  401. void CCP_MainApp::IC_Paste()
  402. {
  403. if( m_IC_IDs.GetSize() <= 0 )
  404. return;
  405. if( m_IC_bCopy )
  406. m_IC_IDs.CopyTo( GetValidGroupID() );
  407. else // Move
  408. m_IC_IDs.MoveTo( GetValidGroupID() );
  409. // don't process the same items twice.
  410. m_IC_IDs.SetSize(0);
  411. RefreshView();
  412. }
  413. // Groups
  414. BOOL CCP_MainApp::EnterGroupID( long lID )
  415. {
  416. BOOL bResult = FALSE;
  417. if( m_GroupID == lID )
  418. return TRUE;
  419. // if we are switching to the parent, focus on the previous group
  420. if( m_GroupParentID == lID && m_GroupID > 0 )
  421. m_FocusID = m_GroupID;
  422. switch( lID )
  423. {
  424. case 0: // History Group "ID"
  425. m_GroupID = 0;
  426. m_GroupParentID = 0;
  427. m_GroupText = "History";
  428. bResult = TRUE;
  429. break;
  430. case -1: // All Groups "ID"
  431. m_GroupID = -1;
  432. m_GroupParentID = 0;
  433. m_GroupText = "Groups";
  434. bResult = TRUE;
  435. break;
  436. default: // Normal Group
  437. try
  438. {
  439. CMainTable recs;
  440. COleVariant varKey( lID, VT_I4 );
  441. recs.Open( dbOpenTable, "Main" );
  442. recs.SetCurrentIndex("lID");
  443. // Find first record whose [lID] field == lID
  444. if( recs.Seek(_T("="), &varKey) && recs.m_bIsGroup )
  445. {
  446. m_GroupID = recs.m_lID;
  447. m_GroupParentID = recs.m_lParentID;
  448. // if( m_GroupParentID == 0 )
  449. // m_GroupParentID = -1; // back out into "all top-level groups" list.
  450. m_GroupText = recs.m_strText;
  451. bResult = TRUE;
  452. }
  453. recs.Close();
  454. }
  455. CATCHDAO
  456. break;
  457. }
  458. if( bResult )
  459. {
  460. theApp.RefreshView();
  461. if( QPasteWnd() )
  462. QPasteWnd()->UpdateStatus( true );
  463. }
  464. return bResult;
  465. }
  466. // returns a usable group id (not negative)
  467. long CCP_MainApp::GetValidGroupID()
  468. {
  469. if( m_GroupID <= 0 )
  470. return 0;
  471. return m_GroupID;
  472. }
  473. // sets a valid id
  474. void CCP_MainApp::SetGroupDefaultID( long lID )
  475. {
  476. if( m_GroupDefaultID == lID )
  477. return;
  478. if( lID <= 0 )
  479. m_GroupDefaultID = 0;
  480. else
  481. m_GroupDefaultID = lID;
  482. if( QPasteWnd() )
  483. QPasteWnd()->UpdateStatus();
  484. }
  485. // Window States
  486. void CCP_MainApp::SetStatus( const char* status, bool bRepaintImmediately )
  487. {
  488. m_Status = status;
  489. if( QPasteWnd() )
  490. QPasteWnd()->UpdateStatus( bRepaintImmediately );
  491. }
  492. void CCP_MainApp::ShowPersistent( bool bVal )
  493. {
  494. g_Opt.SetShowPersistent( bVal );
  495. // give some visual indication
  496. if( m_bShowingQuickPaste )
  497. {
  498. ASSERT( QPasteWnd() );
  499. QPasteWnd()->SetCaptionColorActive(!g_Opt.m_bShowPersistent, theApp.GetConnectCV());
  500. QPasteWnd()->RefreshNc();
  501. }
  502. }
  503. void CCP_MainApp::ShowCopyProperties( long lID )
  504. {
  505. if( m_bShowCopyProperties && lID > 0 )
  506. {
  507. HWND hWndFocus = ::GetForegroundWindow();
  508. m_bShowCopyProperties = false;
  509. ::SendMessage(m_MainhWnd, WM_COPYPROPERTIES, lID, 0); // modal
  510. ::SetForegroundWindow(hWndFocus);
  511. }
  512. }
  513. void CCP_MainApp::Delayed_RemoveOldEntries( UINT delay )
  514. {
  515. if( !m_bRemoveOldEntriesPending )
  516. {
  517. m_bRemoveOldEntriesPending = true;
  518. ((CMainFrame*)theApp.m_pMainWnd)->SetTimer( REMOVE_OLD_ENTRIES_TIMER, delay, 0 );
  519. }
  520. }
  521. /////////////////////////////////////////////////////////////////////////////
  522. // CCP_MainApp message handlers
  523. int CCP_MainApp::ExitInstance()
  524. {
  525. LOG("ExitInstance");
  526. if(CGetSetOptions::GetCompactAndRepairOnExit())
  527. CompactDatabase();
  528. CloseDB();
  529. return CWinApp::ExitInstance();
  530. }
  531. CDaoDatabase* CCP_MainApp::EnsureOpenDB(CString csName)
  532. {
  533. try
  534. {
  535. if(!m_pDatabase)
  536. m_pDatabase = new CDaoDatabase;
  537. if(!m_pDatabase->IsOpen())
  538. {
  539. if(csName == "")
  540. m_pDatabase->Open(GetDBName());
  541. else
  542. m_pDatabase->Open(csName);
  543. }
  544. if(m_pMainWnd)
  545. ((CMainFrame *)m_pMainWnd)->ResetKillDBTimer();
  546. }
  547. CATCHDAO
  548. return m_pDatabase;
  549. }
  550. BOOL CCP_MainApp::CloseDB()
  551. {
  552. if(m_pDatabase)
  553. {
  554. if(m_pDatabase->IsOpen())
  555. m_pDatabase->Close();
  556. delete m_pDatabase;
  557. m_pDatabase = NULL;
  558. }
  559. return TRUE;
  560. }
  561. // return TRUE if there is more idle processing to do
  562. BOOL CCP_MainApp::OnIdle(LONG lCount)
  563. {
  564. // let winapp handle its idle processing
  565. if( CWinApp::OnIdle(lCount) )
  566. return TRUE;
  567. return FALSE;
  568. }
  569. CString CCP_MainApp::GetTargetName()
  570. {
  571. char cWindowText[100];
  572. HWND hParent = m_hTargetWnd;
  573. ::GetWindowText(hParent, cWindowText, 100);
  574. while(strlen(cWindowText) <= 0)
  575. {
  576. hParent = ::GetParent(hParent);
  577. if(hParent == NULL)
  578. break;
  579. ::GetWindowText(hParent, cWindowText, 100);
  580. }
  581. return cWindowText;
  582. }
  583. void CCP_MainApp::SetConnectCV(bool bConnect)
  584. {
  585. m_CopyThread.SetConnectCV(bConnect);
  586. if(QPasteWnd())
  587. {
  588. QPasteWnd()->SetCaptionColorActive(!g_Opt.m_bShowPersistent, theApp.GetConnectCV());
  589. QPasteWnd()->RefreshNc();
  590. }
  591. }