Misc.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. //Handle foreign keyboards pressing ALT_GR (right alt), this simulates a control press
  14. //http://compgroups.net/comp.os.programmer.win32/alt-gr-key-and-left-ctrl/2840252
  15. #define CONTROL_PRESSED ((::GetKeyState(VK_CONTROL) & 0x8000) && (((GetKeyState(VK_RMENU) < 0) && (GetKeyState(VK_LCONTROL) < 0)) == FALSE))
  16. #define ONE_MINUTE 60000
  17. #define ONE_HOUR 3600000
  18. #define ONE_DAY 86400000
  19. class CopyReasonEnum
  20. {
  21. public:
  22. enum CopyReason
  23. {
  24. COPY_TO_UNKOWN,
  25. COPY_TO_GROUP,
  26. COPY_TO_BUFFER
  27. };
  28. };
  29. #define INVALID_STICKY -(2147483647)
  30. #define CATCH_SQLITE_EXCEPTION \
  31. catch (CppSQLite3Exception& e) \
  32. { \
  33. Log(StrF(_T("SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage())); \
  34. ASSERT(FALSE); \
  35. } \
  36. #define CATCH_SQLITE_EXCEPTION_AND_RETURN(bRet) \
  37. catch (CppSQLite3Exception& e) \
  38. { \
  39. Log(StrF(_T("SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage())); \
  40. ASSERT(FALSE); \
  41. return bRet; \
  42. } \
  43. #define FIX_PATH(strPath) \
  44. { \
  45. if (strPath[strlen(strPath)-1] != '\\' && strPath[strlen(strPath)-1] != '/') \
  46. strcat(strPath, "\\"); \
  47. }
  48. #define FIX_CSTRING_PATH(csPath) \
  49. { \
  50. if(csPath.IsEmpty() == FALSE && csPath.GetAt(csPath.GetLength()-1) != '\\' && csPath.GetAt(csPath.GetLength()-1) != '/') \
  51. csPath += "\\"; \
  52. }
  53. #include "DatabaseUtilities.h"
  54. CString GetIPAddress();
  55. CString GetComputerName();
  56. #define FUNC __FUNCTION__
  57. #define FUNCSIG __FUNCSIG__
  58. void AppendToFile(const TCHAR* fn, const TCHAR *msg);
  59. #define Log(msg) log(msg, false, __FILE__, __LINE__)
  60. void log(const TCHAR* msg, bool bFromSendRecieve = false, CString csFile = _T(""), long lLine = -1);
  61. CString GetErrorString(int err);
  62. double IdleSeconds();
  63. #define LogSendRecieveInfo(cs) logsendrecieveinfo(cs, __FILE__, __LINE__);
  64. void logsendrecieveinfo(CString cs, CString csFile = _T(""), long lLine = -1);
  65. // Utility Functions
  66. CString StrF(const TCHAR * pszFormat, ...);
  67. // called after determining that the preceding character is a backslash
  68. BYTE GetEscapeChar( BYTE ch );
  69. CString RemoveEscapes( const TCHAR* str );
  70. CString GetWndText( HWND hWnd );
  71. // returns true if the given window is owned by this process
  72. bool IsAppWnd( HWND hWnd );
  73. // Global Memory Helper Functions
  74. BOOL IsValid(HGLOBAL hGlobal);
  75. void CopyToGlobalHP(HGLOBAL hDest, LPVOID pBuf, SIZE_T ulBufLen);
  76. void CopyToGlobalHH(HGLOBAL hDest, HGLOBAL hSource, SIZE_T ulBufLen);
  77. HGLOBAL NewGlobalP(LPVOID pBuf, SIZE_T nLen);
  78. HGLOBAL NewGlobalH(HGLOBAL hSource, SIZE_T nLen);
  79. HGLOBAL NewGlobal(SIZE_T nLen);
  80. int CompareGlobalHP(HGLOBAL hLeft, LPVOID pBuf, SIZE_T ulBufLen);
  81. int CompareGlobalHH(HGLOBAL hLeft, HGLOBAL hRight, SIZE_T ulBufLen);
  82. BOOL EncryptString(CString &csString, UCHAR*& pOutput, int &nLenOutput);
  83. BOOL DecryptString(UCHAR *pData, int nLenIn, UCHAR*& pOutput, int &nLenOutput);
  84. int GetScreenWidth();
  85. int GetScreenHeight();
  86. void GetMonitorRect(int iMonitor, LPRECT lpDestRect);
  87. int GetMonitorFromRect(LPRECT lpMonitorRect);
  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 CenterRect(CRect startingRect);
  95. CRect CenterRectFromRect(CRect startingRect, CRect outerRect);
  96. __int64 GetLastWriteTime(const CString &csFile);
  97. //Message to the main window to show icon or not
  98. #define WM_SHOW_TRAY_ICON WM_USER + 200
  99. #define WM_SETCONNECT WM_USER + 201
  100. #define WM_CV_IS_CONNECTED WM_USER + 202
  101. #define WM_CLOSE_APP WM_USER + 204
  102. #define WM_REFRESH_VIEW WM_USER + 205
  103. #define WM_CLIPBOARD_COPIED WM_USER + 206
  104. #define WM_ADD_TO_DATABASE_FROM_SOCKET WM_USER + 207
  105. #define WM_SEND_RECIEVE_ERROR WM_USER + 208
  106. #define WM_FOCUS_CHANGED WM_USER + 209
  107. #define WM_CV_GETCONNECT WM_USER + 211
  108. #define WM_EDIT_WND_CLOSING WM_USER + 212
  109. #define WM_SET_CONNECTED WM_USER + 213
  110. #define WM_LOAD_ClIP_ON_CLIPBOARD WM_USER + 214
  111. //defined in tray icon #define WM_CUSTOMIZE_TRAY_MENU WM_USER + 215
  112. //defined in tray icon #define WM_TRAY_MENU_MOUSE_MOVE WM_USER + 216
  113. #define WM_RELOAD_CLIP_AFTER_PASTE WM_USER + 217
  114. #define WM_GLOBAL_CLIPS_CLOSED WM_USER + 218
  115. #define WM_OPTIONS_CLOSED WM_USER + 219
  116. #define WM_SHOW_OPTIONS WM_USER + 220
  117. #define WM_DELETE_CLIPS_CLOSED WM_USER + 221
  118. #define WM_OPEN_CLOSE_WINDWOW WM_USER + 222
  119. #define WM_SAVE_CLIPBOARD WM_USER + 223
  120. #define WM_READD_TASKBAR_ICON WM_USER + 224
  121. #define WM_REOPEN_DATABASE WM_USER + 225
  122. #define WM_SHOW_MSG_WINDOW WM_USER + 226
  123. #define WM_SHOW_DITTO_GROUP WM_USER + 227
  124. #if !defined(_BITSET_)
  125. # include <bitset>
  126. #endif // !defined(_BITSET_)
  127. long NewGroupID(int parentID = 0, CString text = "");
  128. BOOL DeleteAllIDs();
  129. BOOL DeleteFormats(int parentID, ARRAY& formatIDs);
  130. __inline BOOL FileExists(LPCTSTR pszFile)
  131. {
  132. return (GetFileAttributes(pszFile) != 0xffffffff);
  133. }
  134. bool IsRunningLimited();
  135. BOOL IsVista();
  136. void DeleteDittoTempFiles(BOOL checkFileLastAccess);
  137. void DeleteFolderFiles(CString csDir, BOOL checkFileLastAccess);
  138. __int64 FileSize(const TCHAR *fileName);
  139. int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, CString postInsert, int linesPerRow);
  140. void OnInitMenuPopupEx(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu, CWnd *pWnd);
  141. CString InternetEncode(CString text);
  142. bool WriteCF_DIBToFile(CString csPath, LPVOID data, ULONG size);
  143. CString GetProcessName(HWND hWnd, DWORD processId = 0);
  144. void DeleteParamFromRTF(CStringA &test, CStringA find, bool searchForTrailingDigits);
  145. bool RemoveRTFSection(CStringA &str, CStringA section);
  146. #endif // !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)