Misc.h 15 KB

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