Misc.h 15 KB

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