Misc.h 13 KB

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