Misc.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. HGLOBAL NewGlobal(UINT nLen);
  49. int CompareGlobalHP( HGLOBAL hLeft, LPVOID pBuf, ULONG ulBufLen );
  50. int CompareGlobalHH( HGLOBAL hLeft, HGLOBAL hRight, ULONG ulBufLen );
  51. BOOL EncryptString(CString &csString, UCHAR*& pOutput, int &nLenOutput);
  52. BOOL DecryptString(UCHAR *pData, int nLenIn, UCHAR*& pOutput, int &nLenOutput);
  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 LPVOID GetProfileData(CString csName, DWORD &dwLength);
  118. static BOOL SetProfileData(CString csName, LPVOID lpData, DWORD dwLength);
  119. static BOOL SetQuickPasteSize(CSize size);
  120. static void GetQuickPasteSize(CSize &size);
  121. static BOOL SetQuickPastePoint(CPoint point);
  122. static void GetQuickPastePoint(CPoint &point);
  123. static BOOL SetEnableTransparency(BOOL bCheck);
  124. static BOOL GetEnableTransparency();
  125. static BOOL SetTransparencyPercent(long lPercent);
  126. static long GetTransparencyPercent();
  127. static long m_nLinesPerRow;
  128. static BOOL SetLinesPerRow(long lLines);
  129. static long GetLinesPerRow();
  130. static BOOL SetQuickPastePosition(long lPosition);
  131. static long GetQuickPastePosition();
  132. static long CGetSetOptions::GetCopyGap();
  133. static BOOL SetDBPath(CString csPath);
  134. static CString GetDBPath(BOOL bDefault = TRUE);
  135. static void SetCheckForMaxEntries(BOOL bVal);
  136. static BOOL GetCheckForMaxEntries();
  137. static void SetCheckForExpiredEntries(BOOL bVal);
  138. static BOOL GetCheckForExpiredEntries();
  139. static void SetCompactAndRepairOnExit(BOOL bVal);
  140. static BOOL GetCompactAndRepairOnExit();
  141. static void SetMaxEntries(long lVal);
  142. static long GetMaxEntries();
  143. static void SetExpiredEntries(long lVal);
  144. static long GetExpiredEntries();
  145. static void SetTripCopyCount(long lVal);
  146. static long GetTripCopyCount();
  147. static void SetTripPasteCount(long lVal);
  148. static long GetTripPasteCount();
  149. static void SetTripDate(long lDate);
  150. static long GetTripDate();
  151. static void SetTotalCopyCount(long lVal);
  152. static long GetTotalCopyCount();
  153. static void SetTotalPasteCount(long lVal);
  154. static long GetTotalPasteCount();
  155. static void SetTotalDate(long lDate);
  156. static long GetTotalDate();
  157. // the implementations for the following functions were moved out-of-line.
  158. // when they were declared inline, the compiler failed to notice when
  159. // these functions were changed (the linker used an old compiled version)
  160. // (maybe because they are also static?)
  161. static CString GetUpdateFilePath();
  162. static BOOL SetUpdateFilePath(CString cs);
  163. static CString GetUpdateInstallPath();
  164. static BOOL SetUpdateInstallPath(CString cs);
  165. static long GetLastUpdate();
  166. static long SetLastUpdate(long lValue);
  167. static BOOL GetCheckForUpdates();
  168. static BOOL SetCheckForUpdates(BOOL bCheck);
  169. static BOOL m_bUseCtrlNumAccel;
  170. static void SetUseCtrlNumForFirstTenHotKeys(BOOL bVal);
  171. static BOOL GetUseCtrlNumForFirstTenHotKeys();
  172. static BOOL m_bAllowDuplicates;
  173. static void SetAllowDuplicates(BOOL bVal);
  174. static BOOL GetAllowDuplicates();
  175. static BOOL m_bUpdateTimeOnPaste;
  176. static void SetUpdateTimeOnPaste(BOOL bVal);
  177. static BOOL GetUpdateTimeOnPaste();
  178. static BOOL m_bSaveMultiPaste;
  179. static void SetSaveMultiPaste(BOOL bVal);
  180. static BOOL GetSaveMultiPaste();
  181. static BOOL m_bShowPersistent;
  182. static void SetShowPersistent(BOOL bVal);
  183. static BOOL GetShowPersistent();
  184. static BOOL m_bHistoryStartTop;
  185. static void SetHistoryStartTop(BOOL bVal);
  186. static BOOL GetHistoryStartTop();
  187. static void SetShowTextForFirstTenHotKeys(BOOL bVal);
  188. static BOOL GetShowTextForFirstTenHotKeys();
  189. static void SetMainHWND(long lhWnd);
  190. static BOOL GetMainHWND();
  191. static void SetCaptionPos(long lPos);
  192. static long GetCaptionPos();
  193. static void SetAutoHide(BOOL bAutoHide);
  194. static BOOL GetAutoHide();
  195. static long m_bDescTextSize;
  196. static void SetDescTextSize(long lSize);
  197. static long GetDescTextSize();
  198. static BOOL m_bDescShowLeadingWhiteSpace;
  199. static void SetDescShowLeadingWhiteSpace(BOOL bVal);
  200. static BOOL GetDescShowLeadingWhiteSpace();
  201. static BOOL m_bAllwaysShowDescription;
  202. static void SetAllwaysShowDescription(long bShow);
  203. static BOOL GetAllwaysShowDescription();
  204. static long m_bDoubleClickingOnCaptionDoes;
  205. static void SetDoubleClickingOnCaptionDoes(long lOption);
  206. static long GetDoubleClickingOnCaptionDoes();
  207. static BOOL m_bPrompForNewGroupName;
  208. static void SetPrompForNewGroupName(BOOL bOption);
  209. static BOOL GetPrompForNewGroupName();
  210. static BOOL m_bSendPasteOnFirstTenHotKeys;
  211. static void SetSendPasteOnFirstTenHotKeys(BOOL bOption);
  212. static BOOL GetSendPasteOnFirstTenHotKeys();
  213. static CSendClients m_SendClients[MAX_SEND_CLIENTS];
  214. static long m_lAutoSendClientCount;
  215. static void GetClientSendCount();
  216. static void SetSendClients(CSendClients Client, int nPos);
  217. static CSendClients GetSendClients(int nPos);
  218. static CString m_csIPListToPutOnClipboard;
  219. static CString GetListToPutOnClipboard();
  220. static BOOL SetListToPutOnClipboard(CString cs);
  221. static BOOL m_bLogSendReceiveErrors;
  222. static void SetLogSendReceiveErrors(BOOL bOption);
  223. static BOOL GetLogSendReceiveErrors();
  224. static BOOL m_bUseHookDllForFocus;
  225. static BOOL m_HideDittoOnHotKeyIfAlreadyShown;
  226. static BOOL GetHideDittoOnHotKeyIfAlreadyShown();
  227. static void SetHideDittoOnHotKeyIfAlreadyShown(BOOL bVal);
  228. static long m_lPort;
  229. static void SetPort(long lPort);
  230. static long GetPort();
  231. static BOOL GetDisableRecieve();
  232. static void SetDisableRecieve(BOOL bVal);
  233. static BOOL GetFont(LOGFONT &font);
  234. static void SetFont(LOGFONT &font);
  235. static BOOL m_bDrawThumbnail;
  236. static void SetDrawThumbnail(long bDraw);
  237. static BOOL GetDrawThumbnail();
  238. static CString m_csPassword;
  239. static void SetNetworkPassword(CString csPassword);
  240. static CString GetNetworkPassword();
  241. static BOOL m_bDrawRTF;
  242. static void SetDrawRTF(long bDraw);
  243. static BOOL GetDrawRTF();
  244. static BOOL m_bMultiPasteReverse;
  245. static void SetMultiPasteReverse(bool bVal);
  246. static BOOL GetMultiPasteReverse();
  247. static CString m_csPlaySoundOnCopy;
  248. static void SetPlaySoundOnCopy(CString cs);
  249. static CString GetPlaySoundOnCopy();
  250. static CStringArray m_csNetworkPasswordArray;
  251. /*
  252. BOOL IsAutoRun();
  253. void SetAutoRun(BOOL bRun);
  254. CString GetExeFileName();
  255. */
  256. };
  257. // global for easy access and for initialization of fast access variables
  258. extern CGetSetOptions g_Opt;
  259. /*------------------------------------------------------------------*\
  260. CHotKey - a single system-wide hotkey
  261. \*------------------------------------------------------------------*/
  262. class CHotKey
  263. {
  264. public:
  265. CString m_Name;
  266. ATOM m_Atom;
  267. DWORD m_Key; //704 is ctrl-tilda
  268. bool m_bIsRegistered;
  269. bool m_bUnRegisterOnShowDitto;
  270. CHotKey( CString name, DWORD defKey = 0, bool bUnregOnShowDitto = false );
  271. ~CHotKey();
  272. bool IsRegistered() { return m_bIsRegistered; }
  273. CString GetName() { return m_Name; }
  274. DWORD GetKey() { return m_Key; }
  275. void SetKey( DWORD key, bool bSave = false );
  276. // profile
  277. void LoadKey();
  278. bool SaveKey();
  279. void CopyFromCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID);
  280. void CopyToCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID);
  281. // CString GetKeyAsText();
  282. // void SetKeyFromText( CString text );
  283. static BOOL ValidateHotKey(DWORD dwHotKey);
  284. static UINT GetModifier(DWORD dwHotKey);
  285. UINT GetModifier() { return GetModifier(m_Key); }
  286. bool Register();
  287. bool Unregister(bool bOnShowingDitto = false);
  288. };
  289. /*------------------------------------------------------------------*\
  290. CHotKeys - Manages system-wide hotkeys
  291. \*------------------------------------------------------------------*/
  292. class CHotKeys : public CArray<CHotKey*,CHotKey*>
  293. {
  294. public:
  295. HWND m_hWnd;
  296. CHotKeys();
  297. ~CHotKeys();
  298. void Init( HWND hWnd ) { m_hWnd = hWnd; }
  299. int Find( CHotKey* pHotKey );
  300. bool Remove( CHotKey* pHotKey ); // pHotKey is NOT deleted.
  301. // profile load / save
  302. void LoadAllKeys();
  303. void SaveAllKeys();
  304. void RegisterAll(bool bMsgOnError = false);
  305. void UnregisterAll(bool bMsgOnError = false, bool bOnShowDitto = false);
  306. void GetKeys( ARRAY& keys );
  307. void SetKeys( ARRAY& keys, bool bSave = false ); // caution! this alters hotkeys based upon corresponding indexes
  308. static bool FindFirstConflict( ARRAY& keys, int* pX = NULL, int* pY = NULL );
  309. // if true, pX and pY (if valid) are set to the index of the conflicting hotkeys.
  310. bool FindFirstConflict( int* pX = NULL, int* pY = NULL );
  311. };
  312. extern CHotKeys g_HotKeys;
  313. /*------------------------------------------------------------------*\
  314. CAccel - an Accelerator (in-app hotkey)
  315. - the win32 CreateAcceleratorTable using ACCEL was insufficient
  316. because it only allowed a WORD for the cmd associated with it.
  317. \*------------------------------------------------------------------*/
  318. #define ACCEL_VKEY(key) LOBYTE(key)
  319. #define ACCEL_MOD(key) HIBYTE(key)
  320. #define ACCEL_MAKEKEY(vkey,mod) ((mod << 8) | vkey)
  321. class CAccel
  322. {
  323. public:
  324. DWORD Key; // directly uses the CHotKeyCtrl format
  325. DWORD Cmd;
  326. CAccel( DWORD key=0, DWORD cmd=0 ) { Key = key; Cmd = cmd; }
  327. };
  328. /*------------------------------------------------------------------*\
  329. CAccels - Manages a set of CAccel
  330. \*------------------------------------------------------------------*/
  331. class CAccels
  332. {
  333. public:
  334. CAccels();
  335. CMap<DWORD, DWORD, DWORD, DWORD> m_Map;
  336. void AddAccel( CAccel& a );
  337. // handles a key's first WM_KEYDOWN or WM_SYSKEYDOWN message.
  338. // it uses GetKeyState to test for modifiers.
  339. // returns a pointer to the internal CAccel if it matches the given key or NULL
  340. bool OnMsg( MSG* pMsg , DWORD &dID );
  341. };
  342. // returns a BYTE representing the current GetKeyState modifiers:
  343. // HOTKEYF_SHIFT, HOTKEYF_CONTROL, HOTKEYF_ALT
  344. BYTE GetKeyStateModifiers();
  345. /*------------------------------------------------------------------*\
  346. CTokenizer - Tokenizes a string using given delimiters
  347. \*------------------------------------------------------------------*/
  348. // Based upon:
  349. // Date: Monday, October 22, 2001
  350. // Autor: Eduardo Velasquez
  351. // Description: Tokenizer class for CStrings. Works like strtok.
  352. ///////////////
  353. #if !defined(_BITSET_)
  354. # include <bitset>
  355. #endif // !defined(_BITSET_)
  356. class CTokenizer
  357. {
  358. public:
  359. CString m_cs;
  360. std::bitset<256> m_delim;
  361. int m_nCurPos;
  362. CTokenizer(const CString& cs, const CString& csDelim);
  363. void SetDelimiters(const CString& csDelim);
  364. bool Next(CString& cs);
  365. CString Tail() const;
  366. };
  367. /*------------------------------------------------------------------*\
  368. Global ToolTip Manual Control Functions
  369. \*------------------------------------------------------------------*/
  370. void InitToolInfo( TOOLINFO& ti ); // initializes toolinfo with uid 0
  371. /*------------------------------------------------------------------*\
  372. CPopup - a tooltip that pops up manually (when Show is called).
  373. - technique learned from codeproject "ToolTipZen" by "Zarembo Maxim"
  374. \*------------------------------------------------------------------*/
  375. class CPopup
  376. {
  377. public:
  378. bool m_bOwnTT;
  379. HWND m_hTTWnd; // handle to the ToolTip control
  380. TOOLINFO m_TI; // struct specifying info about tool in ToolTip control
  381. bool m_bIsShowing;
  382. bool m_bTop; // true if m_Pos.x is the top, false if the bottom
  383. bool m_bLeft; // true if m_Pos.y is the left, false if the right
  384. bool m_bCenterY; // true if m_Pos is the y center, false if corner
  385. bool m_bCenterX; // true if m_Pos is the x center, false if corner
  386. HWND m_hWndPosRelativeTo;
  387. CPoint m_Pos;
  388. int m_ScreenMaxX;
  389. int m_ScreenMaxY;
  390. HWND m_hWndInsertAfter;
  391. bool m_bAllowShow; // used by SafeShow to determine whether to show or not
  392. CString m_csToolTipText;
  393. CPopup();
  394. CPopup( int x, int y, HWND hWndPosRelativeTo = NULL, HWND hWndInsertAfter = HWND_TOP );
  395. ~CPopup();
  396. void Init();
  397. void SetTTWnd( HWND hTTWnd = NULL, TOOLINFO* pTI = NULL );
  398. void CreateToolTip();
  399. void SetTimeout( int timeout );
  400. void AdjustPos( CPoint& pos );
  401. void SetPos( CPoint& pos );
  402. void SetPosInfo( bool bTop, bool bCenterY, bool bLeft, bool bCenterX );
  403. void SendToolTipText( CString text );
  404. void Show( CString text, CPoint pos, bool bAdjustPos = true );
  405. void Show( CString text );
  406. void AllowShow( CString text ); // only shows if m_bAllowShow is true
  407. void Hide();
  408. };
  409. #endif // !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)