Misc.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #if !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)
  2. #define AFX_CP_GUI_H__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif // _MSC_VER > 1000
  6. #include "Shared/ArrayEx.h"
  7. #define VK_MOUSE_CLICK 0x01
  8. #define VK_MOUSE_DOUBLE_CLICK 0x02
  9. #define VK_MOUSE_RIGHT_CLICK 0x03
  10. #define VK_MOUSE_MIDDLE_CLICK 0x04
  11. #define UPDATE_AFTER_PASTE_SELECT_CLIP 0x1
  12. #define UPDATE_AFTER_PASTE_REFRESH_VISIBLE 0x2
  13. #define REMOTE_CLIP_ADD_TO_CLIPBOARD 0x1
  14. #define REMOTE_CLIP_MANUAL_SEND 0x2
  15. //Handle foreign keyboards pressing ALT_GR (right alt), this simulates a control press
  16. //http://compgroups.net/comp.os.programmer.win32/alt-gr-key-and-left-ctrl/2840252
  17. #define CONTROL_PRESSED ((::GetKeyState(VK_CONTROL) & 0x8000) && (((GetKeyState(VK_RMENU) < 0) && (GetKeyState(VK_LCONTROL) < 0)) == FALSE))
  18. #define ONE_MINUTE 60000
  19. #define ONE_HOUR 3600000
  20. #define ONE_DAY 86400000
  21. class CopyReasonEnum
  22. {
  23. public:
  24. enum CopyReason
  25. {
  26. COPY_TO_UNKOWN,
  27. COPY_TO_GROUP,
  28. COPY_TO_BUFFER,
  29. COPY_FROM_TOOLTIP
  30. };
  31. };
  32. #define INVALID_STICKY -(2147483647)
  33. #define CATCH_SQLITE_EXCEPTION \
  34. catch (CppSQLite3Exception& e) \
  35. { \
  36. Log(StrF(_T("SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage())); \
  37. ASSERT(FALSE); \
  38. } \
  39. #define CATCH_SQLITE_EXCEPTION_AND_RETURN(bRet) \
  40. catch (CppSQLite3Exception& e) \
  41. { \
  42. Log(StrF(_T("SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage())); \
  43. ASSERT(FALSE); \
  44. return bRet; \
  45. } \
  46. #define FIX_PATH(strPath) \
  47. { \
  48. if (strPath[strlen(strPath)-1] != '\\' && strPath[strlen(strPath)-1] != '/') \
  49. strcat(strPath, "\\"); \
  50. }
  51. #define FIX_CSTRING_PATH(csPath) \
  52. { \
  53. if(csPath.IsEmpty() == FALSE && csPath.GetAt(csPath.GetLength()-1) != '\\' && csPath.GetAt(csPath.GetLength()-1) != '/') \
  54. csPath += "\\"; \
  55. }
  56. #include "DatabaseUtilities.h"
  57. CString GetIPAddress();
  58. CString GetComputerName();
  59. #define FUNC __FUNCTION__
  60. #define FUNCSIG __FUNCSIG__
  61. void AppendToFile(const TCHAR* fn, const TCHAR *msg);
  62. #define Log(msg) log(msg, false, __FILE__, __LINE__)
  63. void log(const TCHAR* msg, bool bFromSendRecieve = false, CString csFile = _T(""), long lLine = -1);
  64. CString GetErrorString(int err);
  65. double IdleSeconds();
  66. #define LogSendRecieveInfo(cs) logsendrecieveinfo(cs, __FILE__, __LINE__);
  67. void logsendrecieveinfo(CString cs, CString csFile = _T(""), long lLine = -1);
  68. // Utility Functions
  69. CString StrF(const TCHAR * pszFormat, ...);
  70. // called after determining that the preceding character is a backslash
  71. BYTE GetEscapeChar( BYTE ch );
  72. CString RemoveEscapes( const TCHAR* str );
  73. CString GetWndText( HWND hWnd );
  74. // returns true if the given window is owned by this process
  75. bool IsAppWnd( HWND hWnd );
  76. // Global Memory Helper Functions
  77. BOOL IsValid(HGLOBAL hGlobal);
  78. void CopyToGlobalHP(HGLOBAL hDest, LPVOID pBuf, SIZE_T ulBufLen);
  79. void CopyToGlobalHH(HGLOBAL hDest, HGLOBAL hSource, SIZE_T ulBufLen);
  80. HGLOBAL NewGlobalP(LPVOID pBuf, SIZE_T nLen);
  81. HGLOBAL NewGlobalH(HGLOBAL hSource, SIZE_T nLen);
  82. HGLOBAL NewGlobal(SIZE_T nLen);
  83. int CompareGlobalHP(HGLOBAL hLeft, LPVOID pBuf, SIZE_T ulBufLen);
  84. int CompareGlobalHH(HGLOBAL hLeft, HGLOBAL hRight, SIZE_T ulBufLen);
  85. BOOL EncryptString(CString &csString, UCHAR*& pOutput, int &nLenOutput);
  86. BOOL DecryptString(UCHAR *pData, int nLenIn, UCHAR*& pOutput, int &nLenOutput);
  87. int GetScreenWidth();
  88. int GetScreenHeight();
  89. CLIPFORMAT GetFormatID(LPCTSTR cbName);
  90. CString GetFormatName(CLIPFORMAT cbType);
  91. BOOL PreTranslateGuiDll(MSG *pMsg);
  92. CString GetFilePath(CString csFullPath);
  93. CString GetFileName(CString csFileName);
  94. BOOL EnsureWindowVisible(CRect *pcrRect);
  95. CRect DefaultMonitorRect();
  96. CRect MonitorRectFromRect(CRect rect);
  97. CRect CenterRect(CRect startingRect);
  98. CRect CenterRectFromRect(CRect startingRect, CRect outerRect);
  99. __int64 GetLastWriteTime(const CString &csFile);
  100. //Message to the main window to show icon or not
  101. #define WM_SHOW_TRAY_ICON WM_USER + 200
  102. #define WM_SETCONNECT WM_USER + 201
  103. #define WM_CV_IS_CONNECTED WM_USER + 202
  104. #define WM_CLOSE_APP WM_USER + 204
  105. #define WM_REFRESH_VIEW WM_USER + 205
  106. #define WM_CLIPBOARD_COPIED WM_USER + 206
  107. #define WM_ADD_TO_DATABASE_FROM_SOCKET WM_USER + 207
  108. #define WM_SEND_RECIEVE_ERROR WM_USER + 208
  109. #define WM_FOCUS_CHANGED WM_USER + 209
  110. #define WM_CV_GETCONNECT WM_USER + 211
  111. #define WM_EDIT_WND_CLOSING WM_USER + 212
  112. #define WM_SET_CONNECTED WM_USER + 213
  113. #define WM_LOAD_ClIP_ON_CLIPBOARD WM_USER + 214
  114. //defined in tray icon #define WM_CUSTOMIZE_TRAY_MENU WM_USER + 215
  115. //defined in tray icon #define WM_TRAY_MENU_MOUSE_MOVE WM_USER + 216
  116. #define WM_RELOAD_CLIP_AFTER_PASTE WM_USER + 217
  117. #define WM_GLOBAL_CLIPS_CLOSED WM_USER + 218
  118. #define WM_OPTIONS_CLOSED WM_USER + 219
  119. #define WM_SHOW_OPTIONS WM_USER + 220
  120. #define WM_DELETE_CLIPS_CLOSED WM_USER + 221
  121. #define WM_OPEN_CLOSE_WINDWOW WM_USER + 222
  122. #define WM_SAVE_CLIPBOARD WM_USER + 223
  123. #define WM_READD_TASKBAR_ICON WM_USER + 224
  124. #define WM_REOPEN_DATABASE WM_USER + 225
  125. #define WM_SHOW_MSG_WINDOW WM_USER + 226
  126. #define WM_SHOW_DITTO_GROUP WM_USER + 227
  127. #define WM_PLAIN_TEXT_PASTE WM_USER + 228
  128. #define WM_SHOW_ERROR_MSG WM_USER + 229
  129. #define WM_RESTORE_DB WM_USER + 230
  130. #define WM_BACKUP_DB WM_USER + 231
  131. #define WM_REFRESH_FOOTER WM_USER + 232
  132. #define WM_PASTE_CLIP WM_USER + 233
  133. #define WM_EDIT_CLIP WM_USER + 234
  134. #if !defined(_BITSET_)
  135. # include <bitset>
  136. #endif // !defined(_BITSET_)
  137. long NewGroupID(int parentID = 0, CString text = "");
  138. BOOL DeleteAllIDs();
  139. BOOL DeleteFormats(int parentID, ARRAY& formatIDs);
  140. __inline BOOL FileExists(LPCTSTR pszFile)
  141. {
  142. return (GetFileAttributes(pszFile) != 0xffffffff);
  143. }
  144. bool IsRunningLimited();
  145. BOOL IsVista();
  146. void DeleteDittoTempFiles(BOOL checkFileLastAccess);
  147. void DeleteFolderFiles(CString csDir, BOOL checkFileLastAccess);
  148. __int64 FileSize(const TCHAR *fileName);
  149. int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, CString postInsert, int linesPerRow);
  150. void OnInitMenuPopupEx(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu, CWnd *pWnd);
  151. CString InternetEncode(CString text);
  152. CString GetProcessName(HWND hWnd, DWORD processId = 0);
  153. void DeleteParamFromRTF(CStringA &test, CStringA find, bool searchForTrailingDigits);
  154. bool RemoveRTFSection(CStringA &str, CStringA section);
  155. CString NewGuidString();
  156. CString FolderPath(int folderId);
  157. CString TopLevelWindowText(DWORD pid);
  158. BOOL DarkAppWindows10Setting();
  159. DWORD Windows10AccentColor();
  160. BOOL Windows10ColorTitleBar();
  161. BOOL BackupDbPrompt(HWND hwnd);
  162. BOOL RestoreDbPrompt(HWND hwnd);
  163. #endif // !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)