Misc.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. };
  30. };
  31. #define INVALID_STICKY -(2147483647)
  32. #define CATCH_SQLITE_EXCEPTION \
  33. catch (CppSQLite3Exception& e) \
  34. { \
  35. Log(StrF(_T("SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage())); \
  36. ASSERT(FALSE); \
  37. } \
  38. #define CATCH_SQLITE_EXCEPTION_AND_RETURN(bRet) \
  39. catch (CppSQLite3Exception& e) \
  40. { \
  41. Log(StrF(_T("SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage())); \
  42. ASSERT(FALSE); \
  43. return bRet; \
  44. } \
  45. #define FIX_PATH(strPath) \
  46. { \
  47. if (strPath[strlen(strPath)-1] != '\\' && strPath[strlen(strPath)-1] != '/') \
  48. strcat(strPath, "\\"); \
  49. }
  50. #define FIX_CSTRING_PATH(csPath) \
  51. { \
  52. if(csPath.IsEmpty() == FALSE && csPath.GetAt(csPath.GetLength()-1) != '\\' && csPath.GetAt(csPath.GetLength()-1) != '/') \
  53. csPath += "\\"; \
  54. }
  55. #include "DatabaseUtilities.h"
  56. CString GetIPAddress();
  57. CString GetComputerName();
  58. #define FUNC __FUNCTION__
  59. #define FUNCSIG __FUNCSIG__
  60. void AppendToFile(const TCHAR* fn, const TCHAR *msg);
  61. #define Log(msg) log(msg, false, __FILE__, __LINE__)
  62. void log(const TCHAR* msg, bool bFromSendRecieve = false, CString csFile = _T(""), long lLine = -1);
  63. CString GetErrorString(int err);
  64. double IdleSeconds();
  65. #define LogSendRecieveInfo(cs) logsendrecieveinfo(cs, __FILE__, __LINE__);
  66. void logsendrecieveinfo(CString cs, CString csFile = _T(""), long lLine = -1);
  67. // Utility Functions
  68. CString StrF(const TCHAR * pszFormat, ...);
  69. // called after determining that the preceding character is a backslash
  70. BYTE GetEscapeChar( BYTE ch );
  71. CString RemoveEscapes( const TCHAR* str );
  72. CString GetWndText( HWND hWnd );
  73. // returns true if the given window is owned by this process
  74. bool IsAppWnd( HWND hWnd );
  75. // Global Memory Helper Functions
  76. BOOL IsValid(HGLOBAL hGlobal);
  77. void CopyToGlobalHP(HGLOBAL hDest, LPVOID pBuf, SIZE_T ulBufLen);
  78. void CopyToGlobalHH(HGLOBAL hDest, HGLOBAL hSource, SIZE_T ulBufLen);
  79. HGLOBAL NewGlobalP(LPVOID pBuf, SIZE_T nLen);
  80. HGLOBAL NewGlobalH(HGLOBAL hSource, SIZE_T nLen);
  81. HGLOBAL NewGlobal(SIZE_T nLen);
  82. int CompareGlobalHP(HGLOBAL hLeft, LPVOID pBuf, SIZE_T ulBufLen);
  83. int CompareGlobalHH(HGLOBAL hLeft, HGLOBAL hRight, SIZE_T ulBufLen);
  84. BOOL EncryptString(CString &csString, UCHAR*& pOutput, int &nLenOutput);
  85. BOOL DecryptString(UCHAR *pData, int nLenIn, UCHAR*& pOutput, int &nLenOutput);
  86. int GetScreenWidth();
  87. int GetScreenHeight();
  88. CLIPFORMAT GetFormatID(LPCTSTR cbName);
  89. CString GetFormatName(CLIPFORMAT cbType);
  90. BOOL PreTranslateGuiDll(MSG *pMsg);
  91. CString GetFilePath(CString csFullPath);
  92. CString GetFileName(CString csFileName);
  93. BOOL EnsureWindowVisible(CRect *pcrRect);
  94. CRect DefaultMonitorRect();
  95. CRect MonitorRectFromRect(CRect rect);
  96. CRect CenterRect(CRect startingRect);
  97. CRect CenterRectFromRect(CRect startingRect, CRect outerRect);
  98. __int64 GetLastWriteTime(const CString &csFile);
  99. //Message to the main window to show icon or not
  100. #define WM_SHOW_TRAY_ICON WM_USER + 200
  101. #define WM_SETCONNECT WM_USER + 201
  102. #define WM_CV_IS_CONNECTED WM_USER + 202
  103. #define WM_CLOSE_APP WM_USER + 204
  104. #define WM_REFRESH_VIEW WM_USER + 205
  105. #define WM_CLIPBOARD_COPIED WM_USER + 206
  106. #define WM_ADD_TO_DATABASE_FROM_SOCKET WM_USER + 207
  107. #define WM_SEND_RECIEVE_ERROR WM_USER + 208
  108. #define WM_FOCUS_CHANGED WM_USER + 209
  109. #define WM_CV_GETCONNECT WM_USER + 211
  110. #define WM_EDIT_WND_CLOSING WM_USER + 212
  111. #define WM_SET_CONNECTED WM_USER + 213
  112. #define WM_LOAD_ClIP_ON_CLIPBOARD WM_USER + 214
  113. //defined in tray icon #define WM_CUSTOMIZE_TRAY_MENU WM_USER + 215
  114. //defined in tray icon #define WM_TRAY_MENU_MOUSE_MOVE WM_USER + 216
  115. #define WM_RELOAD_CLIP_AFTER_PASTE WM_USER + 217
  116. #define WM_GLOBAL_CLIPS_CLOSED WM_USER + 218
  117. #define WM_OPTIONS_CLOSED WM_USER + 219
  118. #define WM_SHOW_OPTIONS WM_USER + 220
  119. #define WM_DELETE_CLIPS_CLOSED WM_USER + 221
  120. #define WM_OPEN_CLOSE_WINDWOW WM_USER + 222
  121. #define WM_SAVE_CLIPBOARD WM_USER + 223
  122. #define WM_READD_TASKBAR_ICON WM_USER + 224
  123. #define WM_REOPEN_DATABASE WM_USER + 225
  124. #define WM_SHOW_MSG_WINDOW WM_USER + 226
  125. #define WM_SHOW_DITTO_GROUP WM_USER + 227
  126. #define WM_PLAIN_TEXT_PASTE WM_USER + 228
  127. #if !defined(_BITSET_)
  128. # include <bitset>
  129. #endif // !defined(_BITSET_)
  130. long NewGroupID(int parentID = 0, CString text = "");
  131. BOOL DeleteAllIDs();
  132. BOOL DeleteFormats(int parentID, ARRAY& formatIDs);
  133. __inline BOOL FileExists(LPCTSTR pszFile)
  134. {
  135. return (GetFileAttributes(pszFile) != 0xffffffff);
  136. }
  137. bool IsRunningLimited();
  138. BOOL IsVista();
  139. void DeleteDittoTempFiles(BOOL checkFileLastAccess);
  140. void DeleteFolderFiles(CString csDir, BOOL checkFileLastAccess);
  141. __int64 FileSize(const TCHAR *fileName);
  142. int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, CString postInsert, int linesPerRow);
  143. void OnInitMenuPopupEx(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu, CWnd *pWnd);
  144. CString InternetEncode(CString text);
  145. CString GetProcessName(HWND hWnd, DWORD processId = 0);
  146. void DeleteParamFromRTF(CStringA &test, CStringA find, bool searchForTrailingDigits);
  147. bool RemoveRTFSection(CStringA &str, CStringA section);
  148. CString NewGuidString();
  149. CString FolderPath(int folderId);
  150. #endif // !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)