Misc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. #define ONE_MINUTE 60000
  7. #define DELETE_PTR(ptr) { if(ptr) {delete ptr; ptr = NULL;} }
  8. #define CATCHDAO \
  9. catch(CDaoException* e) \
  10. { \
  11. e->ReportError(); \
  12. ASSERT(0); \
  13. e->Delete(); \
  14. }
  15. #include "DatabaseUtilities.h"
  16. // Debugging
  17. #ifdef _DEBUG
  18. #define LOG(x) Log(x)
  19. #else
  20. #define LOG(x)
  21. #endif
  22. #define FUNC __FUNCTION__
  23. #define FUNCSIG __FUNCSIG__
  24. void AppendToFile( const char* fn, const char *msg );
  25. void Log( const char* msg );
  26. CString GetErrorString( int err );
  27. #define MS_VC_EXCEPTION 0x406d1388
  28. typedef struct tagTHREADNAME_INFO
  29. {
  30. DWORD dwType; // must be 0x1000
  31. LPCSTR szName; // pointer to name (in same addr space)
  32. DWORD dwThreadID; // thread ID (-1 caller thread)
  33. DWORD dwFlags; // reserved for future use, most be zero
  34. } THREADNAME_INFO;
  35. void SetThreadName(DWORD dwThreadID, LPCTSTR szThreadName);
  36. // Utility Functions
  37. CString StrF(const char * pszFormat, ...);
  38. // called after determining that the preceding character is a backslash
  39. BYTE GetEscapeChar( BYTE ch );
  40. CString RemoveEscapes( const char* str );
  41. CString GetWndText( HWND hWnd );
  42. // returns true if the given window is owned by this process
  43. bool IsAppWnd( HWND hWnd );
  44. // returns the current Focus window even if it is not owned by our thread.
  45. HWND GetFocusWnd(CPoint *pPointCaret = NULL);
  46. // Global Memory Helper Functions
  47. void CopyToGlobalHP( HGLOBAL hDest, LPVOID pBuf, ULONG ulBufLen );
  48. void CopyToGlobalHH( HGLOBAL hDest, HGLOBAL hSource, ULONG ulBufLen );
  49. HGLOBAL NewGlobalP( LPVOID pBuf, UINT nLen );
  50. HGLOBAL NewGlobalH( HGLOBAL hSource, UINT nLen );
  51. int CompareGlobalHP( HGLOBAL hLeft, LPVOID pBuf, ULONG ulBufLen );
  52. int CompareGlobalHH( HGLOBAL hLeft, HGLOBAL hRight, ULONG ulBufLen );
  53. void GetMonitorRect(int iMonitor, LPRECT lpDestRect);
  54. int GetMonitorFromRect(LPRECT lpMonitorRect);
  55. long DoOptions(CWnd *pParent);
  56. CLIPFORMAT GetFormatID(LPCSTR cbName);
  57. CString GetFormatName(CLIPFORMAT cbType);
  58. BOOL PreTranslateGuiDll(MSG *pMsg);
  59. CString GetFilePath(CString csFullPath);
  60. #define POS_AT_CARET 1
  61. #define POS_AT_CURSOR 2
  62. #define POS_AT_PREVIOUS 3
  63. //Message to the main window to show icon or not
  64. #define WM_SHOW_TRAY_ICON WM_USER + 200
  65. #define WM_CV_RECONNECT WM_USER + 201
  66. #define WM_CV_IS_CONNECTED WM_USER + 202
  67. #define WM_COPYPROPERTIES WM_USER + 203
  68. #define WM_CLOSE_APP WM_USER + 204
  69. #define WM_REFRESH_VIEW WM_USER + 205
  70. #define WM_CLIPBOARD_COPIED WM_USER + 206
  71. #define REG_PATH "Software\\Ditto"
  72. /*------------------------------------------------------------------*\
  73. CGetSetOptions - Manages Application Registry settings
  74. \*------------------------------------------------------------------*/
  75. class CGetSetOptions
  76. {
  77. public:
  78. CGetSetOptions();
  79. virtual ~CGetSetOptions();
  80. //System Tray Icon
  81. static BOOL GetShowIconInSysTray();
  82. static BOOL SetShowIconInSysTray(BOOL bShow);
  83. //Run At StartUp
  84. static BOOL GetRunOnStartUp();
  85. static void SetRunOnStartUp(BOOL bRun);
  86. static CString GetExeFileName();
  87. static CString GetAppName();
  88. static BOOL SetProfileLong(CString csName, long lValue);
  89. static long GetProfileLong(CString csName, long bDefaultValue = -1);
  90. static CString GetProfileString(CString csName, CString csDefault);
  91. static BOOL SetProfileString(CString csName, CString csValue);
  92. static BOOL SetQuickPasteSize(CSize size);
  93. static void GetQuickPasteSize(CSize &size);
  94. static BOOL SetQuickPastePoint(CPoint point);
  95. static void GetQuickPastePoint(CPoint &point);
  96. static BOOL SetEnableTransparency(BOOL bCheck);
  97. static BOOL GetEnableTransparency();
  98. static BOOL SetTransparencyPercent(long lPercent);
  99. static long GetTransparencyPercent();
  100. static BOOL SetLinesPerRow(long lLines);
  101. static long GetLinesPerRow();
  102. static BOOL SetQuickPastePosition(long lPosition);
  103. static long GetQuickPastePosition();
  104. static long CGetSetOptions::GetCopyGap();
  105. static BOOL SetDBPath(CString csPath);
  106. static CString GetDBPath(BOOL bDefault = TRUE);
  107. static void SetCheckForMaxEntries(BOOL bVal);
  108. static BOOL GetCheckForMaxEntries();
  109. static void SetCheckForExpiredEntries(BOOL bVal);
  110. static BOOL GetCheckForExpiredEntries();
  111. static void SetCompactAndRepairOnExit(BOOL bVal);
  112. static BOOL GetCompactAndRepairOnExit();
  113. static void SetMaxEntries(long lVal);
  114. static long GetMaxEntries();
  115. static void SetExpiredEntries(long lVal);
  116. static long GetExpiredEntries();
  117. static void SetTripCopyCount(long lVal);
  118. static long GetTripCopyCount();
  119. static void SetTripPasteCount(long lVal);
  120. static long GetTripPasteCount();
  121. static void SetTripDate(long lDate);
  122. static long GetTripDate();
  123. static void SetTotalCopyCount(long lVal);
  124. static long GetTotalCopyCount();
  125. static void SetTotalPasteCount(long lVal);
  126. static long GetTotalPasteCount();
  127. static void SetTotalDate(long lDate);
  128. static long GetTotalDate();
  129. // the implementations for the following functions were moved out-of-line.
  130. // when they were declared inline, the compiler failed to notice when
  131. // these functions were changed (the linker used an old compiled version)
  132. // (maybe because they are also static?)
  133. static CString GetUpdateFilePath();
  134. static BOOL SetUpdateFilePath(CString cs);
  135. static CString GetUpdateInstallPath();
  136. static BOOL SetUpdateInstallPath(CString cs);
  137. static long GetLastUpdate();
  138. static long SetLastUpdate(long lValue);
  139. static BOOL GetCheckForUpdates();
  140. static BOOL SetCheckForUpdates(BOOL bCheck);
  141. static BOOL m_bUseCtrlNumAccel;
  142. static void SetUseCtrlNumForFirstTenHotKeys(BOOL bVal);
  143. static BOOL GetUseCtrlNumForFirstTenHotKeys();
  144. static BOOL m_bAllowDuplicates;
  145. static void SetAllowDuplicates(BOOL bVal);
  146. static BOOL GetAllowDuplicates();
  147. static BOOL m_bUpdateTimeOnPaste;
  148. static void SetUpdateTimeOnPaste(BOOL bVal);
  149. static BOOL GetUpdateTimeOnPaste();
  150. static BOOL m_bSaveMultiPaste;
  151. static void SetSaveMultiPaste(BOOL bVal);
  152. static BOOL GetSaveMultiPaste();
  153. static BOOL m_bShowPersistent;
  154. static void SetShowPersistent(BOOL bVal);
  155. static BOOL GetShowPersistent();
  156. static BOOL m_bHistoryStartTop;
  157. static void SetHistoryStartTop(BOOL bVal);
  158. static BOOL GetHistoryStartTop();
  159. static void SetShowTextForFirstTenHotKeys(BOOL bVal);
  160. static BOOL GetShowTextForFirstTenHotKeys();
  161. static void SetMainHWND(long lhWnd);
  162. static BOOL GetMainHWND();
  163. /*
  164. BOOL IsAutoRun();
  165. void SetAutoRun(BOOL bRun);
  166. CString GetExeFileName();
  167. */
  168. };
  169. // global for easy access and for initialization of fast access variables
  170. extern CGetSetOptions g_Opt;
  171. /*------------------------------------------------------------------*\
  172. CHotKey - a single system-wide hotkey
  173. \*------------------------------------------------------------------*/
  174. class CHotKey
  175. {
  176. public:
  177. CString m_Name;
  178. ATOM m_Atom;
  179. DWORD m_Key; //704 is ctrl-tilda
  180. bool m_bIsRegistered;
  181. CHotKey( CString name, DWORD defKey = 0 );
  182. ~CHotKey();
  183. bool IsRegistered() { return m_bIsRegistered; }
  184. CString GetName() { return m_Name; }
  185. DWORD GetKey() { return m_Key; }
  186. void SetKey( DWORD key, bool bSave = false );
  187. // profile
  188. void LoadKey();
  189. bool SaveKey();
  190. void CopyFromCtrl( CHotKeyCtrl& ctrl ) { SetKey( ctrl.GetHotKey() ); }
  191. void CopyToCtrl( CHotKeyCtrl& ctrl ) { ctrl.SetHotKey(LOBYTE(m_Key),HIBYTE(m_Key)); }
  192. // CString GetKeyAsText();
  193. // void SetKeyFromText( CString text );
  194. static BOOL ValidateHotKey(DWORD dwHotKey);
  195. static UINT GetModifier(DWORD dwHotKey);
  196. UINT GetModifier() { return GetModifier(m_Key); }
  197. bool Register();
  198. bool Unregister();
  199. };
  200. /*------------------------------------------------------------------*\
  201. CHotKeys - Manages system-wide hotkeys
  202. \*------------------------------------------------------------------*/
  203. class CHotKeys : public CArray<CHotKey*>
  204. {
  205. public:
  206. HWND m_hWnd;
  207. CHotKeys();
  208. ~CHotKeys();
  209. void Init( HWND hWnd ) { m_hWnd = hWnd; }
  210. int Find( CHotKey* pHotKey );
  211. bool Remove( CHotKey* pHotKey ); // pHotKey is NOT deleted.
  212. // profile load / save
  213. void LoadAllKeys();
  214. void SaveAllKeys();
  215. void RegisterAll( bool bMsgOnError = false );
  216. void UnregisterAll( bool bMsgOnError = false );
  217. void GetKeys( ARRAY& keys );
  218. void SetKeys( ARRAY& keys, bool bSave = false ); // caution! this alters hotkeys based upon corresponding indexes
  219. static bool FindFirstConflict( ARRAY& keys, int* pX = NULL, int* pY = NULL );
  220. // if true, pX and pY (if valid) are set to the index of the conflicting hotkeys.
  221. bool FindFirstConflict( int* pX = NULL, int* pY = NULL );
  222. };
  223. extern CHotKeys g_HotKeys;
  224. /*------------------------------------------------------------------*\
  225. CAccel - an Accelerator (in-app hotkey)
  226. - the win32 CreateAcceleratorTable using ACCEL was insufficient
  227. because it only allowed a WORD for the cmd associated with it.
  228. \*------------------------------------------------------------------*/
  229. #define ACCEL_VKEY(key) LOBYTE(key)
  230. #define ACCEL_MOD(key) HIBYTE(key)
  231. #define ACCEL_MAKEKEY(vkey,mod) ((mod << 8) | vkey)
  232. class CAccel
  233. {
  234. public:
  235. DWORD Key; // directly uses the CHotKeyCtrl format
  236. DWORD Cmd;
  237. CAccel( DWORD key=0, DWORD cmd=0 ) { Key = key; Cmd = cmd; }
  238. };
  239. /*------------------------------------------------------------------*\
  240. CAccels - Manages a set of CAccel
  241. \*------------------------------------------------------------------*/
  242. class CAccels : public CArray<CAccel>
  243. {
  244. public:
  245. CArray<CAccel*> m_Index;
  246. CAccels();
  247. void Clear() { SetSize(0); }
  248. void AddAccel( CAccel& a );
  249. // "bBigAndFast" means:
  250. // - big: about 1024 bytes larger
  251. // - fast: approx. constant speed lookup versus binary search
  252. void StartBuildingTable( bool bBigAndFast = true, int size = -1 );
  253. void FinishBuildingTable();
  254. // handles a key's first WM_KEYDOWN or WM_SYSKEYDOWN message.
  255. // it uses GetKeyState to test for modifiers.
  256. // returns a pointer to the internal CAccel if it matches the given key or NULL
  257. CAccel* OnMsg( MSG* pMsg );
  258. };
  259. // returns a BYTE representing the current GetKeyState modifiers:
  260. // HOTKEYF_SHIFT, HOTKEYF_CONTROL, HOTKEYF_ALT
  261. BYTE GetKeyStateModifiers();
  262. /*------------------------------------------------------------------*\
  263. CTokenizer - Tokenizes a string using given delimiters
  264. \*------------------------------------------------------------------*/
  265. // Based upon:
  266. // Date: Monday, October 22, 2001
  267. // Autor: Eduardo Velasquez
  268. // Description: Tokenizer class for CStrings. Works like strtok.
  269. ///////////////
  270. #if !defined(_BITSET_)
  271. # include <bitset>
  272. #endif // !defined(_BITSET_)
  273. class CTokenizer
  274. {
  275. public:
  276. CString m_cs;
  277. std::bitset<256> m_delim;
  278. int m_nCurPos;
  279. CTokenizer(const CString& cs, const CString& csDelim);
  280. void SetDelimiters(const CString& csDelim);
  281. bool Next(CString& cs);
  282. CString Tail() const;
  283. };
  284. /*------------------------------------------------------------------*\
  285. Global ToolTip Manual Control Functions
  286. \*------------------------------------------------------------------*/
  287. void InitToolInfo( TOOLINFO& ti ); // initializes toolinfo with uid 0
  288. /*------------------------------------------------------------------*\
  289. CPopup - a tooltip that pops up manually (when Show is called).
  290. - technique learned from codeproject "ToolTipZen" by "Zarembo Maxim"
  291. \*------------------------------------------------------------------*/
  292. class CPopup
  293. {
  294. public:
  295. bool m_bOwnTT;
  296. HWND m_hTTWnd; // handle to the ToolTip control
  297. TOOLINFO m_TI; // struct specifying info about tool in ToolTip control
  298. bool m_bIsShowing;
  299. CPoint m_Pos;
  300. CPopup();
  301. CPopup( CPoint& pos, HWND hTTWnd = NULL );
  302. ~CPopup();
  303. void Init( HWND hTTWnd = NULL, TOOLINFO* pTI = NULL );
  304. void CreateToolTip();
  305. void SetTimeout( int timeout );
  306. void Show( CString text, CPoint& pos );
  307. void Show( CString text );
  308. void Hide();
  309. };
  310. #endif // !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)