CP_Main.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CCP_MainApp
  15. BEGIN_MESSAGE_MAP(CCP_MainApp, CWinApp)
  16. //{{AFX_MSG_MAP(CCP_MainApp)
  17. // NOTE - the ClassWizard will add and remove mapping macros here.
  18. // DO NOT EDIT what you see in these blocks of generated code!
  19. //}}AFX_MSG_MAP
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CCP_MainApp construction
  23. CCP_MainApp::CCP_MainApp()
  24. {
  25. // TODO: add construction code here,
  26. // Place all significant initialization in InitInstance
  27. }
  28. /////////////////////////////////////////////////////////////////////////////
  29. // The one and only CCP_MainApp object
  30. CCP_MainApp theApp;
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CCP_MainApp initialization
  33. BOOL CCP_MainApp::InitInstance()
  34. {
  35. AfxEnableControlContainer();
  36. m_hMutex = CreateMutex(NULL, FALSE, "Ditto Is Now Running");
  37. DWORD dwError = GetLastError();
  38. if(dwError == ERROR_ALREADY_EXISTS)
  39. {
  40. HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
  41. if(hWnd)
  42. ::SendMessage(hWnd, WM_SHOW_TRAY_ICON, TRUE, TRUE);
  43. return TRUE;
  44. }
  45. m_bShowingOptions = false;
  46. m_bShowingQuickPaste = false;
  47. m_bHandleClipboardDataChange = true;
  48. m_bReloadTypes = true;
  49. m_atomHotKey = GlobalAddAtom(HK_ACTIVATE);
  50. m_atomNamedCopy = GlobalAddAtom(HK_NAMED_COPY);
  51. m_MainhWnd = NULL;
  52. m_pDatabase = NULL;
  53. ShowCopyProperties = NULL;
  54. if(CheckDBExists(CGetSetOptions::GetDBPath()) == FALSE)
  55. {
  56. AfxMessageBox("Error Opening Database.");
  57. return TRUE;
  58. }
  59. AfxOleInit();
  60. CMainFrame* pFrame = new CMainFrame;
  61. m_pMainWnd = pFrame;
  62. pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
  63. pFrame->ShowWindow(SW_SHOW);
  64. pFrame->UpdateWindow();
  65. return TRUE;
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CCP_MainApp message handlers
  69. int CCP_MainApp::ExitInstance()
  70. {
  71. if(CGetSetOptions::GetCompactAndRepairOnExit())
  72. CompactDatabase();
  73. CloseDB();
  74. return CWinApp::ExitInstance();
  75. }
  76. CDaoDatabase* CCP_MainApp::EnsureOpenDB(CString csName)
  77. {
  78. if(!m_pDatabase)
  79. m_pDatabase = new CDaoDatabase;
  80. if(!m_pDatabase->IsOpen())
  81. {
  82. if(csName == "")
  83. m_pDatabase->Open(GetDBName());
  84. else
  85. m_pDatabase->Open(csName);
  86. }
  87. if(m_pMainWnd)
  88. ((CMainFrame *)m_pMainWnd)->ResetKillDBTimer();
  89. return m_pDatabase;
  90. }
  91. BOOL CCP_MainApp::CloseDB()
  92. {
  93. if(m_pDatabase)
  94. {
  95. if(m_pDatabase->IsOpen())
  96. m_pDatabase->Close();
  97. delete m_pDatabase;
  98. m_pDatabase = NULL;
  99. }
  100. return TRUE;
  101. }