MainFrm.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "MainFrm.h"
  6. #include "afxole.h"
  7. #include "Misc.h"
  8. #include "CopyProperties.h"
  9. #include "InternetUpdate.h"
  10. #include ".\mainfrm.h"
  11. #include "HyperLink.h"
  12. #include "tinyxml\tinyxml.h"
  13. #include "Path.h"
  14. #include "DittoCopyBuffer.h"
  15. #include "HotKeys.h"
  16. #include "GlobalClips.h"
  17. #include "OptionsSheet.h"
  18. #include "DeleteClipData.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #define WM_ICON_NOTIFY WM_APP+10
  25. #define MYWM_NOTIFYICON (WM_USER+1)
  26. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  27. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  28. //{{AFX_MSG_MAP(CMainFrame)
  29. ON_WM_CREATE()
  30. ON_COMMAND(ID_FIRST_OPTION, OnFirstOption)
  31. ON_COMMAND(ID_FIRST_EXIT, OnFirstExit)
  32. ON_WM_TIMER()
  33. ON_COMMAND(ID_FIRST_SHOWQUICKPASTE, OnFirstShowquickpaste)
  34. ON_COMMAND(ID_FIRST_TOGGLECONNECTCV, OnFirstToggleConnectCV)
  35. ON_UPDATE_COMMAND_UI(ID_FIRST_TOGGLECONNECTCV, OnUpdateFirstToggleConnectCV)
  36. ON_COMMAND(ID_FIRST_HELP, OnFirstHelp)
  37. //}}AFX_MSG_MAP
  38. ON_MESSAGE(WM_HOTKEY, OnHotKey)
  39. ON_MESSAGE(WM_SHOW_TRAY_ICON, OnShowTrayIcon)
  40. ON_MESSAGE(WM_CLIPBOARD_COPIED, OnClipboardCopied)
  41. ON_WM_CLOSE()
  42. ON_MESSAGE(WM_ADD_TO_DATABASE_FROM_SOCKET, OnAddToDatabaseFromSocket)
  43. ON_MESSAGE(WM_SEND_RECIEVE_ERROR, OnErrorOnSendRecieve)
  44. ON_MESSAGE(WM_CUSTOMIZE_TRAY_MENU, OnCustomizeTrayMenu)
  45. ON_COMMAND(ID_FIRST_IMPORT, OnFirstImport)
  46. ON_MESSAGE(WM_EDIT_WND_CLOSING, OnEditWndClose)
  47. ON_WM_DESTROY()
  48. ON_COMMAND(ID_FIRST_NEWCLIP, OnFirstNewclip)
  49. ON_MESSAGE(WM_SET_CONNECTED, OnSetConnected)
  50. ON_MESSAGE(WM_OPEN_CLOSE_WINDWOW, OnOpenCloseWindow)
  51. ON_MESSAGE(WM_LOAD_ClIP_ON_CLIPBOARD, OnLoadClipOnClipboard)
  52. ON_MESSAGE(WM_TRAY_MENU_MOUSE_MOVE, OnSystemTrayMouseMove)
  53. ON_COMMAND(ID_FIRST_GLOBALHOTKEYS, &CMainFrame::OnFirstGlobalhotkeys)
  54. ON_MESSAGE(WM_GLOBAL_CLIPS_CLOSED, OnGlobalClipsClosed)
  55. ON_MESSAGE(WM_OPTIONS_CLOSED, OnOptionsClosed)
  56. ON_MESSAGE(WM_SHOW_OPTIONS, OnShowOptions)
  57. ON_COMMAND(ID_FIRST_DELETECLIPDATA, &CMainFrame::OnFirstDeleteclipdata)
  58. ON_MESSAGE(WM_DELETE_CLIPS_CLOSED, OnDeleteClipDataClosed)
  59. ON_COMMAND(ID_FIRST_SAVECURRENTCLIPBOARD, &CMainFrame::OnFirstSavecurrentclipboard)
  60. ON_MESSAGE(WM_SAVE_CLIPBOARD, &CMainFrame::OnSaveClipboardMessage)
  61. ON_MESSAGE(WM_READD_TASKBAR_ICON, OnReAddTaskBarIcon)
  62. ON_MESSAGE(WM_REOPEN_DATABASE, &CMainFrame::OnReOpenDatabase)
  63. END_MESSAGE_MAP()
  64. static UINT indicators[] =
  65. {
  66. ID_SEPARATOR, // status line indicator
  67. ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,
  68. };
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CMainFrame construction/destruction
  71. CMainFrame::CMainFrame()
  72. {
  73. m_pEditFrameWnd = NULL;
  74. m_keyStateModifiers = 0;
  75. m_startKeyStateTime = 0;
  76. m_bMovedSelectionMoveKeyState = false;
  77. m_keyModifiersTimerCount = 0;
  78. m_pGlobalClips = NULL;
  79. m_pOptions = NULL;
  80. m_pDeleteClips = NULL;
  81. m_doubleClickGroupId = -1;
  82. m_doubleClickGroupStartTime = 0;
  83. }
  84. CMainFrame::~CMainFrame()
  85. {
  86. CGetSetOptions::SetMainHWND(0);
  87. }
  88. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  89. {
  90. if(CFrameWnd::OnCreate(lpCreateStruct) == - 1)
  91. {
  92. return - 1;
  93. }
  94. m_PowerManager.Start(m_hWnd);
  95. //Center the main window so message boxes are in the center
  96. CRect rcScreen;
  97. GetMonitorRect(0, &rcScreen);
  98. CPoint cpCenter = rcScreen.CenterPoint();
  99. //MoveWindow(cpCenter.x, cpCenter.x, - 2, - 2);
  100. //Then set the main window to transparent so it's never shown
  101. //if it is shown then only the task tray icon
  102. //m_Transparency.SetTransparent(m_hWnd, 0, true);
  103. SetWindowText(_T(""));
  104. Log(_T("Setting polling timer to track focus"));
  105. SetTimer(ACTIVE_WINDOW_TIMER, g_Opt.FocusWndTimerTimeout(), 0);
  106. SetTimer(READ_RANDOM_DB_FILE, g_Opt.ReadRandomFileInterval() * 1000, 0);
  107. SetWindowText(_T("Ditto"));
  108. HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  109. m_TrayIcon.Create(NULL, WM_ICON_NOTIFY, _T("Ditto"), hIcon, IDR_MENU, FALSE, _T(""), _T(""), NULL, 20);
  110. m_TrayIcon.SetSingleClickSelect(TRUE);
  111. m_TrayIcon.MinimiseToTray(this);
  112. m_TrayIcon.SetMenuDefaultItem(ID_FIRST_SHOWQUICKPASTE, FALSE);
  113. //Only if in release
  114. #ifndef _DEBUG
  115. {
  116. //If not showing the icon show it for 40 seconds so they can get to the option
  117. //in case they can't remember the hot keys or something like that
  118. if(!(CGetSetOptions::GetShowIconInSysTray()))
  119. {
  120. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  121. }
  122. }
  123. #endif
  124. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR*24, 0);
  125. SetTimer(REMOVE_OLD_REMOTE_COPIES, ONE_DAY, 0);
  126. SetTimer(REMOVE_OLD_ENTRIES_TIMER, ONE_MINUTE*15, 0);
  127. //found on some computers GetTickCount gettickcount returns a smaller value than other, can't explain
  128. //check here to see if we need to make an adjustment
  129. IdleSeconds();
  130. m_ulCopyGap = CGetSetOptions::GetCopyGap();
  131. theApp.AfterMainCreate();
  132. m_thread.Start(this);
  133. return 0;
  134. }
  135. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
  136. {
  137. if(cs.hMenu != NULL)
  138. {
  139. ::DestroyMenu(cs.hMenu); // delete menu if loaded
  140. cs.hMenu = NULL; // no menu for this window
  141. }
  142. if(!CFrameWnd::PreCreateWindow(cs))
  143. {
  144. return FALSE;
  145. }
  146. WNDCLASS wc;
  147. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  148. wc.lpfnWndProc = AfxWndProc;
  149. wc.cbClsExtra = 0;
  150. wc.cbWndExtra = 0;
  151. wc.hInstance = AfxGetInstanceHandle();
  152. wc.hIcon = NULL;
  153. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  154. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  155. wc.lpszMenuName = NULL;
  156. wc.lpszClassName = _T("Ditto");
  157. // Create the QPaste window class
  158. if(!AfxRegisterClass(&wc))
  159. {
  160. return FALSE;
  161. }
  162. cs.lpszClass = wc.lpszClassName;
  163. return TRUE;
  164. }
  165. /////////////////////////////////////////////////////////////////////////////
  166. // CMainFrame diagnostics
  167. #ifdef _DEBUG
  168. void CMainFrame::AssertValid()const
  169. {
  170. CFrameWnd::AssertValid();
  171. }
  172. void CMainFrame::Dump(CDumpContext &dc)const
  173. {
  174. CFrameWnd::Dump(dc);
  175. }
  176. #endif //_DEBUG
  177. /////////////////////////////////////////////////////////////////////////////
  178. // CMainFrame message handlers
  179. void CMainFrame::OnFirstExit()
  180. {
  181. this->SendMessage(WM_CLOSE, 0, 0);
  182. }
  183. LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
  184. {
  185. if(theApp.m_pDittoHotKey && wParam == theApp.m_pDittoHotKey->m_Atom)
  186. {
  187. //If they still have the shift/ctrl keys down
  188. if(m_keyStateModifiers != 0 && m_quickPaste.IsWindowVisibleEx())
  189. {
  190. Log(_T("On Show Ditto HotKey, key state modifiers are still down, moving selection"));
  191. if(m_bMovedSelectionMoveKeyState == false)
  192. {
  193. Log(_T("Setting flag m_bMovedSelectionMoveKeyState to true, will paste when modifer keys are up"));
  194. }
  195. m_quickPaste.MoveSelection(true);
  196. m_bMovedSelectionMoveKeyState = true;
  197. }
  198. else if(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown && m_quickPaste.IsWindowTopLevel() && g_Opt.GetShowPersistent() == FALSE)
  199. {
  200. Log(_T("On Show Ditto HotKey, window is alread visible, hiding window"));
  201. m_quickPaste.HideQPasteWnd();
  202. }
  203. else
  204. {
  205. Log(_T("On Show Ditto HotKey, showing window"));
  206. StartKeyModifyerTimer();
  207. //Before we show our window find the current focused window for paste into
  208. theApp.m_activeWnd.TrackActiveWnd(true);
  209. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  210. }
  211. //KillTimer(CLOSE_WINDOW_TIMER);
  212. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR *24, 0);
  213. }
  214. else if(theApp.m_pPosOne && wParam == theApp.m_pPosOne->m_Atom)
  215. {
  216. Log(_T("Pos 1 hot key"));
  217. DoFirstTenPositionsPaste(0);
  218. }
  219. else if(theApp.m_pPosTwo && wParam == theApp.m_pPosTwo->m_Atom)
  220. {
  221. Log(_T("Pos 2 hot key"));
  222. DoFirstTenPositionsPaste(1);
  223. }
  224. else if(theApp.m_pPosThree && wParam == theApp.m_pPosThree->m_Atom)
  225. {
  226. Log(_T("Pos 3 hot key"));
  227. DoFirstTenPositionsPaste(2);
  228. }
  229. else if(theApp.m_pPosFour && wParam == theApp.m_pPosFour->m_Atom)
  230. {
  231. Log(_T("Pos 4 hot key"));
  232. DoFirstTenPositionsPaste(3);
  233. }
  234. else if(theApp.m_pPosFive && wParam == theApp.m_pPosFive->m_Atom)
  235. {
  236. Log(_T("Pos 5 hot key"));
  237. DoFirstTenPositionsPaste(4);
  238. }
  239. else if(theApp.m_pPosSix && wParam == theApp.m_pPosSix->m_Atom)
  240. {
  241. Log(_T("Pos 6 hot key"));
  242. DoFirstTenPositionsPaste(5);
  243. }
  244. else if(theApp.m_pPosSeven && wParam == theApp.m_pPosSeven->m_Atom)
  245. {
  246. Log(_T("Pos 7 hot key"));
  247. DoFirstTenPositionsPaste(6);
  248. }
  249. else if(theApp.m_pPosEight && wParam == theApp.m_pPosEight->m_Atom)
  250. {
  251. Log(_T("Pos 8 hot key"));
  252. DoFirstTenPositionsPaste(7);
  253. }
  254. else if(theApp.m_pPosNine && wParam == theApp.m_pPosNine->m_Atom)
  255. {
  256. Log(_T("Pos 9 hot key"));
  257. DoFirstTenPositionsPaste(8);
  258. }
  259. else if(theApp.m_pPosTen && wParam == theApp.m_pPosTen->m_Atom)
  260. {
  261. Log(_T("Pos 10 hot key"));
  262. DoFirstTenPositionsPaste(9);
  263. }
  264. else if(theApp.m_pCopyBuffer1 && wParam == theApp.m_pCopyBuffer1->m_Atom)
  265. {
  266. Log(_T("Copy buffer 1 hot key"));
  267. theApp.m_CopyBuffer.StartCopy(0);
  268. }
  269. else if(theApp.m_pPasteBuffer1 && wParam == theApp.m_pPasteBuffer1->m_Atom)
  270. {
  271. Log(_T("Paste buffer 1 hot key"));
  272. theApp.m_CopyBuffer.PastCopyBuffer(0);
  273. }
  274. else if(theApp.m_pCutBuffer1 && wParam == theApp.m_pCutBuffer1->m_Atom)
  275. {
  276. Log(_T("Cut buffer 1 hot key"));
  277. theApp.m_CopyBuffer.StartCopy(0, true);
  278. }
  279. else if(theApp.m_pCopyBuffer2 && wParam == theApp.m_pCopyBuffer2->m_Atom)
  280. {
  281. Log(_T("Copy buffer 2 hot key"));
  282. theApp.m_CopyBuffer.StartCopy(1);
  283. }
  284. else if(theApp.m_pPasteBuffer2 && wParam == theApp.m_pPasteBuffer2->m_Atom)
  285. {
  286. Log(_T("Paste buffer 2 hot key"));
  287. theApp.m_CopyBuffer.PastCopyBuffer(1);
  288. }
  289. else if(theApp.m_pCutBuffer2 && wParam == theApp.m_pCutBuffer2->m_Atom)
  290. {
  291. Log(_T("Cut buffer 2 hot key"));
  292. theApp.m_CopyBuffer.StartCopy(1, true);
  293. }
  294. else if(theApp.m_pCopyBuffer3 && wParam == theApp.m_pCopyBuffer3->m_Atom)
  295. {
  296. Log(_T("Copy buffer 3 hot key"));
  297. theApp.m_CopyBuffer.StartCopy(2);
  298. }
  299. else if(theApp.m_pPasteBuffer3 && wParam == theApp.m_pPasteBuffer3->m_Atom)
  300. {
  301. Log(_T("Paste buffer 3 hot key"));
  302. theApp.m_CopyBuffer.PastCopyBuffer(2);
  303. }
  304. else if(theApp.m_pCutBuffer3 && wParam == theApp.m_pCutBuffer3->m_Atom)
  305. {
  306. Log(_T("Cut buffer 3 hot key"));
  307. theApp.m_CopyBuffer.StartCopy(2, true);
  308. }
  309. else if(theApp.m_pTextOnlyPaste && wParam == theApp.m_pTextOnlyPaste->m_Atom)
  310. {
  311. DoTextOnlyPaste();
  312. }
  313. else if(theApp.m_pSaveClipboard && wParam == theApp.m_pSaveClipboard->m_Atom)
  314. {
  315. OnFirstSavecurrentclipboard();
  316. }
  317. else
  318. {
  319. for(int i = 0; i < g_HotKeys.GetCount(); i++)
  320. {
  321. if(g_HotKeys[i] != NULL &&
  322. g_HotKeys[i]->m_Atom == wParam &&
  323. g_HotKeys[i]->m_clipId > 0)
  324. {
  325. if(g_HotKeys[i]->m_hkType == CHotKey::PASTE_OPEN_CLIP)
  326. {
  327. Log(StrF(_T("Pasting clip from global shortcut, clipId: %d"), g_HotKeys[i]->m_clipId));
  328. PasteOrShowGroup(g_HotKeys[i]->m_clipId, -1, FALSE, TRUE);
  329. }
  330. else if(g_HotKeys[i]->m_hkType == CHotKey::MOVE_TO_GROUP)
  331. {
  332. Log(StrF(_T("Global hot key to save clip to group Id: %d, Sending copy to save selection to this group"), g_HotKeys[i]->m_clipId));
  333. KillTimer(GROUP_DOUBLE_CLICK);
  334. m_doubleClickGroupId = -1;
  335. m_doubleClickGroupStartTime = 0;
  336. theApp.SetActiveGroupId(g_HotKeys[i]->m_clipId);
  337. theApp.m_activeWnd.SendCopy(CopyReasonEnum::COPY_TO_GROUP);
  338. }
  339. break;
  340. }
  341. }
  342. }
  343. return TRUE;
  344. }
  345. void CMainFrame::DoTextOnlyPaste()
  346. {
  347. CClipboardSaveRestore textOnlyPaste;
  348. Log(_T("Text Only paste, saving clipboard to be restored later"));
  349. textOnlyPaste.Save(TRUE);
  350. Log(_T("Text Only paste, Add cf_text or cf_unicodetext to clipboard"));
  351. textOnlyPaste.RestoreTextOnly();
  352. DWORD pasteDelay = g_Opt.GetTextOnlyPasteDelay();
  353. Log(StrF(_T("Text Only paste, delaying %d ms before sending paste"), pasteDelay));
  354. Sleep(pasteDelay);
  355. Log(_T("Text Only paste, Sending paste"));
  356. theApp.m_activeWnd.SendPaste(false);
  357. Log(_T("Text Only paste, Post sending paste"));
  358. }
  359. void CMainFrame::DoFirstTenPositionsPaste(int nPos)
  360. {
  361. try
  362. {
  363. CString csSort = _T("");
  364. csSort = "Main.bIsGroup ASC, "
  365. "Main.stickyClipOrder DESC, "
  366. "Main.clipOrder DESC";
  367. CString strFilter = _T("");
  368. if (g_Opt.m_bShowAllClipsInMainList)
  369. {
  370. if (CGetSetOptions::GetShowGroupsInMainList())
  371. {
  372. //found to be slower on large databases
  373. strFilter = "((Main.bIsGroup = 1 AND Main.lParentID = -1) OR Main.bIsGroup = 0)";
  374. }
  375. else
  376. {
  377. strFilter = "(Main.bIsGroup = 0)";
  378. }
  379. }
  380. else
  381. {
  382. strFilter = "((Main.bIsGroup = 1 AND Main.lParentID = -1) OR (Main.bIsGroup = 0 AND Main.lParentID = -1))";
  383. }
  384. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, bIsGroup FROM Main WHERE %s ORDER BY %s LIMIT 1 OFFSET %d"), strFilter, csSort, nPos);
  385. if(q.eof() == false)
  386. {
  387. PasteOrShowGroup(q.getIntField(_T("lID")), CGetSetOptions::GetMoveClipsOnGlobal10(), false, g_Opt.m_bSendPasteOnFirstTenHotKeys);
  388. }
  389. }
  390. CATCH_SQLITE_EXCEPTION
  391. }
  392. void CMainFrame::StartKeyModifyerTimer()
  393. {
  394. m_keyModifiersTimerCount = 0;
  395. m_bMovedSelectionMoveKeyState = false;
  396. m_startKeyStateTime = GetTickCount();
  397. m_keyStateModifiers = CAccels::GetKeyStateModifiers();
  398. SetTimer(KEY_STATE_MODIFIERS, 50, NULL);
  399. }
  400. void CMainFrame::PasteOrShowGroup(int dbId, BOOL updateClipTime, BOOL activeTarget, BOOL sendPaste)
  401. {
  402. try
  403. {
  404. bool isGroup = false;
  405. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT bIsGroup FROM Main WHERE lID = %d"), dbId);
  406. if(q.eof() == false)
  407. {
  408. if(q.getIntField(_T("bIsGroup")) > 0)
  409. {
  410. isGroup = true;
  411. }
  412. }
  413. if(isGroup)
  414. {
  415. int maxDiff = CGetSetOptions::GetGroupDoubleClickTimeMS();
  416. DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;
  417. if(m_doubleClickGroupId == dbId &&
  418. diff < maxDiff)
  419. {
  420. Log(StrF(_T("Second Press of group hot key, group Id: %d, Sending copy to save selection to this group"), dbId));
  421. KillTimer(GROUP_DOUBLE_CLICK);
  422. m_doubleClickGroupId = -1;
  423. m_doubleClickGroupStartTime = 0;
  424. theApp.SetActiveGroupId(dbId);
  425. theApp.m_activeWnd.SendCopy(CopyReasonEnum::COPY_TO_GROUP);
  426. }
  427. else
  428. {
  429. m_doubleClickGroupId = dbId;
  430. m_doubleClickGroupStartTime = GetTickCount();
  431. int doubleClickTime = CGetSetOptions::GetGroupDoubleClickTimeMS();
  432. SetTimer(GROUP_DOUBLE_CLICK, doubleClickTime, 0);
  433. Log(StrF(_T("First Press of group hot key, group Id: %d, timout: %d"), dbId, doubleClickTime));
  434. }
  435. }
  436. else
  437. {
  438. KillTimer(GROUP_DOUBLE_CLICK);
  439. m_doubleClickGroupId = -1;
  440. m_doubleClickGroupStartTime = 0;
  441. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  442. if (updateClipTime != -1)
  443. {
  444. g_Opt.m_bUpdateTimeOnPaste = updateClipTime;
  445. }
  446. CProcessPaste paste;
  447. paste.GetClipIDs().Add(dbId);
  448. if (activeTarget != -1)
  449. {
  450. paste.m_bActivateTarget = activeTarget ? true : false;;
  451. }
  452. if (sendPaste != -1)
  453. {
  454. paste.m_bSendPaste = sendPaste ? true : false;
  455. }
  456. paste.DoPaste();
  457. theApp.OnPasteCompleted();
  458. if (updateClipTime != -1)
  459. {
  460. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  461. }
  462. }
  463. }
  464. CATCH_SQLITE_EXCEPTION
  465. }
  466. void CMainFrame::DoDittoCopyBufferPaste(int nCopyBuffer)
  467. {
  468. try
  469. {
  470. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE CopyBuffer = %d"), nCopyBuffer);
  471. if(q.eof() == false)
  472. {
  473. //Don't move these to the top
  474. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  475. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  476. CProcessPaste paste;
  477. paste.GetClipIDs().Add(q.getIntField(_T("lID")));
  478. paste.m_bActivateTarget = false;
  479. paste.DoPaste();
  480. theApp.OnPasteCompleted();
  481. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  482. }
  483. }
  484. CATCH_SQLITE_EXCEPTION
  485. }
  486. void CMainFrame::OnTimer(UINT_PTR nIDEvent)
  487. {
  488. switch(nIDEvent)
  489. {
  490. case HIDE_ICON_TIMER:
  491. {
  492. m_TrayIcon.HideIcon();
  493. KillTimer(nIDEvent);
  494. }
  495. break;
  496. case CLOSE_WINDOW_TIMER:
  497. {
  498. //m_quickPaste.CloseQPasteWnd();
  499. }
  500. break;
  501. case REMOVE_OLD_ENTRIES_TIMER:
  502. {
  503. m_thread.FireDeleteEntries();
  504. }
  505. break;
  506. case REMOVE_OLD_REMOTE_COPIES:
  507. {
  508. m_thread.FireRemoveRemoteFiles();
  509. }
  510. break;
  511. case KEY_STATE_MODIFIERS:
  512. m_keyModifiersTimerCount++;
  513. if(m_keyStateModifiers != 0)
  514. {
  515. BYTE keyState = CAccels::GetKeyStateModifiers();
  516. //Have they release the key state modifiers yet(ctrl, shift, alt)
  517. if((m_keyStateModifiers &keyState) == 0)
  518. {
  519. KillTimer(KEY_STATE_MODIFIERS);
  520. long waitTime = (long)(GetTickCount() - m_startKeyStateTime);
  521. if(m_bMovedSelectionMoveKeyState || m_keyModifiersTimerCount > g_Opt.GetKeyStateWaitTimerCount())
  522. {
  523. Log(StrF(_T("Timer KEY_STATE_MODIFIERS timeout count hit(%d), count (%d), time (%d), Move Selection from Modifer (%d) sending paste"), g_Opt.GetKeyStateWaitTimerCount(), m_keyModifiersTimerCount, waitTime, m_bMovedSelectionMoveKeyState));
  524. m_quickPaste.OnKeyStateUp();
  525. }
  526. else
  527. {
  528. Log(StrF(_T("Timer KEY_STATE_MODIFIERS count NOT hit(%d), count (%d) time (%d)"), g_Opt.GetKeyStateWaitTimerCount(), m_keyModifiersTimerCount, waitTime));
  529. m_quickPaste.SetKeyModiferState(false);
  530. }
  531. m_keyStateModifiers = 0;
  532. m_keyModifiersTimerCount = 0;
  533. m_bMovedSelectionMoveKeyState = 0;
  534. }
  535. }
  536. else
  537. {
  538. KillTimer(KEY_STATE_MODIFIERS);
  539. }
  540. break;
  541. case ACTIVE_WINDOW_TIMER:
  542. {
  543. if(theApp.m_bShowingQuickPaste)
  544. {
  545. theApp.m_activeWnd.TrackActiveWnd(false);
  546. }
  547. }
  548. break;
  549. case READ_RANDOM_DB_FILE:
  550. {
  551. m_thread.FireReadDbFile();
  552. }
  553. break;
  554. case GROUP_DOUBLE_CLICK:
  555. {
  556. KillTimer(GROUP_DOUBLE_CLICK);
  557. Log(StrF(_T("Processing single click of groupId %d in timer, opening ditto to this group"), m_doubleClickGroupId));
  558. int maxDiff = (CGetSetOptions::GetGroupDoubleClickTimeMS() * 1.5);
  559. DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;
  560. if(diff < maxDiff)
  561. {
  562. if(m_doubleClickGroupId > -1)
  563. {
  564. if (theApp.EnterGroupID(m_doubleClickGroupId, FALSE, TRUE))
  565. {
  566. theApp.m_activeWnd.TrackActiveWnd(true);
  567. StartKeyModifyerTimer();
  568. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  569. }
  570. }
  571. }
  572. else
  573. {
  574. Log(StrF(_T("Something happened and we didn't process the group timer in time, Id: %d, Diff ms: %d, maxDiff: %d"), m_doubleClickGroupId, diff, maxDiff));
  575. }
  576. m_doubleClickGroupId = -1;
  577. m_doubleClickGroupStartTime = 0;
  578. }
  579. break;
  580. }
  581. CFrameWnd::OnTimer(nIDEvent);
  582. }
  583. LRESULT CMainFrame::OnShowTrayIcon(WPARAM wParam, LPARAM lParam)
  584. {
  585. if(lParam)
  586. {
  587. if(!m_TrayIcon.Visible())
  588. {
  589. KillTimer(HIDE_ICON_TIMER);
  590. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  591. }
  592. }
  593. if(wParam)
  594. {
  595. m_TrayIcon.ShowIcon();
  596. }
  597. else
  598. {
  599. m_TrayIcon.HideIcon();
  600. }
  601. return TRUE;
  602. }
  603. void CMainFrame::OnFirstShowquickpaste()
  604. {
  605. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  606. }
  607. void CMainFrame::OnFirstToggleConnectCV()
  608. {
  609. theApp.ToggleConnectCV();
  610. }
  611. void CMainFrame::OnUpdateFirstToggleConnectCV(CCmdUI *pCmdUI)
  612. {
  613. theApp.UpdateMenuConnectCV(pCmdUI->m_pMenu, ID_FIRST_TOGGLECONNECTCV);
  614. }
  615. LRESULT CMainFrame::OnClipboardCopied(WPARAM wParam, LPARAM lParam)
  616. {
  617. Log(_T("Start of function OnClipboardCopied, adding clip to thread for processing"));
  618. CClip *pClip = (CClip*)wParam;
  619. if(pClip != NULL)
  620. {
  621. m_thread.AddClipToSave(pClip);
  622. }
  623. Log(_T("End of function OnClipboardCopied"));
  624. return TRUE;
  625. }
  626. BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
  627. {
  628. // target before mouse messages change the focus
  629. /*if(theApp.m_bShowingQuickPaste && WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST)
  630. {
  631. theApp.m_activeWnd.TrackActiveWnd(true);
  632. }*/
  633. return CFrameWnd::PreTranslateMessage(pMsg);
  634. }
  635. void CMainFrame::OnClose()
  636. {
  637. CloseAllOpenDialogs();
  638. if(m_pEditFrameWnd)
  639. {
  640. if(m_pEditFrameWnd->CloseAll() == false)
  641. {
  642. return ;
  643. }
  644. }
  645. Log(_T("OnClose - before stop MainFrm thread"));
  646. m_thread.Stop();
  647. Log(_T("OnClose - after stop MainFrm thread"));
  648. theApp.BeforeMainClose();
  649. m_PowerManager.Close();
  650. CFrameWnd::OnClose();
  651. }
  652. bool CMainFrame::CloseAllOpenDialogs()
  653. {
  654. bool bRet = false;
  655. DWORD dwordProcessId;
  656. DWORD dwordChildWindowProcessId;
  657. GetWindowThreadProcessId(this->m_hWnd, &dwordProcessId);
  658. ASSERT(dwordProcessId);
  659. CWnd *pTempWnd = GetDesktopWindow()->GetWindow(GW_CHILD);
  660. while((pTempWnd = pTempWnd->GetWindow(GW_HWNDNEXT)) != NULL)
  661. {
  662. if(pTempWnd->GetSafeHwnd() == NULL)
  663. {
  664. break;
  665. }
  666. GetWindowThreadProcessId(pTempWnd->GetSafeHwnd(), &dwordChildWindowProcessId);
  667. if(dwordChildWindowProcessId == dwordProcessId)
  668. {
  669. TCHAR szTemp[100];
  670. GetClassName(pTempWnd->GetSafeHwnd(), szTemp, 100);
  671. // #32770 is class name for dialogs so don't process the message if it is a dialog
  672. if(STRCMP(szTemp, _T("#32770")) == 0)
  673. {
  674. pTempWnd->SendMessage(WM_CLOSE, 0, 0);
  675. bRet = true;
  676. }
  677. }
  678. }
  679. MSG msg;
  680. while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  681. {
  682. TranslateMessage(&msg);
  683. DispatchMessage(&msg);
  684. }
  685. return bRet;
  686. }
  687. LRESULT CMainFrame::OnSystemTrayMouseMove(WPARAM wParam, LPARAM lParam)
  688. {
  689. theApp.m_activeWnd.TrackActiveWnd(true);
  690. return 0;
  691. }
  692. LRESULT CMainFrame::OnLoadClipOnClipboard(WPARAM wParam, LPARAM lParam)
  693. {
  694. CClip *pClip = (CClip*)wParam;
  695. if(pClip == NULL)
  696. {
  697. LogSendRecieveInfo("---------ERROR OnLoadClipOnClipboard pClip == NULL");
  698. return FALSE;
  699. }
  700. if(pClip)
  701. {
  702. CProcessPaste paste;
  703. paste.m_bSendPaste = false;
  704. paste.m_bActivateTarget = false;
  705. LogSendRecieveInfo("---------OnLoadClipOnClipboard - Before PutFormats on clipboard");
  706. paste.m_pOle->PutFormatOnClipboard(&pClip->m_Formats);
  707. paste.m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
  708. LogSendRecieveInfo("---------OnLoadClipOnClipboard - After PutFormats on clipboard");
  709. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - Setting clip id: %d on ole clipboard"), pClip->m_id));
  710. paste.GetClipIDs().Add(pClip->m_id);
  711. paste.DoPaste();
  712. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - After paste clip id: %d on ole clipboard"), pClip->m_id));
  713. }
  714. delete pClip;
  715. return TRUE;
  716. }
  717. LRESULT CMainFrame::OnAddToDatabaseFromSocket(WPARAM wParam, LPARAM lParam)
  718. {
  719. CClipList *pClipList = (CClipList*)wParam;
  720. if(pClipList == NULL)
  721. {
  722. LogSendRecieveInfo("---------OnAddToDatabaseFromSocket - ERROR pClipList == NULL");
  723. return FALSE;
  724. }
  725. BOOL bSetToClipBoard = (BOOL)lParam;
  726. if(bSetToClipBoard)
  727. {
  728. CClip *pClip = pClipList->GetTail();
  729. if(pClip)
  730. {
  731. LogSendRecieveInfo("OnAddToDatabaseFromSocket - Adding clip from socket setting clip to be put on clipboard");
  732. pClip->m_param1 = TRUE;
  733. }
  734. }
  735. m_thread.AddRemoteClipToSave(pClipList);
  736. delete pClipList;
  737. return TRUE;
  738. }
  739. LRESULT CMainFrame::OnErrorOnSendRecieve(WPARAM wParam, LPARAM lParam)
  740. {
  741. CString csNewText = (TCHAR*)wParam;
  742. ShowErrorMessage(_T("Ditto - Send/Receive Error"), csNewText);
  743. return TRUE;
  744. }
  745. CString WndName(HWND hParent)
  746. {
  747. TCHAR cWindowText[200];
  748. ::GetWindowText(hParent, cWindowText, 100);
  749. int nCount = 0;
  750. while(STRLEN(cWindowText) <= 0)
  751. {
  752. hParent = ::GetParent(hParent);
  753. if(hParent == NULL)
  754. {
  755. break;
  756. }
  757. ::GetWindowText(hParent, cWindowText, 100);
  758. nCount++;
  759. if(nCount > 100)
  760. {
  761. Log(_T("GetTargetName reached maximum search depth of 100"));
  762. break;
  763. }
  764. }
  765. return cWindowText;
  766. }
  767. void CMainFrame::OnFirstHelp()
  768. {
  769. CString csFile = CGetSetOptions::GetPath(PATH_HELP);
  770. csFile += "DittoGettingStarted.htm";
  771. CHyperLink::GotoURL(csFile, SW_SHOW);
  772. }
  773. LRESULT CMainFrame::OnCustomizeTrayMenu(WPARAM wParam, LPARAM lParam)
  774. {
  775. CMenu *pMenu = (CMenu*)wParam;
  776. if(pMenu)
  777. {
  778. theApp.m_Language.UpdateTrayIconRightClickMenu(pMenu);
  779. }
  780. return true;
  781. }
  782. void CMainFrame::ShowErrorMessage(CString csTitle, CString csMessage)
  783. {
  784. Log(StrF(_T("ShowErrorMessage %s - %s"), csTitle, csMessage));
  785. CToolTipEx *pErrorWnd = new CToolTipEx;
  786. pErrorWnd->Create(this);
  787. pErrorWnd->SetToolTipText(csTitle + "\n\n" + csMessage);
  788. CPoint pt;
  789. CRect rcScreen;
  790. GetMonitorRect(0, &rcScreen);
  791. pt = rcScreen.BottomRight();
  792. CRect cr = pErrorWnd->GetBoundsRect();
  793. pt.x -= max(cr.Width() + 50, 150);
  794. pt.y -= max(cr.Height() + 50, 150);
  795. pErrorWnd->Show(pt);
  796. pErrorWnd->HideWindowInXMilliSeconds(4000);
  797. }
  798. void CMainFrame::OnFirstImport()
  799. {
  800. theApp.ImportClips(theApp.m_MainhWnd);
  801. }
  802. void CMainFrame::ShowEditWnd(CClipIDs &Ids)
  803. {
  804. CWaitCursor wait;
  805. bool bCreatedWindow = false;
  806. if(m_pEditFrameWnd == NULL)
  807. {
  808. m_pEditFrameWnd = new CEditFrameWnd;
  809. m_pEditFrameWnd->LoadFrame(IDR_MAINFRAME);
  810. bCreatedWindow = true;
  811. }
  812. if(m_pEditFrameWnd)
  813. {
  814. m_pEditFrameWnd->EditIds(Ids);
  815. m_pEditFrameWnd->SetNotifyWnd(m_hWnd);
  816. if(bCreatedWindow)
  817. {
  818. CSize sz;
  819. CPoint pt;
  820. CGetSetOptions::GetEditWndSize(sz);
  821. CGetSetOptions::GetEditWndPoint(pt);
  822. CRect cr(pt, sz);
  823. EnsureWindowVisible(&cr);
  824. m_pEditFrameWnd->MoveWindow(cr);
  825. }
  826. m_pEditFrameWnd->ShowWindow(SW_SHOW);
  827. m_pEditFrameWnd->SetForegroundWindow();
  828. m_pEditFrameWnd->SetFocus();
  829. }
  830. }
  831. LRESULT CMainFrame::OnEditWndClose(WPARAM wParam, LPARAM lParam)
  832. {
  833. m_pEditFrameWnd = NULL;
  834. return TRUE;
  835. }
  836. LRESULT CMainFrame::OnSetConnected(WPARAM wParam, LPARAM lParam)
  837. {
  838. if(wParam)
  839. {
  840. theApp.SetConnectCV(true);
  841. }
  842. else if(lParam)
  843. {
  844. theApp.SetConnectCV(false);
  845. }
  846. return TRUE;
  847. }
  848. LRESULT CMainFrame::OnOpenCloseWindow(WPARAM wParam, LPARAM lParam)
  849. {
  850. if(wParam)
  851. {
  852. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  853. }
  854. else if(lParam)
  855. {
  856. m_quickPaste.HideQPasteWnd();
  857. }
  858. return TRUE;
  859. }
  860. void CMainFrame::OnDestroy()
  861. {
  862. CFrameWnd::OnDestroy();
  863. if(m_pEditFrameWnd)
  864. {
  865. m_pEditFrameWnd->DestroyWindow();
  866. }
  867. }
  868. void CMainFrame::OnFirstNewclip()
  869. {
  870. CClipIDs IDs;
  871. IDs.Add( - 1);
  872. theApp.EditItems(IDs, true);
  873. }
  874. void CMainFrame::OnFirstOption()
  875. {
  876. if(m_pOptions != NULL)
  877. {
  878. ::SetForegroundWindow(m_pOptions->m_hWnd);
  879. }
  880. else
  881. {
  882. m_pOptions = new COptionsSheet(_T(""));
  883. if(m_pOptions != NULL)
  884. {
  885. ((COptionsSheet*)m_pOptions)->SetNotifyWnd(m_hWnd);
  886. m_pOptions->Create();
  887. m_pOptions->ShowWindow(SW_SHOW);
  888. }
  889. }
  890. }
  891. void CMainFrame::OnFirstGlobalhotkeys()
  892. {
  893. if(m_pGlobalClips != NULL)
  894. {
  895. ::SetForegroundWindow(m_pGlobalClips->m_hWnd);
  896. }
  897. else
  898. {
  899. m_pGlobalClips = new GlobalClips();
  900. CAlphaBlend tran;
  901. tran.SetTransparent(m_hWnd, 0, 1);
  902. if(m_pGlobalClips != NULL)
  903. {
  904. ((GlobalClips*)m_pGlobalClips)->SetNotifyWnd(m_hWnd);
  905. m_pGlobalClips->Create(IDD_GLOBAL_CLIPS, NULL);
  906. m_pGlobalClips->ShowWindow(SW_SHOW);
  907. }
  908. }
  909. }
  910. LRESULT CMainFrame::OnShowOptions(WPARAM wParam, LPARAM lParam)
  911. {
  912. OnFirstOption();
  913. return 0;
  914. }
  915. LRESULT CMainFrame::OnOptionsClosed(WPARAM wParam, LPARAM lParam)
  916. {
  917. m_TrayIcon.MinimiseToTray(this);
  918. CAlphaBlend tran;
  919. tran.SetTransparent(m_hWnd, 255, 0);
  920. delete m_pOptions;
  921. m_pOptions = NULL;
  922. if(m_quickPaste.m_pwndPaste != NULL)
  923. {
  924. m_quickPaste.m_pwndPaste->PostMessage(NM_POST_OPTIONS_WINDOW);
  925. }
  926. return 0;
  927. }
  928. LRESULT CMainFrame::OnGlobalClipsClosed(WPARAM wParam, LPARAM lParam)
  929. {
  930. m_TrayIcon.MinimiseToTray(this);
  931. CAlphaBlend tran;
  932. tran.SetTransparent(m_hWnd, 255, 0);
  933. delete m_pGlobalClips;
  934. m_pGlobalClips = NULL;
  935. return 0;
  936. }
  937. void CMainFrame::RefreshShowInTaskBar()
  938. {
  939. BOOL windowVisible = m_quickPaste.IsWindowVisibleEx();
  940. m_quickPaste.CloseQPasteWnd();
  941. if (windowVisible)
  942. {
  943. m_quickPaste.ShowQPasteWnd(this, true, false, true);
  944. }
  945. }
  946. LRESULT CMainFrame::OnDeleteClipDataClosed(WPARAM wParam, LPARAM lParam)
  947. {
  948. m_TrayIcon.MinimiseToTray(this);
  949. CAlphaBlend tran;
  950. tran.SetTransparent(m_hWnd, 255, 0);
  951. delete m_pDeleteClips;
  952. m_pDeleteClips = NULL;
  953. return 0;
  954. }
  955. void CMainFrame::OnFirstDeleteclipdata()
  956. {
  957. //this->ShowWindow(SW_HIDE);
  958. if (m_pDeleteClips != NULL)
  959. {
  960. ::SetForegroundWindow(m_pDeleteClips->m_hWnd);
  961. }
  962. else
  963. {
  964. m_pDeleteClips = new CDeleteClipData();
  965. CAlphaBlend tran;
  966. tran.SetTransparent(m_hWnd, 0, 1);
  967. if (m_pDeleteClips != NULL)
  968. {
  969. ((CDeleteClipData*) m_pDeleteClips)->SetNotifyWnd(m_hWnd);
  970. m_pDeleteClips->Create(IDD_DELETE_CLIP_DATA, NULL);
  971. m_pDeleteClips->ShowWindow(SW_SHOW);
  972. }
  973. }
  974. }
  975. LRESULT CMainFrame::OnSaveClipboardMessage(WPARAM wParam, LPARAM lParam)
  976. {
  977. OnFirstSavecurrentclipboard();
  978. return TRUE;
  979. }
  980. void CMainFrame::OnFirstSavecurrentclipboard()
  981. {
  982. Log(_T("Start Saving the current clipboard to the database"));
  983. CClip* pClip = new CClip;
  984. if(pClip)
  985. {
  986. CClipTypes* pTypes = theApp.LoadTypesFromDB();
  987. if(pTypes)
  988. {
  989. if(pClip->LoadFromClipboard(pTypes, false))
  990. {
  991. Log(_T("Loaded clips from the clipboard, sending message to save to the db"));
  992. ::PostMessage(m_hWnd, WM_CLIPBOARD_COPIED, (WPARAM)pClip, 0);
  993. }
  994. else
  995. {
  996. Log(_T("Failed to load clips from the clipboard, not saving to db"));
  997. delete pClip;
  998. pClip = NULL;
  999. }
  1000. }
  1001. else
  1002. {
  1003. Log(_T("Failed to load supported types from the db, not saving to the db"));
  1004. }
  1005. }
  1006. Log(_T("Start Saving the current clipboard to the database"));
  1007. }
  1008. LRESULT CMainFrame::OnReAddTaskBarIcon(WPARAM wParam, LPARAM lParam)
  1009. {
  1010. if(CGetSetOptions::GetShowIconInSysTray())
  1011. {
  1012. m_TrayIcon.AddIcon();
  1013. }
  1014. return TRUE;
  1015. }
  1016. LRESULT CMainFrame::OnReOpenDatabase(WPARAM wParam, LPARAM lParam)
  1017. {
  1018. Log(StrF(_T("OnReOpenDatabase, Start closing and reopening database Delay: %d"), CGetSetOptions::GetWindowsResumeDelayReOpenDbMS()));
  1019. try
  1020. {
  1021. Sleep(CGetSetOptions::GetWindowsResumeDelayReOpenDbMS());
  1022. m_quickPaste.CloseQPasteWnd();
  1023. theApp.m_db.close();
  1024. OpenDatabase(CGetSetOptions::GetDBPath());
  1025. }
  1026. CATCH_SQLITE_EXCEPTION
  1027. Log(StrF(_T("OnReOpenDatabase, End closing and reopening database Delay: %d"), CGetSetOptions::GetWindowsResumeDelayReOpenDbMS()));
  1028. return TRUE;
  1029. }