Misc.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368
  1. #include "stdafx.h"
  2. #include "CP_Main.h"
  3. #include "Misc.h"
  4. #include "OptionsSheet.h"
  5. #include "AlphaBlend.h"
  6. // Debug Functions
  7. CString GetIPAddress()
  8. {
  9. WORD wVersionRequested;
  10. WSADATA wsaData;
  11. char name[255];
  12. CString IP;
  13. PHOSTENT hostinfo;
  14. wVersionRequested = MAKEWORD(2,0);
  15. if (WSAStartup(wVersionRequested, &wsaData)==0)
  16. {
  17. if(gethostname(name, sizeof(name))==0)
  18. {
  19. if((hostinfo=gethostbyname(name)) != NULL)
  20. {
  21. IP = inet_ntoa(*(struct in_addr*)* hostinfo->h_addr_list);
  22. }
  23. }
  24. WSACleanup();
  25. }
  26. IP.MakeUpper();
  27. return IP;
  28. }
  29. CString GetComputerName()
  30. {
  31. char ComputerName[MAX_COMPUTERNAME_LENGTH+1]="";
  32. DWORD Size=MAX_COMPUTERNAME_LENGTH+1;
  33. GetComputerName(ComputerName, &Size);
  34. CString cs(ComputerName);
  35. cs.MakeUpper();
  36. return cs;
  37. }
  38. void AppendToFile( const char* fn, const char* msg )
  39. {
  40. FILE *file = fopen(fn, "a");
  41. ASSERT( file );
  42. fprintf(file, msg);
  43. fclose(file);
  44. }
  45. void Log(const char* msg, bool bFromSendRecieve)
  46. {
  47. ASSERT(AfxIsValidString(msg));
  48. CTime time = CTime::GetCurrentTime();
  49. CString csText = time.Format("[%Y/%m/%d %I:%M:%S %p] ");
  50. csText += msg;
  51. csText += "\n";
  52. //TRACE(csText);
  53. OutputDebugString(csText);
  54. #ifndef _DEBUG
  55. if(!bFromSendRecieve)
  56. {
  57. if(!g_Opt.m_bEnableDebugLogging)
  58. return;
  59. }
  60. #endif
  61. CString csFile = CGetSetOptions::GetExeFileName();
  62. csFile = GetFilePath(csFile);
  63. csFile += "Ditto.log";
  64. AppendToFile(csFile, csText);
  65. }
  66. void LogSendRecieveInfo(CString cs)
  67. {
  68. if(g_Opt.m_bLogSendReceiveErrors)
  69. Log(cs, true);
  70. }
  71. CString GetErrorString( int err )
  72. {
  73. CString str;
  74. LPVOID lpMsgBuf;
  75. ::FormatMessage(
  76. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  77. NULL,
  78. err,
  79. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  80. (LPTSTR) &lpMsgBuf,
  81. 0,
  82. NULL
  83. );
  84. str = (LPCTSTR) lpMsgBuf;
  85. // Display the string.
  86. // ::MessageBox( NULL, lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
  87. ::LocalFree( lpMsgBuf );
  88. return str;
  89. }
  90. void SetThreadName(DWORD dwThreadID, LPCTSTR szThreadName)
  91. {
  92. THREADNAME_INFO info;
  93. info.dwType = 0x1000;
  94. info.szName = szThreadName;
  95. info.dwThreadID = dwThreadID;
  96. info.dwFlags = 0;
  97. __try
  98. {
  99. RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (DWORD *)&info);
  100. }
  101. __except (EXCEPTION_CONTINUE_EXECUTION)
  102. {
  103. }
  104. }
  105. // Utility Functions
  106. CString StrF(const char * pszFormat, ...)
  107. {
  108. ASSERT( AfxIsValidString( pszFormat ) );
  109. CString str;
  110. va_list argList;
  111. va_start( argList, pszFormat );
  112. str.FormatV( pszFormat, argList );
  113. va_end( argList );
  114. return str;
  115. }
  116. BYTE GetEscapeChar( BYTE ch )
  117. {
  118. switch(ch)
  119. {
  120. case '\'': return '\''; // Single quotation mark (') = 39 or 0x27
  121. case '\"': return '\"'; // Double quotation mark (") = 34 or 0x22
  122. case '?': return '\?'; // Question mark (?) = 63 or 0x3f
  123. case '\\': return '\\'; // Backslash (\) = 92 or 0x5c
  124. case 'a': return '\a'; // Alert (BEL) = 7
  125. case 'b': return '\b'; // Backspace (BS) = 8
  126. case 'f': return '\f'; // Formfeed (FF) = 12 or 0x0c
  127. case 'n': return '\n'; // Newline (NL or LF) = 10 or 0x0a
  128. case 'r': return '\r'; // Carriage Return (CR) = 13 or 0x0d
  129. case 't': return '\t'; // Horizontal tab (HT) = 9
  130. case 'v': return '\v'; // Vertical tab (VT) = 11 or 0x0b
  131. case '0': return '\0'; // Null character (NUL) = 0
  132. }
  133. return 0; // invalid
  134. }
  135. CString RemoveEscapes( const char* str )
  136. {
  137. ASSERT( str );
  138. CString ret;
  139. char* pSrc = (char*) str;
  140. char* pDest = ret.GetBuffer( strlen(pSrc) );
  141. char* pStart = pDest;
  142. while( *pSrc != '\0' )
  143. {
  144. if( *pSrc == '\\' )
  145. {
  146. pSrc++;
  147. *pDest = GetEscapeChar( *pSrc );
  148. }
  149. else
  150. *pDest = *pSrc;
  151. pSrc++;
  152. pDest++;
  153. }
  154. ret.ReleaseBuffer( pDest - pStart );
  155. return ret;
  156. }
  157. CString GetWndText( HWND hWnd )
  158. {
  159. CString text;
  160. if( !IsWindow(hWnd) )
  161. return "! NOT A VALID WINDOW !";
  162. CWnd* pWnd = CWnd::FromHandle(hWnd);
  163. pWnd->GetWindowText(text);
  164. return text;
  165. }
  166. bool IsAppWnd( HWND hWnd )
  167. {
  168. DWORD dwMyPID = ::GetCurrentProcessId();
  169. DWORD dwTestPID;
  170. ::GetWindowThreadProcessId( hWnd, &dwTestPID );
  171. return dwMyPID == dwTestPID;
  172. }
  173. HWND GetFocusWnd(CPoint *pPointCaret)
  174. {
  175. HWND hWndFocus = NULL;
  176. if (pPointCaret)
  177. *pPointCaret = CPoint(-1, -1);
  178. HWND hWndForground = GetForegroundWindow(); // Get the desktop's foreground window
  179. if (hWndForground != NULL)
  180. {
  181. DWORD ProcID;
  182. DWORD ThreadID = GetWindowThreadProcessId(hWndForground, &ProcID);
  183. // Attach other thread's message queue to our own to ensure GetFocus() is working properly
  184. BOOL ARes = AttachThreadInput(ThreadID, GetCurrentThreadId(), TRUE);
  185. if (ARes)
  186. {
  187. // Get the other thread's focussed window
  188. CWnd *pWnd = CWnd::FromHandle(hWndForground);
  189. if (pWnd)
  190. {
  191. CWnd *pWndFocus = pWnd->GetFocus();
  192. if (pWndFocus)
  193. {
  194. hWndFocus = pWndFocus->m_hWnd;
  195. if (pPointCaret)
  196. {
  197. *pPointCaret = pWndFocus->GetCaretPos();
  198. pWndFocus->ClientToScreen(pPointCaret);
  199. }
  200. }
  201. }
  202. // Detach other thread's message queue from our own again
  203. ARes = AttachThreadInput(ThreadID, GetCurrentThreadId(), FALSE);
  204. }
  205. }
  206. return hWndFocus;
  207. }
  208. /*----------------------------------------------------------------------------*\
  209. Global Memory Helper Functions
  210. \*----------------------------------------------------------------------------*/
  211. // make sure the given HGLOBAL is valid.
  212. BOOL IsValid( HGLOBAL hGlobal )
  213. {
  214. void* pvData = ::GlobalLock( hGlobal );
  215. ::GlobalUnlock( hGlobal );
  216. return ( pvData != NULL );
  217. }
  218. // asserts if hDest isn't big enough
  219. void CopyToGlobalHP( HGLOBAL hDest, LPVOID pBuf, ULONG ulBufLen )
  220. {
  221. ASSERT( hDest && pBuf && ulBufLen );
  222. LPVOID pvData = GlobalLock(hDest);
  223. ASSERT( pvData );
  224. ULONG size = GlobalSize(hDest);
  225. ASSERT( size >= ulBufLen ); // assert if hDest isn't big enough
  226. memcpy(pvData, pBuf, ulBufLen);
  227. GlobalUnlock(hDest);
  228. }
  229. void CopyToGlobalHH( HGLOBAL hDest, HGLOBAL hSource, ULONG ulBufLen )
  230. {
  231. ASSERT( hDest && hSource && ulBufLen );
  232. LPVOID pvData = GlobalLock(hSource);
  233. ASSERT( pvData );
  234. ULONG size = GlobalSize(hSource);
  235. ASSERT( size >= ulBufLen ); // assert if hSource isn't big enough
  236. CopyToGlobalHP(hDest, pvData, ulBufLen);
  237. GlobalUnlock(hSource);
  238. }
  239. HGLOBAL NewGlobalP( LPVOID pBuf, UINT nLen )
  240. {
  241. ASSERT( pBuf && nLen );
  242. HGLOBAL hDest = GlobalAlloc( GMEM_MOVEABLE | GMEM_SHARE, nLen );
  243. ASSERT( hDest );
  244. CopyToGlobalHP( hDest, pBuf, nLen );
  245. return hDest;
  246. }
  247. HGLOBAL NewGlobal(UINT nLen)
  248. {
  249. ASSERT(nLen);
  250. HGLOBAL hDest = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, nLen);
  251. return hDest;
  252. }
  253. HGLOBAL NewGlobalH( HGLOBAL hSource, UINT nLen )
  254. {
  255. ASSERT( hSource && nLen );
  256. LPVOID pvData = GlobalLock( hSource );
  257. HGLOBAL hDest = NewGlobalP( pvData, nLen );
  258. GlobalUnlock( hSource );
  259. return hDest;
  260. }
  261. int CompareGlobalHP( HGLOBAL hLeft, LPVOID pBuf, ULONG ulBufLen )
  262. {
  263. ASSERT( hLeft && pBuf && ulBufLen );
  264. LPVOID pvData = GlobalLock( hLeft );
  265. ASSERT( pvData );
  266. ASSERT( ulBufLen <= GlobalSize(hLeft) );
  267. int result = memcmp(pvData, pBuf, ulBufLen);
  268. GlobalUnlock( hLeft );
  269. return result;
  270. }
  271. int CompareGlobalHH( HGLOBAL hLeft, HGLOBAL hRight, ULONG ulBufLen )
  272. {
  273. ASSERT( hLeft && hRight && ulBufLen );
  274. ASSERT( ulBufLen <= GlobalSize(hRight) );
  275. LPVOID pvData = GlobalLock(hRight);
  276. ASSERT( pvData );
  277. int result = CompareGlobalHP( hLeft, pvData, ulBufLen );
  278. GlobalUnlock( hLeft );
  279. return result;
  280. }
  281. long DoOptions(CWnd *pParent)
  282. {
  283. //Don't let it open up more than once
  284. if(theApp.m_bShowingOptions)
  285. return FALSE;
  286. theApp.m_bShowingOptions = true;
  287. COptionsSheet Sheet("Copy Pro Options", pParent);
  288. int nRet = Sheet.DoModal();
  289. theApp.m_bShowingOptions = false;
  290. return nRet;
  291. }
  292. //Do not change these these are stored in the database
  293. CLIPFORMAT GetFormatID(LPCSTR cbName)
  294. {
  295. if(strcmp(cbName, "CF_TEXT") == 0)
  296. return CF_TEXT;
  297. else if(strcmp(cbName, "CF_METAFILEPICT") == 0)
  298. return CF_METAFILEPICT;
  299. else if(strcmp(cbName, "CF_SYLK") == 0)
  300. return CF_SYLK;
  301. else if(strcmp(cbName, "CF_DIF") == 0)
  302. return CF_DIF;
  303. else if(strcmp(cbName, "CF_TIFF") == 0)
  304. return CF_TIFF;
  305. else if(strcmp(cbName, "CF_OEMTEXT") == 0)
  306. return CF_OEMTEXT;
  307. else if(strcmp(cbName, "CF_DIB") == 0)
  308. return CF_DIB;
  309. else if(strcmp(cbName, "CF_PALETTE") == 0)
  310. return CF_PALETTE;
  311. else if(strcmp(cbName, "CF_PENDATA") == 0)
  312. return CF_PENDATA;
  313. else if(strcmp(cbName, "CF_RIFF") == 0)
  314. return CF_RIFF;
  315. else if(strcmp(cbName, "CF_WAVE") == 0)
  316. return CF_WAVE;
  317. else if(strcmp(cbName, "CF_UNICODETEXT") == 0)
  318. return CF_UNICODETEXT;
  319. else if(strcmp(cbName, "CF_ENHMETAFILE") == 0)
  320. return CF_ENHMETAFILE;
  321. else if(strcmp(cbName, "CF_HDROP") == 0)
  322. return CF_HDROP;
  323. else if(strcmp(cbName, "CF_LOCALE") == 0)
  324. return CF_LOCALE;
  325. else if(strcmp(cbName, "CF_OWNERDISPLAY") == 0)
  326. return CF_OWNERDISPLAY;
  327. else if(strcmp(cbName, "CF_DSPTEXT") == 0)
  328. return CF_DSPTEXT;
  329. else if(strcmp(cbName, "CF_DSPBITMAP") == 0)
  330. return CF_DSPBITMAP;
  331. else if(strcmp(cbName, "CF_DSPMETAFILEPICT") == 0)
  332. return CF_DSPMETAFILEPICT;
  333. else if(strcmp(cbName, "CF_DSPENHMETAFILE") == 0)
  334. return CF_DSPENHMETAFILE;
  335. return ::RegisterClipboardFormat(cbName);
  336. }
  337. //Do not change these these are stored in the database
  338. CString GetFormatName(CLIPFORMAT cbType)
  339. {
  340. switch(cbType)
  341. {
  342. case CF_TEXT:
  343. return "CF_TEXT";
  344. case CF_BITMAP:
  345. return "CF_BITMAP";
  346. case CF_METAFILEPICT:
  347. return "CF_METAFILEPICT";
  348. case CF_SYLK:
  349. return "CF_SYLK";
  350. case CF_DIF:
  351. return "CF_DIF";
  352. case CF_TIFF:
  353. return "CF_TIFF";
  354. case CF_OEMTEXT:
  355. return "CF_OEMTEXT";
  356. case CF_DIB:
  357. return "CF_DIB";
  358. case CF_PALETTE:
  359. return "CF_PALETTE";
  360. case CF_PENDATA:
  361. return "CF_PENDATA";
  362. case CF_RIFF:
  363. return "CF_RIFF";
  364. case CF_WAVE:
  365. return "CF_WAVE";
  366. case CF_UNICODETEXT:
  367. return "CF_UNICODETEXT";
  368. case CF_ENHMETAFILE:
  369. return "CF_ENHMETAFILE";
  370. case CF_HDROP:
  371. return "CF_HDROP";
  372. case CF_LOCALE:
  373. return "CF_LOCALE";
  374. case CF_OWNERDISPLAY:
  375. return "CF_OWNERDISPLAY";
  376. case CF_DSPTEXT:
  377. return "CF_DSPTEXT";
  378. case CF_DSPBITMAP:
  379. return "CF_DSPBITMAP";
  380. case CF_DSPMETAFILEPICT:
  381. return "CF_DSPMETAFILEPICT";
  382. case CF_DSPENHMETAFILE:
  383. return "CF_DSPENHMETAFILE";
  384. default:
  385. //Not a default type get the name from the clipboard
  386. if (cbType != 0)
  387. {
  388. TCHAR szFormat[256];
  389. GetClipboardFormatName(cbType, szFormat, 256);
  390. return szFormat;
  391. }
  392. break;
  393. }
  394. return "ERROR";
  395. }
  396. CString GetFilePath(CString csFileName)
  397. {
  398. long lSlash = csFileName.ReverseFind('\\');
  399. if(lSlash > -1)
  400. {
  401. csFileName = csFileName.Left(lSlash + 1);
  402. }
  403. return csFileName;
  404. }
  405. /*------------------------------------------------------------------*\
  406. CGetSetOptions
  407. \*------------------------------------------------------------------*/
  408. long CGetSetOptions::m_nLinesPerRow;
  409. BOOL CGetSetOptions::m_bUseCtrlNumAccel;
  410. BOOL CGetSetOptions::m_bAllowDuplicates;
  411. BOOL CGetSetOptions::m_bUpdateTimeOnPaste;
  412. BOOL CGetSetOptions::m_bSaveMultiPaste;
  413. BOOL CGetSetOptions::m_bShowPersistent;
  414. BOOL CGetSetOptions::m_bHistoryStartTop;
  415. long CGetSetOptions::m_bDescTextSize;
  416. BOOL CGetSetOptions::m_bDescShowLeadingWhiteSpace;
  417. BOOL CGetSetOptions::m_bAllwaysShowDescription;
  418. long CGetSetOptions::m_bDoubleClickingOnCaptionDoes;
  419. BOOL CGetSetOptions::m_bPrompForNewGroupName;
  420. BOOL CGetSetOptions::m_bSendPasteOnFirstTenHotKeys;
  421. CSendClients CGetSetOptions::m_SendClients[MAX_SEND_CLIENTS];
  422. long CGetSetOptions::m_lAutoSendClientCount;
  423. CString CGetSetOptions::m_csIPListToPutOnClipboard;
  424. BOOL CGetSetOptions::m_bLogSendReceiveErrors;
  425. BOOL CGetSetOptions::m_bUseHookDllForFocus;
  426. BOOL CGetSetOptions::m_HideDittoOnHotKeyIfAlreadyShown;
  427. long CGetSetOptions::m_lPort;
  428. BOOL CGetSetOptions::m_bDrawThumbnail;
  429. CString CGetSetOptions::m_csPassword;
  430. BOOL CGetSetOptions::m_bDrawRTF;
  431. BOOL CGetSetOptions::m_bMultiPasteReverse;
  432. CString CGetSetOptions::m_csPlaySoundOnCopy;
  433. CStringArray CGetSetOptions::m_csNetworkPasswordArray;
  434. BOOL CGetSetOptions::m_bSendPasteMessageAfterSelection;
  435. BOOL CGetSetOptions::m_bFindAsYouType;
  436. BOOL CGetSetOptions::m_bEnsureEntireWindowCanBeSeen;
  437. BOOL CGetSetOptions::m_bShowAllClipsInMainList;
  438. long CGetSetOptions::m_lMaxClipSizeInBytes;
  439. long CGetSetOptions::m_lSaveClipDelay;
  440. long CGetSetOptions::m_lProcessDrawClipboardDelay;
  441. BOOL CGetSetOptions::m_bEnableDebugLogging;
  442. BOOL CGetSetOptions::m_bEnsureConnectToClipboard;
  443. CGetSetOptions g_Opt;
  444. CGetSetOptions::CGetSetOptions()
  445. {
  446. m_nLinesPerRow = GetLinesPerRow();
  447. m_bUseCtrlNumAccel = GetUseCtrlNumForFirstTenHotKeys();
  448. m_bAllowDuplicates = GetAllowDuplicates();
  449. m_bUpdateTimeOnPaste = GetUpdateTimeOnPaste();
  450. m_bSaveMultiPaste = GetSaveMultiPaste();
  451. m_bShowPersistent = GetShowPersistent();
  452. m_bHistoryStartTop = GetHistoryStartTop();
  453. m_bDescTextSize = GetDescTextSize();
  454. m_bDescShowLeadingWhiteSpace = GetDescShowLeadingWhiteSpace();
  455. m_bAllwaysShowDescription = GetAllwaysShowDescription();
  456. m_bDoubleClickingOnCaptionDoes = GetDoubleClickingOnCaptionDoes();
  457. m_bPrompForNewGroupName = GetPrompForNewGroupName();
  458. m_bSendPasteOnFirstTenHotKeys = GetSendPasteOnFirstTenHotKeys();
  459. m_csIPListToPutOnClipboard = GetListToPutOnClipboard();
  460. m_bLogSendReceiveErrors = GetLogSendReceiveErrors();
  461. m_bUseHookDllForFocus = GetProfileLong("UseHookDllForFocus", TRUE);
  462. m_HideDittoOnHotKeyIfAlreadyShown = GetHideDittoOnHotKeyIfAlreadyShown();
  463. m_lPort = GetPort();
  464. m_bDrawThumbnail = GetDrawThumbnail();
  465. m_csPassword = GetNetworkPassword();
  466. m_bDrawRTF = GetDrawRTF();
  467. m_bMultiPasteReverse = GetMultiPasteReverse();
  468. m_csPlaySoundOnCopy = GetPlaySoundOnCopy();
  469. m_bSendPasteMessageAfterSelection = GetSendPasteAfterSelection();
  470. m_bFindAsYouType = GetFindAsYouType();
  471. m_bEnsureEntireWindowCanBeSeen = GetEnsureEntireWindowCanBeSeen();
  472. m_bShowAllClipsInMainList = GetShowAllClipsInMainList();
  473. m_lMaxClipSizeInBytes = GetMaxClipSizeInBytes();
  474. m_lSaveClipDelay = GetSaveClipDelay();
  475. m_lProcessDrawClipboardDelay = GetProcessDrawClipboardDelay();
  476. m_bEnableDebugLogging = GetEnableDebugLogging();
  477. m_bEnsureConnectToClipboard = GetEnsureConnectToClipboard();
  478. GetExtraNetworkPassword(true);
  479. #ifdef _DEBUG
  480. m_bUseHookDllForFocus = FALSE;
  481. #endif
  482. for(int i = 0; i < MAX_SEND_CLIENTS; i++)
  483. {
  484. GetSendClients(i);
  485. }
  486. GetClientSendCount();
  487. }
  488. CGetSetOptions::~CGetSetOptions()
  489. {
  490. }
  491. long CGetSetOptions::GetProfileLong(CString csName, long bDefaultValue)
  492. {
  493. HKEY hkKey;
  494. long lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T(REG_PATH),
  495. NULL, KEY_READ, &hkKey);
  496. if(lResult != ERROR_SUCCESS)
  497. return bDefaultValue;
  498. DWORD buffer;
  499. DWORD len = sizeof(buffer);
  500. DWORD type;
  501. lResult = ::RegQueryValueEx(hkKey, csName, 0, &type, (LPBYTE)&buffer, &len);
  502. RegCloseKey(hkKey);
  503. if(lResult == ERROR_SUCCESS)
  504. return (long)buffer;
  505. return bDefaultValue;
  506. }
  507. CString CGetSetOptions::GetProfileString(CString csName, CString csDefault)
  508. {
  509. HKEY hkKey;
  510. long lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T(REG_PATH),
  511. NULL, KEY_READ, &hkKey);
  512. char szString[256];
  513. DWORD dwBufLen = 256;
  514. lResult = ::RegQueryValueEx(hkKey , csName, NULL, NULL, (LPBYTE)szString, &dwBufLen);
  515. if(lResult != ERROR_SUCCESS)
  516. return csDefault;
  517. return CString(szString);
  518. }
  519. BOOL CGetSetOptions::SetProfileLong(CString csName, long lValue)
  520. {
  521. HKEY hkKey;
  522. DWORD dWord;
  523. long lResult = RegCreateKeyEx(HKEY_CURRENT_USER, _T(REG_PATH), NULL,
  524. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  525. NULL, &hkKey, &dWord);
  526. if(lResult != ERROR_SUCCESS)
  527. return FALSE;
  528. DWORD val = (DWORD)lValue;
  529. lResult = ::RegSetValueEx(hkKey, csName, 0, REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
  530. RegCloseKey(hkKey);
  531. return lResult == ERROR_SUCCESS;
  532. }
  533. BOOL CGetSetOptions::SetProfileString(CString csName, CString csValue)
  534. {
  535. HKEY hkKey;
  536. DWORD dWord;
  537. long lResult = RegCreateKeyEx(HKEY_CURRENT_USER, _T(REG_PATH), NULL,
  538. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  539. NULL, &hkKey, &dWord);
  540. if(lResult != ERROR_SUCCESS)
  541. return FALSE;
  542. ::RegSetValueEx(hkKey, csName, NULL, REG_SZ,
  543. (BYTE*)(LPCTSTR)csValue, csValue.GetLength()+sizeof(TCHAR));
  544. RegCloseKey(hkKey);
  545. return lResult == ERROR_SUCCESS;
  546. }
  547. BOOL CGetSetOptions::SetProfileData(CString csName, LPVOID lpData, DWORD dwLength)
  548. {
  549. HKEY hkKey;
  550. DWORD dWord;
  551. long lResult = RegCreateKeyEx(HKEY_CURRENT_USER, _T(REG_PATH), NULL,
  552. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  553. NULL, &hkKey, &dWord);
  554. if(lResult != ERROR_SUCCESS)
  555. return FALSE;
  556. ::RegSetValueEx(hkKey, csName, NULL, REG_BINARY,
  557. (BYTE*)lpData, dwLength);
  558. RegCloseKey(hkKey);
  559. return lResult == ERROR_SUCCESS;
  560. }
  561. LPVOID CGetSetOptions::GetProfileData(CString csName, DWORD &dwLength)
  562. {
  563. HKEY hkKey;
  564. long lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T(REG_PATH),
  565. NULL, KEY_READ, &hkKey);
  566. lResult = ::RegQueryValueEx(hkKey , csName, NULL, NULL, NULL, &dwLength);
  567. if(lResult != ERROR_SUCCESS)
  568. return NULL;
  569. LPVOID lpVoid = new BYTE[dwLength];
  570. lResult = ::RegQueryValueEx(hkKey , csName, NULL, NULL, (LPBYTE)lpVoid, &dwLength);
  571. if(lResult != ERROR_SUCCESS)
  572. return NULL;
  573. return lpVoid;
  574. }
  575. BOOL CGetSetOptions::GetShowIconInSysTray()
  576. {
  577. return GetProfileLong("ShowIconInSystemTray", TRUE);
  578. }
  579. BOOL CGetSetOptions::SetShowIconInSysTray(BOOL bShow)
  580. {
  581. return SetProfileLong("ShowIconInSystemTray", bShow);
  582. }
  583. BOOL CGetSetOptions::SetEnableTransparency(BOOL bCheck)
  584. {
  585. return SetProfileLong("EnableTransparency", bCheck);
  586. }
  587. BOOL CGetSetOptions::GetEnableTransparency()
  588. {
  589. return GetProfileLong("EnableTransparency", FALSE);
  590. }
  591. BOOL CGetSetOptions::SetTransparencyPercent(long lPercent)
  592. {
  593. #ifdef AFTER_98
  594. if(lPercent > OPACITY_MAX)
  595. lPercent = OPACITY_MAX;
  596. if(lPercent < 0)
  597. lPercent = 0;
  598. return SetProfileLong("TransparencyPercent", lPercent);
  599. #endif
  600. return FALSE;
  601. }
  602. long CGetSetOptions::GetTransparencyPercent()
  603. {
  604. #ifdef AFTER_98
  605. long lValue = GetProfileLong("TransparencyPercent", 14);
  606. if(lValue > OPACITY_MAX) lValue = OPACITY_MAX;
  607. if(lValue < 0) lValue = 0;
  608. return lValue;
  609. #endif
  610. return 0;
  611. }
  612. BOOL CGetSetOptions::SetLinesPerRow(long lLines)
  613. {
  614. m_nLinesPerRow = lLines;
  615. return SetProfileLong("LinesPerRow", lLines);
  616. }
  617. long CGetSetOptions::GetLinesPerRow()
  618. {
  619. return GetProfileLong("LinesPerRow", 2);
  620. }
  621. BOOL CGetSetOptions::GetRunOnStartUp()
  622. {
  623. HKEY hkRun;
  624. LONG nResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  625. _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
  626. NULL, KEY_READ, &hkRun);
  627. if(nResult != ERROR_SUCCESS)
  628. return FALSE;
  629. nResult = RegQueryValueEx(hkRun, GetAppName(), NULL, NULL, NULL, NULL);
  630. RegCloseKey(hkRun);
  631. return nResult == ERROR_SUCCESS;
  632. }
  633. void CGetSetOptions::SetRunOnStartUp(BOOL bRun)
  634. {
  635. if(bRun == GetRunOnStartUp())
  636. return;
  637. HKEY hkRun;
  638. LONG nResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  639. _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
  640. NULL, KEY_ALL_ACCESS, &hkRun);
  641. if(nResult != ERROR_SUCCESS)
  642. return;
  643. if(bRun)
  644. {
  645. CString sExeName = GetExeFileName();
  646. ::RegSetValueEx(hkRun, GetAppName(), NULL, REG_SZ,
  647. (BYTE*)(LPCTSTR)sExeName, sExeName.GetLength()+sizeof(TCHAR));
  648. }
  649. else
  650. {
  651. ::RegDeleteValue(hkRun, GetAppName());
  652. }
  653. ::RegCloseKey(hkRun);
  654. }
  655. CString CGetSetOptions::GetExeFileName()
  656. {
  657. CString sExeName;
  658. GetModuleFileName(NULL, sExeName.GetBuffer(_MAX_PATH),_MAX_PATH);
  659. sExeName.ReleaseBuffer();
  660. return sExeName;
  661. }
  662. CString CGetSetOptions::GetAppName()
  663. {
  664. return "Ditto";
  665. }
  666. BOOL CGetSetOptions::SetQuickPastePosition(long lPosition)
  667. {
  668. return SetProfileLong("ShowQuickPastePosition", lPosition);
  669. }
  670. long CGetSetOptions::GetQuickPastePosition()
  671. {
  672. return GetProfileLong("ShowQuickPastePosition", POS_AT_PREVIOUS);
  673. }
  674. BOOL CGetSetOptions::SetQuickPasteSize(CSize size)
  675. {
  676. BOOL bRet = SetProfileLong("QuickPasteCX", size.cx);
  677. bRet = SetProfileLong("QuickPasteCY", size.cy);
  678. return bRet;
  679. }
  680. void CGetSetOptions::GetQuickPasteSize(CSize &size)
  681. {
  682. size.cx = GetProfileLong("QuickPasteCX", 300);
  683. size.cy = GetProfileLong("QuickPasteCY", 300);
  684. }
  685. BOOL CGetSetOptions::SetQuickPastePoint(CPoint point)
  686. {
  687. BOOL bRet = SetProfileLong("QuickPasteX", point.x);
  688. bRet = SetProfileLong("QuickPasteY", point.y);
  689. return bRet;
  690. }
  691. void CGetSetOptions::GetQuickPastePoint(CPoint &point)
  692. {
  693. point.x = GetProfileLong("QuickPasteX", 300);
  694. point.y = GetProfileLong("QuickPasteY", 300);
  695. }
  696. long CGetSetOptions::GetCopyGap()
  697. {
  698. return GetProfileLong("CopyGap", 150);
  699. }
  700. BOOL CGetSetOptions::SetDBPath(CString csPath)
  701. {
  702. return SetProfileString("DBPath", csPath);
  703. }
  704. CString CGetSetOptions::GetDBPath(BOOL bDefault/* = TRUE*/)
  705. {
  706. //First check the reg string
  707. CString csDefaultPath = GetProfileString("DBPath", "");
  708. //If there is nothing in the regesty then get the default
  709. //In the users application data in my documents
  710. if(bDefault)
  711. {
  712. if(csDefaultPath.IsEmpty())
  713. csDefaultPath = GetDefaultDBName();
  714. }
  715. return csDefaultPath;
  716. }
  717. void CGetSetOptions::SetCheckForMaxEntries(BOOL bVal)
  718. {
  719. SetProfileLong("CheckForMaxEntries", bVal);
  720. }
  721. BOOL CGetSetOptions::GetCheckForMaxEntries()
  722. {
  723. return GetProfileLong("CheckForMaxEntries", 0);
  724. }
  725. void CGetSetOptions::SetCheckForExpiredEntries(BOOL bVal)
  726. {
  727. SetProfileLong("CheckForExpiredEntries", bVal);
  728. }
  729. BOOL CGetSetOptions::GetCheckForExpiredEntries()
  730. {
  731. return GetProfileLong("CheckForExpiredEntries", 0);
  732. }
  733. void CGetSetOptions::SetMaxEntries(long lVal)
  734. {
  735. SetProfileLong("MaxEntries", lVal);
  736. }
  737. long CGetSetOptions::GetMaxEntries()
  738. {
  739. return GetProfileLong("MaxEntries", 500);
  740. }
  741. void CGetSetOptions::SetExpiredEntries(long lVal)
  742. {
  743. SetProfileLong("ExpiredEntries", lVal);
  744. }
  745. long CGetSetOptions::GetExpiredEntries()
  746. {
  747. return GetProfileLong("ExpiredEntries", 5);
  748. }
  749. void CGetSetOptions::SetTripCopyCount(long lVal)
  750. {
  751. // negative means a relative offset
  752. if(lVal < 0)
  753. lVal = GetTripCopyCount() - lVal; // add the absolute value
  754. if(GetTripDate() == 0)
  755. SetTripDate(-1);
  756. SetProfileLong("TripCopies", lVal);
  757. }
  758. long CGetSetOptions::GetTripCopyCount()
  759. {
  760. return GetProfileLong("TripCopies", 0);
  761. }
  762. void CGetSetOptions::SetTripPasteCount(long lVal)
  763. {
  764. // negative means a relative offset
  765. if(lVal < 0)
  766. lVal = GetTripPasteCount() - lVal; // add the absolute value
  767. if(GetTripDate() == 0)
  768. SetTripDate(-1);
  769. SetProfileLong("TripPastes", lVal);
  770. }
  771. long CGetSetOptions::GetTripPasteCount()
  772. {
  773. return GetProfileLong("TripPastes", 0);
  774. }
  775. void CGetSetOptions::SetTripDate(long lDate)
  776. {
  777. if(lDate == -1)
  778. lDate = (long)CTime::GetCurrentTime().GetTime();
  779. SetProfileLong("TripDate", lDate);
  780. }
  781. long CGetSetOptions::GetTripDate()
  782. {
  783. return GetProfileLong("TripDate", 0);
  784. }
  785. void CGetSetOptions::SetTotalCopyCount(long lVal)
  786. {
  787. // negative means a relative offset
  788. if(lVal < 0)
  789. lVal = GetTotalCopyCount() - lVal; // add the absolute value
  790. if(GetTotalDate() == 0)
  791. SetTotalDate(-1);
  792. SetProfileLong("TotalCopies", lVal);
  793. }
  794. long CGetSetOptions::GetTotalCopyCount()
  795. {
  796. return GetProfileLong("TotalCopies", 0);
  797. }
  798. void CGetSetOptions::SetTotalPasteCount(long lVal)
  799. {
  800. // negative means a relative offset
  801. if(lVal < 0)
  802. lVal = GetTotalPasteCount() - lVal; // add the absolute value
  803. if(GetTotalDate() == 0)
  804. SetTotalDate(-1);
  805. SetProfileLong("TotalPastes", lVal);
  806. }
  807. long CGetSetOptions::GetTotalPasteCount()
  808. {
  809. return GetProfileLong("TotalPastes", 0);
  810. }
  811. void CGetSetOptions::SetTotalDate(long lDate)
  812. {
  813. if(lDate == -1)
  814. lDate = (long)CTime::GetCurrentTime().GetTime();
  815. SetProfileLong("TotalDate", lDate);
  816. }
  817. long CGetSetOptions::GetTotalDate()
  818. {
  819. return GetProfileLong("TotalDate", 0);
  820. }
  821. // the implementations for the following functions were moved out-of-line.
  822. // when they were declared inline, the compiler failed to notice when
  823. // these functions were changed (the linker used an old compiled version)
  824. // (maybe because they are also static?)
  825. CString CGetSetOptions::GetUpdateFilePath() { return GetProfileString("UpdateFilePath", ""); }
  826. BOOL CGetSetOptions::SetUpdateFilePath(CString cs) { return SetProfileString("UpdateFilePath", cs); }
  827. CString CGetSetOptions::GetUpdateInstallPath() { return GetProfileString("UpdateInstallPath", ""); }
  828. BOOL CGetSetOptions::SetUpdateInstallPath(CString cs) { return SetProfileString("UpdateInstallPath", cs); }
  829. long CGetSetOptions::GetLastUpdate() { return GetProfileLong("LastUpdateDay", 0); }
  830. long CGetSetOptions::SetLastUpdate(long lValue) { return SetProfileLong("LastUpdateDay", lValue); }
  831. BOOL CGetSetOptions::GetCheckForUpdates() { return GetProfileLong("CheckForUpdates", TRUE); }
  832. BOOL CGetSetOptions::SetCheckForUpdates(BOOL bCheck) { return SetProfileLong("CheckForUpdates", bCheck); }
  833. void CGetSetOptions::SetUseCtrlNumForFirstTenHotKeys(BOOL bVal) { SetProfileLong("UseCtrlNumForFirstTenHotKeys", bVal); m_bUseCtrlNumAccel = bVal; }
  834. BOOL CGetSetOptions::GetUseCtrlNumForFirstTenHotKeys() { return GetProfileLong("UseCtrlNumForFirstTenHotKeys", 0); }
  835. void CGetSetOptions::SetAllowDuplicates(BOOL bVal) { SetProfileLong("AllowDuplicates", bVal); m_bAllowDuplicates = bVal; }
  836. BOOL CGetSetOptions::GetAllowDuplicates() { return GetProfileLong("AllowDuplicates", 0); }
  837. void CGetSetOptions::SetUpdateTimeOnPaste(BOOL bVal) { SetProfileLong("UpdateTimeOnPaste", bVal); m_bUpdateTimeOnPaste = bVal; }
  838. BOOL CGetSetOptions::GetUpdateTimeOnPaste() { return GetProfileLong("UpdateTimeOnPaste", TRUE); }
  839. void CGetSetOptions::SetSaveMultiPaste(BOOL bVal) { SetProfileLong("SaveMultiPaste", bVal); m_bSaveMultiPaste = bVal; }
  840. BOOL CGetSetOptions::GetSaveMultiPaste() { return GetProfileLong("SaveMultiPaste", 0); }
  841. void CGetSetOptions::SetShowPersistent(BOOL bVal) { SetProfileLong("ShowPersistent", bVal); m_bShowPersistent = bVal; }
  842. BOOL CGetSetOptions::GetShowPersistent() { return GetProfileLong("ShowPersistent", 0); }
  843. void CGetSetOptions::SetHistoryStartTop(BOOL bVal) { SetProfileLong("HistoryStartTop", bVal); m_bHistoryStartTop = bVal; }
  844. BOOL CGetSetOptions::GetHistoryStartTop() { return GetProfileLong("HistoryStartTop", TRUE); }
  845. void CGetSetOptions::SetShowTextForFirstTenHotKeys(BOOL bVal) { SetProfileLong("ShowTextForFirstTenHotKeys", bVal); }
  846. BOOL CGetSetOptions::GetShowTextForFirstTenHotKeys() { return GetProfileLong("ShowTextForFirstTenHotKeys", TRUE); }
  847. void CGetSetOptions::SetMainHWND(long lhWnd) { SetProfileLong("MainhWnd", lhWnd); }
  848. BOOL CGetSetOptions::GetMainHWND() { return GetProfileLong("MainhWnd", 0); }
  849. void CGetSetOptions::SetCaptionPos(long lPos) { SetProfileLong("CaptionPos", lPos); }
  850. long CGetSetOptions::GetCaptionPos() { return GetProfileLong("CaptionPos", CAPTION_RIGHT); }
  851. void CGetSetOptions::SetAutoHide(BOOL bAutoHide){ SetProfileLong("AutoHide", bAutoHide); }
  852. BOOL CGetSetOptions::GetAutoHide() { return GetProfileLong("AutoHide", FALSE); }
  853. void CGetSetOptions::SetDescTextSize(long lSize){ SetProfileLong("DescTextSize", lSize); m_bDescTextSize = lSize; }
  854. long CGetSetOptions::GetDescTextSize() { return GetProfileLong("DescTextSize", 500); }
  855. void CGetSetOptions::SetDescShowLeadingWhiteSpace(BOOL bVal){ SetProfileLong("DescShowLeadingWhiteSpace", bVal); m_bDescShowLeadingWhiteSpace = bVal; }
  856. BOOL CGetSetOptions::GetDescShowLeadingWhiteSpace() { return GetProfileLong("DescShowLeadingWhiteSpace", FALSE); }
  857. void CGetSetOptions::SetAllwaysShowDescription(long bShow) { SetProfileLong("AllwaysShowDescription", bShow); m_bAllwaysShowDescription = bShow; }
  858. BOOL CGetSetOptions::GetAllwaysShowDescription() { return GetProfileLong("AllwaysShowDescription", FALSE); }
  859. void CGetSetOptions::SetDoubleClickingOnCaptionDoes(long lOption) { SetProfileLong("DoubleClickingOnCaptionDoes", lOption); m_bDoubleClickingOnCaptionDoes = lOption; }
  860. long CGetSetOptions::GetDoubleClickingOnCaptionDoes() { return GetProfileLong("DoubleClickingOnCaptionDoes", TOGGLES_ALLWAYS_ON_TOP); }
  861. void CGetSetOptions::SetPrompForNewGroupName(BOOL bOption) { SetProfileLong("PrompForNewGroupName", bOption); m_bPrompForNewGroupName = bOption; }
  862. BOOL CGetSetOptions::GetPrompForNewGroupName() { return GetProfileLong("PrompForNewGroupName", TRUE); }
  863. void CGetSetOptions::SetSendPasteOnFirstTenHotKeys(BOOL bOption) { SetProfileLong("SendPasteOnFirstTenHotKeys", bOption); m_bSendPasteOnFirstTenHotKeys = bOption; }
  864. BOOL CGetSetOptions::GetSendPasteOnFirstTenHotKeys() { return GetProfileLong("SendPasteOnFirstTenHotKeys", TRUE); }
  865. void CGetSetOptions::SetSendClients(CSendClients Client, int nPos)
  866. {
  867. CString cs;
  868. cs.Format("sendclient_ip_%d", nPos);
  869. SetProfileString(cs, Client.csIP);
  870. cs.Format("sendclient_autosend_%d", nPos);
  871. SetProfileLong(cs, Client.bSendAll);
  872. cs.Format("sendclient_description_%d", nPos);
  873. SetProfileString(cs, Client.csDescription);
  874. //Save this setting so it's not reset
  875. Client.bShownFirstError = m_SendClients[nPos].bShownFirstError;
  876. m_SendClients[nPos] = Client;
  877. }
  878. CSendClients CGetSetOptions::GetSendClients(int nPos)
  879. {
  880. CSendClients Client;
  881. CString cs;
  882. cs.Format("sendclient_ip_%d", nPos);
  883. Client.csIP = GetProfileString(cs, "");
  884. cs.Format("sendclient_autosend_%d", nPos);
  885. Client.bSendAll = GetProfileLong(cs, FALSE);
  886. cs.Format("sendclient_description_%d", nPos);
  887. Client.csDescription = GetProfileString(cs, "");
  888. m_SendClients[nPos] = Client;
  889. return Client;
  890. }
  891. void CGetSetOptions::GetClientSendCount()
  892. {
  893. m_lAutoSendClientCount = 0;
  894. for(int i = 0; i < MAX_SEND_CLIENTS; i++)
  895. {
  896. if(m_SendClients[i].csIP.GetLength() > 0)
  897. {
  898. if(m_SendClients[i].bSendAll)
  899. m_lAutoSendClientCount++;
  900. }
  901. }
  902. }
  903. CString CGetSetOptions::GetListToPutOnClipboard()
  904. {
  905. CString cs = GetProfileString("ListToPutOnClipboard", "");
  906. cs.MakeUpper();
  907. return cs;
  908. }
  909. BOOL CGetSetOptions::SetListToPutOnClipboard(CString cs)
  910. {
  911. cs.MakeUpper();
  912. m_csIPListToPutOnClipboard = cs;
  913. return SetProfileString("ListToPutOnClipboard", cs);
  914. }
  915. void CGetSetOptions::SetLogSendReceiveErrors(BOOL bOption)
  916. {
  917. m_bLogSendReceiveErrors = bOption;
  918. SetProfileLong("LogSendReceiveErrors", bOption);
  919. }
  920. BOOL CGetSetOptions::GetLogSendReceiveErrors()
  921. {
  922. return GetProfileLong("LogSendReceiveErrors", FALSE);
  923. }
  924. BOOL CGetSetOptions::GetHideDittoOnHotKeyIfAlreadyShown()
  925. {
  926. return GetProfileLong("HideDittoOnHotKeyIfAlreadyShown", TRUE);
  927. }
  928. void CGetSetOptions::SetHideDittoOnHotKeyIfAlreadyShown(BOOL bVal)
  929. {
  930. m_HideDittoOnHotKeyIfAlreadyShown = bVal;
  931. SetProfileLong("HideDittoOnHotKeyIfAlreadyShown", bVal);
  932. }
  933. void CGetSetOptions::SetPort(long lPort)
  934. {
  935. m_lPort = lPort;
  936. SetProfileLong("SendRecvPort", lPort);
  937. }
  938. long CGetSetOptions::GetPort()
  939. {
  940. return GetProfileLong("SendRecvPort", 23443);
  941. }
  942. BOOL CGetSetOptions::GetDisableRecieve()
  943. {
  944. return GetProfileLong("DisableRecieve", FALSE);
  945. }
  946. void CGetSetOptions::SetDisableRecieve(BOOL bVal)
  947. {
  948. SetProfileLong("DisableRecieve", bVal);
  949. }
  950. BOOL CGetSetOptions::GetFont(LOGFONT &font)
  951. {
  952. DWORD dwLength;
  953. LPVOID lpVoid = GetProfileData("DisplayFont", dwLength);
  954. if(lpVoid)
  955. {
  956. memcpy(&font, lpVoid, dwLength);
  957. return TRUE;
  958. }
  959. return FALSE;
  960. }
  961. void CGetSetOptions::SetFont(LOGFONT &font)
  962. {
  963. SetProfileData("DisplayFont", &font, sizeof(LOGFONT));
  964. }
  965. void CGetSetOptions::SetDrawThumbnail(long bDraw)
  966. {
  967. SetProfileLong("DrawThumbnail", bDraw);
  968. m_bDrawThumbnail = bDraw;
  969. }
  970. BOOL CGetSetOptions::GetDrawThumbnail()
  971. {
  972. return GetProfileLong("DrawThumbnail", TRUE);
  973. }
  974. void CGetSetOptions::SetExtraNetworkPassword(CString csPassword)
  975. {
  976. SetProfileString("NetworkExtraPassword", csPassword);
  977. }
  978. CString CGetSetOptions::GetExtraNetworkPassword(bool bFillArray)
  979. {
  980. CString cs = GetProfileString("NetworkExtraPassword", "");
  981. if(bFillArray)
  982. {
  983. m_csNetworkPasswordArray.RemoveAll();
  984. char seps[] = ",";
  985. char *token;
  986. char *pString = cs.GetBuffer(cs.GetLength());
  987. /* Establish string and get the first token: */
  988. token = strtok(pString, seps);
  989. while(token != NULL)
  990. {
  991. CString cs(token);
  992. cs.TrimLeft();
  993. cs.TrimRight();
  994. m_csNetworkPasswordArray.Add(cs);
  995. // Get next token
  996. token = strtok( NULL, seps );
  997. }
  998. cs.ReleaseBuffer();
  999. }
  1000. return cs;
  1001. }
  1002. void CGetSetOptions::SetNetworkPassword(CString csPassword)
  1003. {
  1004. m_csPassword = csPassword;
  1005. SetProfileString("NetworkStringPassword", csPassword);
  1006. // UCHAR *pData = NULL;
  1007. // int nLength = 0;
  1008. //
  1009. // if(EncryptString(csPassword, pData, nLength))
  1010. // {
  1011. // SetProfileData("NetworkPassword", pData, nLength);
  1012. // }
  1013. // else
  1014. // {
  1015. // SetProfileData("NetworkPassword", NULL, 0);
  1016. // }
  1017. //
  1018. // DELETE_PTR(pData);
  1019. }
  1020. CString CGetSetOptions::GetNetworkPassword()
  1021. {
  1022. return GetProfileString("NetworkStringPassword", "LetMeIn");
  1023. // CString cs = "";
  1024. // DWORD dwLength = 0;
  1025. // LPVOID lpVoid = GetProfileData("NetworkPassword", dwLength);
  1026. // if(lpVoid)
  1027. // {
  1028. // UCHAR *pData = NULL;
  1029. // int nLength = 0;
  1030. //
  1031. // if(DecryptString((UCHAR *)lpVoid, dwLength, pData, nLength))
  1032. // cs = pData;
  1033. //
  1034. // DELETE_PTR(pData);
  1035. // DELETE_PTR(lpVoid);
  1036. // }
  1037. //
  1038. // if(cs == "")
  1039. // cs = "LetMeIn";
  1040. }
  1041. void CGetSetOptions::SetDrawRTF(long bDraw)
  1042. {
  1043. SetProfileLong("DrawRTF", bDraw);
  1044. m_bDrawRTF = bDraw;
  1045. }
  1046. BOOL CGetSetOptions::GetDrawRTF()
  1047. {
  1048. return GetProfileLong("DrawRTF", FALSE);
  1049. }
  1050. void CGetSetOptions::SetMultiPasteReverse(bool bVal)
  1051. {
  1052. SetProfileLong("MultiPasteReverse", bVal);
  1053. m_bMultiPasteReverse = bVal;
  1054. }
  1055. BOOL CGetSetOptions::GetMultiPasteReverse()
  1056. {
  1057. return GetProfileLong("MultiPasteReverse", TRUE);
  1058. }
  1059. void CGetSetOptions::SetPlaySoundOnCopy(CString cs)
  1060. {
  1061. m_csPlaySoundOnCopy = cs;
  1062. SetProfileString("PlaySoundOnCopy", cs);
  1063. }
  1064. CString CGetSetOptions::GetPlaySoundOnCopy()
  1065. {
  1066. return GetProfileString("PlaySoundOnCopy", "");
  1067. }
  1068. void CGetSetOptions::SetSendPasteAfterSelection(BOOL bVal)
  1069. {
  1070. m_bSendPasteMessageAfterSelection = bVal;
  1071. SetProfileLong("SendPasteMessageAfterSelection", bVal);
  1072. }
  1073. BOOL CGetSetOptions::GetSendPasteAfterSelection()
  1074. {
  1075. return GetProfileLong("SendPasteMessageAfterSelection", TRUE);
  1076. }
  1077. void CGetSetOptions::SetFindAsYouType(BOOL bVal)
  1078. {
  1079. m_bFindAsYouType = bVal;
  1080. SetProfileLong("FindAsYouType", bVal);
  1081. }
  1082. BOOL CGetSetOptions::GetFindAsYouType()
  1083. {
  1084. return GetProfileLong("FindAsYouType", TRUE);
  1085. }
  1086. void CGetSetOptions::SetEnsureEntireWindowCanBeSeen(BOOL bVal)
  1087. {
  1088. m_bEnsureEntireWindowCanBeSeen = bVal;
  1089. SetProfileLong("EnsureEntireWindowCanBeSeen", bVal);
  1090. }
  1091. BOOL CGetSetOptions::GetEnsureEntireWindowCanBeSeen()
  1092. {
  1093. return GetProfileLong("EnsureEntireWindowCanBeSeen", TRUE);
  1094. }
  1095. void CGetSetOptions::SetShowAllClipsInMainList(BOOL bVal)
  1096. {
  1097. m_bShowAllClipsInMainList = bVal;
  1098. SetProfileLong("ShowAllClipsInMainList", bVal);
  1099. }
  1100. BOOL CGetSetOptions::GetShowAllClipsInMainList()
  1101. {
  1102. return GetProfileLong("ShowAllClipsInMainList", TRUE);
  1103. }
  1104. long CGetSetOptions::GetMaxClipSizeInBytes()
  1105. {
  1106. return GetProfileLong("MaxClipSizeInBytes", 0);
  1107. }
  1108. void CGetSetOptions::SetMaxClipSizeInBytes(long lSize)
  1109. {
  1110. m_lMaxClipSizeInBytes = lSize;
  1111. SetProfileLong("MaxClipSizeInBytes", lSize);
  1112. }
  1113. CString CGetSetOptions::GetLanguageFile()
  1114. {
  1115. return GetProfileString("LanguageFile", "");
  1116. }
  1117. void CGetSetOptions::SetLanguageFile(CString csLanguage)
  1118. {
  1119. SetProfileString("LanguageFile", csLanguage);
  1120. }
  1121. long CGetSetOptions::GetSaveClipDelay()
  1122. {
  1123. return GetProfileLong("SaveClipDelay", 500);
  1124. }
  1125. void CGetSetOptions::SetSaveClipDelay(long lDelay)
  1126. {
  1127. m_lSaveClipDelay = lDelay;
  1128. SetProfileLong("SaveClipDelay", lDelay);
  1129. }
  1130. long CGetSetOptions::GetProcessDrawClipboardDelay()
  1131. {
  1132. return GetProfileLong("ProcessDrawClipboardDelay", 100);
  1133. }
  1134. void CGetSetOptions::SetProcessDrawClipboardDelay(long lDelay)
  1135. {
  1136. m_lProcessDrawClipboardDelay = lDelay;
  1137. SetProfileLong("ProcessDrawClipboardDelay", lDelay);
  1138. }
  1139. BOOL CGetSetOptions::GetEnableDebugLogging()
  1140. {
  1141. return GetProfileLong("EnableDebugLogging", FALSE);
  1142. }
  1143. void CGetSetOptions::SetEnableDebugLogging(BOOL bEnable)
  1144. {
  1145. m_bEnableDebugLogging = bEnable;
  1146. SetProfileLong("EnableDebugLogging", bEnable);
  1147. }
  1148. BOOL CGetSetOptions::GetEnsureConnectToClipboard()
  1149. {
  1150. return GetProfileLong("EnsureConnected", FALSE);
  1151. }
  1152. void CGetSetOptions::SetEnsureConnectToClipboard(BOOL bSet)
  1153. {
  1154. m_bEnsureConnectToClipboard = bSet;
  1155. SetProfileLong("EnsureConnected", bSet);
  1156. }
  1157. /*------------------------------------------------------------------*\
  1158. CHotKey - a single system-wide hotkey
  1159. \*------------------------------------------------------------------*/
  1160. CHotKey::CHotKey( CString name, DWORD defKey, bool bUnregOnShowDitto )
  1161. : m_Name(name), m_bIsRegistered(false), m_bUnRegisterOnShowDitto(bUnregOnShowDitto)
  1162. {
  1163. m_Atom = ::GlobalAddAtom( m_Name );
  1164. ASSERT( m_Atom );
  1165. m_Key = (DWORD) g_Opt.GetProfileLong( m_Name, (long) defKey );
  1166. g_HotKeys.Add( this );
  1167. }
  1168. CHotKey::~CHotKey()
  1169. {
  1170. Unregister();
  1171. }
  1172. void CHotKey::SetKey( DWORD key, bool bSave )
  1173. {
  1174. if( m_Key == key )
  1175. return;
  1176. if( m_bIsRegistered )
  1177. Unregister();
  1178. m_Key = key;
  1179. if( bSave )
  1180. SaveKey();
  1181. }
  1182. void CHotKey::LoadKey()
  1183. {
  1184. SetKey( (DWORD) g_Opt.GetProfileLong( m_Name, 0 ) );
  1185. }
  1186. bool CHotKey::SaveKey()
  1187. {
  1188. return g_Opt.SetProfileLong( m_Name, (long) m_Key ) != FALSE;
  1189. }
  1190. // CString GetKeyAsText();
  1191. // void SetKeyFromText( CString text );
  1192. BOOL CHotKey::ValidateHotKey(DWORD dwHotKey)
  1193. {
  1194. ATOM id = ::GlobalAddAtom("HK_VALIDATE");
  1195. BOOL bResult = ::RegisterHotKey( g_HotKeys.m_hWnd,
  1196. id,
  1197. GetModifier(dwHotKey),
  1198. LOBYTE(dwHotKey) );
  1199. if(bResult)
  1200. ::UnregisterHotKey(g_HotKeys.m_hWnd, id);
  1201. ::GlobalDeleteAtom(id);
  1202. return bResult;
  1203. }
  1204. void CHotKey::CopyFromCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID)
  1205. {
  1206. long lHotKey = ctrl.GetHotKey();
  1207. short sKeyKode = LOBYTE(lHotKey);
  1208. short sModifers = HIBYTE(lHotKey);
  1209. if(lHotKey && ::IsDlgButtonChecked(hParent, nWindowsCBID))
  1210. {
  1211. sModifers |= HOTKEYF_EXT;
  1212. }
  1213. SetKey(MAKEWORD(sKeyKode, sModifers));
  1214. }
  1215. void CHotKey::CopyToCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID)
  1216. {
  1217. long lModifiers = HIBYTE(m_Key);
  1218. ctrl.SetHotKey(LOBYTE(m_Key), lModifiers);
  1219. if(lModifiers & HOTKEYF_EXT)
  1220. {
  1221. ::CheckDlgButton(hParent, nWindowsCBID, BST_CHECKED);
  1222. }
  1223. }
  1224. UINT CHotKey::GetModifier(DWORD dwHotKey)
  1225. {
  1226. UINT uMod = 0;
  1227. if( HIBYTE(dwHotKey) & HOTKEYF_SHIFT ) uMod |= MOD_SHIFT;
  1228. if( HIBYTE(dwHotKey) & HOTKEYF_CONTROL ) uMod |= MOD_CONTROL;
  1229. if( HIBYTE(dwHotKey) & HOTKEYF_ALT ) uMod |= MOD_ALT;
  1230. if( HIBYTE(dwHotKey) & HOTKEYF_EXT ) uMod |= MOD_WIN;
  1231. return uMod;
  1232. }
  1233. bool CHotKey::Register()
  1234. {
  1235. if(m_Key)
  1236. {
  1237. if(m_bIsRegistered == false)
  1238. {
  1239. ASSERT(g_HotKeys.m_hWnd);
  1240. m_bIsRegistered = ::RegisterHotKey(g_HotKeys.m_hWnd,
  1241. m_Atom,
  1242. GetModifier(),
  1243. LOBYTE(m_Key) ) == TRUE;
  1244. }
  1245. }
  1246. else
  1247. m_bIsRegistered = true;
  1248. return m_bIsRegistered;
  1249. }
  1250. bool CHotKey::Unregister(bool bOnShowingDitto)
  1251. {
  1252. if(!m_bIsRegistered)
  1253. return true;
  1254. if(bOnShowingDitto)
  1255. {
  1256. if(m_bUnRegisterOnShowDitto == false)
  1257. return true;
  1258. }
  1259. if(m_Key)
  1260. {
  1261. ASSERT(g_HotKeys.m_hWnd);
  1262. if(::UnregisterHotKey( g_HotKeys.m_hWnd, m_Atom))
  1263. {
  1264. m_bIsRegistered = false;
  1265. return true;
  1266. }
  1267. else
  1268. {
  1269. Log("Unregister" "FAILED!");
  1270. ASSERT(0);
  1271. }
  1272. }
  1273. else
  1274. {
  1275. m_bIsRegistered = false;
  1276. return true;
  1277. }
  1278. return false;
  1279. }
  1280. /*------------------------------------------------------------------*\
  1281. CHotKeys - Manages system-wide hotkeys
  1282. \*------------------------------------------------------------------*/
  1283. CHotKeys g_HotKeys;
  1284. CHotKeys::CHotKeys() : m_hWnd(NULL) {}
  1285. CHotKeys::~CHotKeys()
  1286. {
  1287. CHotKey* pHotKey;
  1288. int count = GetSize();
  1289. for(int i=0; i < count; i++)
  1290. {
  1291. pHotKey = ElementAt(i);
  1292. if(pHotKey)
  1293. delete pHotKey;
  1294. }
  1295. }
  1296. int CHotKeys::Find( CHotKey* pHotKey )
  1297. {
  1298. int count = GetSize();
  1299. for(int i=0; i < count; i++)
  1300. {
  1301. if( pHotKey == ElementAt(i) )
  1302. return i;
  1303. }
  1304. return -1;
  1305. }
  1306. bool CHotKeys::Remove( CHotKey* pHotKey )
  1307. {
  1308. int i = Find(pHotKey);
  1309. if(i >= 0)
  1310. {
  1311. RemoveAt(i);
  1312. return true;
  1313. }
  1314. return false;
  1315. }
  1316. void CHotKeys::LoadAllKeys()
  1317. {
  1318. int count = GetSize();
  1319. for(int i=0; i < count; i++)
  1320. ElementAt(i)->LoadKey();
  1321. }
  1322. void CHotKeys::SaveAllKeys()
  1323. {
  1324. int count = GetSize();
  1325. for(int i=0; i < count; i++)
  1326. ElementAt(i)->SaveKey();
  1327. }
  1328. void CHotKeys::RegisterAll(bool bMsgOnError)
  1329. {
  1330. CString str;
  1331. CHotKey* pHotKey;
  1332. int count = GetSize();
  1333. for(int i = 0; i < count; i++)
  1334. {
  1335. pHotKey = ElementAt(i);
  1336. if(!pHotKey->Register())
  1337. {
  1338. str = "Error Registering ";
  1339. str += pHotKey->GetName();
  1340. Log(str);
  1341. if(bMsgOnError)
  1342. AfxMessageBox(str);
  1343. }
  1344. }
  1345. }
  1346. void CHotKeys::UnregisterAll(bool bMsgOnError, bool bOnShowDitto)
  1347. {
  1348. CString str;
  1349. CHotKey* pHotKey;
  1350. int count = GetSize();
  1351. for(int i = 0; i < count; i++)
  1352. {
  1353. pHotKey = ElementAt(i);
  1354. if(!pHotKey->Unregister(bOnShowDitto))
  1355. {
  1356. str = "Error Unregistering ";
  1357. str += pHotKey->GetName();
  1358. Log(str);
  1359. if(bMsgOnError)
  1360. AfxMessageBox(str);
  1361. }
  1362. }
  1363. }
  1364. void CHotKeys::GetKeys(ARRAY& keys)
  1365. {
  1366. int count = GetSize();
  1367. keys.SetSize(count);
  1368. for(int i=0; i < count; i++)
  1369. keys[i] = ElementAt(i)->GetKey();
  1370. }
  1371. // caution! this alters hotkeys based upon corresponding indexes
  1372. void CHotKeys::SetKeys(ARRAY& keys, bool bSave)
  1373. {
  1374. int count = GetSize();
  1375. ASSERT(count == keys.GetSize());
  1376. for(int i=0; i < count; i++)
  1377. ElementAt(i)->SetKey(keys[i], bSave);
  1378. }
  1379. bool CHotKeys::FindFirstConflict(ARRAY& keys, int* pX, int* pY)
  1380. {
  1381. bool bConflict = false;
  1382. int i, j;
  1383. int count = keys.GetSize();
  1384. DWORD key;
  1385. for(i = 0; i < count && !bConflict; i++)
  1386. {
  1387. key = keys.ElementAt(i);
  1388. // only check valid keys
  1389. if(key == 0)
  1390. continue;
  1391. // scan the array for a duplicate
  1392. for(j = i+1; j < count; j++ )
  1393. {
  1394. if(keys.ElementAt(j) == key)
  1395. {
  1396. bConflict = true;
  1397. break;
  1398. }
  1399. }
  1400. }
  1401. if(bConflict)
  1402. {
  1403. if(pX)
  1404. *pX = i-1;
  1405. if(pY)
  1406. *pY = j;
  1407. }
  1408. return bConflict;
  1409. }
  1410. // if true, pX and pY (if valid) are set to the indexes of the conflicting hotkeys.
  1411. bool CHotKeys::FindFirstConflict(int* pX, int* pY)
  1412. {
  1413. ARRAY keys;
  1414. GetKeys(keys);
  1415. return FindFirstConflict(keys, pX, pY);
  1416. }
  1417. /****************************************************************************************************
  1418. BOOL CALLBACK MyMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
  1419. ***************************************************************************************************/
  1420. typedef struct
  1421. {
  1422. long lFlags; // Flags
  1423. LPRECT pVirtualRect; // Ptr to rect that receives the results, or the src of the monitor search method
  1424. int iMonitor; // Ndx to the mointor to look at, -1 for all, -or- result of the monitor search method
  1425. int nMonitorCount; // Total number of monitors found, -1 for monitor search method
  1426. } MONITOR_ENUM_PARAM;
  1427. #define MONITOR_SEARCH_METOHD 0x00000001
  1428. BOOL CALLBACK MyMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
  1429. {
  1430. // Typecast param
  1431. MONITOR_ENUM_PARAM* pParam = (MONITOR_ENUM_PARAM*)dwData;
  1432. if(pParam)
  1433. {
  1434. // If a dest rect was passed
  1435. if(pParam->pVirtualRect)
  1436. {
  1437. // If MONITOR_SEARCH_METOHD then we are being asked for the index of the monitor
  1438. // that the rect falls inside of
  1439. if(pParam->lFlags & MONITOR_SEARCH_METOHD)
  1440. {
  1441. if( (pParam->pVirtualRect->right < lprcMonitor->left) ||
  1442. (pParam->pVirtualRect->left > lprcMonitor->right) ||
  1443. (pParam->pVirtualRect->bottom < lprcMonitor->top) ||
  1444. (pParam->pVirtualRect->top > lprcMonitor->bottom))
  1445. {
  1446. // Nothing
  1447. }
  1448. else
  1449. {
  1450. // This is the one
  1451. pParam->iMonitor = pParam->nMonitorCount;
  1452. // Stop the enumeration
  1453. return FALSE;
  1454. }
  1455. }
  1456. else
  1457. {
  1458. if(pParam->iMonitor == pParam->nMonitorCount)
  1459. {
  1460. *pParam->pVirtualRect = *lprcMonitor;
  1461. }
  1462. else
  1463. if(pParam->iMonitor == -1)
  1464. {
  1465. pParam->pVirtualRect->left = min(pParam->pVirtualRect->left, lprcMonitor->left);
  1466. pParam->pVirtualRect->top = min(pParam->pVirtualRect->top, lprcMonitor->top);
  1467. pParam->pVirtualRect->right = max(pParam->pVirtualRect->right, lprcMonitor->right);
  1468. pParam->pVirtualRect->bottom = max(pParam->pVirtualRect->bottom, lprcMonitor->bottom);
  1469. }
  1470. }
  1471. }
  1472. // Up the count if necessary
  1473. pParam->nMonitorCount++;
  1474. }
  1475. return TRUE;
  1476. }
  1477. int GetScreenWidth(void)
  1478. {
  1479. OSVERSIONINFO OS_Version_Info;
  1480. DWORD dwPlatform = 0;
  1481. if(GetVersionEx(&OS_Version_Info) != 0)
  1482. {
  1483. dwPlatform = OS_Version_Info.dwPlatformId;
  1484. }
  1485. if(dwPlatform == VER_PLATFORM_WIN32_NT)
  1486. {
  1487. int width, height;
  1488. width = GetSystemMetrics(SM_CXSCREEN);
  1489. height = GetSystemMetrics(SM_CYSCREEN);
  1490. switch(width)
  1491. {
  1492. default:
  1493. case 640:
  1494. case 800:
  1495. case 1024:
  1496. return(width);
  1497. case 1280:
  1498. if(height == 480)
  1499. {
  1500. return(width / 2);
  1501. }
  1502. return(width);
  1503. case 1600:
  1504. if(height == 600)
  1505. {
  1506. return(width / 2);
  1507. }
  1508. return(width);
  1509. case 2048:
  1510. if(height == 768)
  1511. {
  1512. return(width / 2);
  1513. }
  1514. return(width);
  1515. }
  1516. }
  1517. else
  1518. {
  1519. return(GetSystemMetrics(SM_CXSCREEN));
  1520. }
  1521. }
  1522. int GetScreenHeight(void)
  1523. {
  1524. OSVERSIONINFO OS_Version_Info;
  1525. DWORD dwPlatform = 0;
  1526. if(GetVersionEx(&OS_Version_Info) != 0)
  1527. {
  1528. dwPlatform = OS_Version_Info.dwPlatformId;
  1529. }
  1530. if(dwPlatform == VER_PLATFORM_WIN32_NT)
  1531. {
  1532. int width, height;
  1533. width = GetSystemMetrics(SM_CXSCREEN);
  1534. height = GetSystemMetrics(SM_CYSCREEN);
  1535. switch(height)
  1536. {
  1537. default:
  1538. case 480:
  1539. case 600:
  1540. case 768:
  1541. return(height);
  1542. case 960:
  1543. if(width == 640)
  1544. {
  1545. return(height / 2);
  1546. }
  1547. return(height);
  1548. case 1200:
  1549. if(width == 800)
  1550. {
  1551. return(height / 2);
  1552. }
  1553. return(height);
  1554. case 1536:
  1555. if(width == 1024)
  1556. {
  1557. return(height / 2);
  1558. }
  1559. return(height);
  1560. }
  1561. }
  1562. else
  1563. {
  1564. return(GetSystemMetrics(SM_CYSCREEN));
  1565. }
  1566. }
  1567. int GetMonitorFromRect(LPRECT lpMonitorRect)
  1568. {
  1569. // Build up the param
  1570. MONITOR_ENUM_PARAM EnumParam;
  1571. ZeroMemory(&EnumParam, sizeof(EnumParam));
  1572. EnumParam.lFlags = MONITOR_SEARCH_METOHD;
  1573. EnumParam.pVirtualRect = lpMonitorRect;
  1574. EnumParam.iMonitor = -1;
  1575. // Enum Displays
  1576. EnumDisplayMonitors(NULL, NULL, MyMonitorEnumProc, (long)&EnumParam);
  1577. // Return the result
  1578. return EnumParam.iMonitor;
  1579. }
  1580. void GetMonitorRect(int iMonitor, LPRECT lpDestRect)
  1581. {
  1582. // Build up the param
  1583. MONITOR_ENUM_PARAM EnumParam;
  1584. ZeroMemory(&EnumParam, sizeof(EnumParam));
  1585. EnumParam.iMonitor = iMonitor;
  1586. EnumParam.pVirtualRect = lpDestRect;
  1587. // Zero out dest rect
  1588. lpDestRect->bottom = lpDestRect->left = lpDestRect->right = lpDestRect->top = 0;
  1589. // Enum Displays
  1590. EnumDisplayMonitors(NULL, NULL, MyMonitorEnumProc, (long)&EnumParam);
  1591. // If not successful, default to the screen dimentions
  1592. if(lpDestRect->right == 0 || lpDestRect->bottom == 0)
  1593. {
  1594. lpDestRect->right = GetScreenWidth();
  1595. lpDestRect->bottom = GetScreenHeight();
  1596. }
  1597. }
  1598. /*------------------------------------------------------------------*\
  1599. CAccel - an Accelerator (in-app hotkey)
  1600. - the win32 CreateAcceleratorTable using ACCEL was insufficient
  1601. because it only allowed a WORD for the cmd associated with it.
  1602. \*------------------------------------------------------------------*/
  1603. /*------------------------------------------------------------------*\
  1604. CAccels - Manages a set of CAccel
  1605. \*------------------------------------------------------------------*/
  1606. int CompareAccel( const void* pLeft, const void* pRight )
  1607. {
  1608. WORD w;
  1609. int l,r;
  1610. // swap bytes: place the VirtualKey in the MSB and the modifier in the LSB
  1611. // so that Accels based upon the same vkey are grouped together.
  1612. // this is required by our use of m_Index
  1613. // alternatively, we could store them this way in CAccel.
  1614. w = (WORD) ((CAccel*)pLeft)->Key;
  1615. l = (ACCEL_VKEY(w) << 8) | ACCEL_MOD(w);
  1616. w = (WORD) ((CAccel*)pRight)->Key;
  1617. r = (ACCEL_VKEY(w) << 8) | ACCEL_MOD(w);
  1618. return l - r;
  1619. }
  1620. CAccels::CAccels()
  1621. {}
  1622. void CAccels::AddAccel( CAccel& a )
  1623. {
  1624. m_Map.SetAt(a.Key, a.Cmd);
  1625. }
  1626. bool CAccels::OnMsg( MSG* pMsg, DWORD &dID)
  1627. {
  1628. // bit 30 (0x40000000) is 1 if this is NOT the first msg of the key
  1629. // i.e. auto-repeat may cause multiple msgs of the same key
  1630. if( (pMsg->lParam & 0x40000000) ||
  1631. (pMsg->message != WM_KEYDOWN &&
  1632. pMsg->message != WM_SYSKEYDOWN) )
  1633. {
  1634. return NULL;
  1635. }
  1636. if( !pMsg || m_Map.GetCount() <= 0 )
  1637. return NULL;
  1638. BYTE vkey = LOBYTE(pMsg->wParam);
  1639. BYTE mod = GetKeyStateModifiers();
  1640. DWORD key = ACCEL_MAKEKEY( vkey, mod );
  1641. if(m_Map.Lookup(key, dID))
  1642. return true;;
  1643. return false;
  1644. }
  1645. BYTE GetKeyStateModifiers()
  1646. {
  1647. BYTE m=0;
  1648. if( GetKeyState(VK_SHIFT) & 0x8000 )
  1649. m |= HOTKEYF_SHIFT;
  1650. if( GetKeyState(VK_CONTROL) & 0x8000 )
  1651. m |= HOTKEYF_CONTROL;
  1652. if( GetKeyState(VK_MENU) & 0x8000 )
  1653. m |= HOTKEYF_ALT;
  1654. return m;
  1655. }
  1656. /*------------------------------------------------------------------*\
  1657. CTokenizer - Tokenizes a string using given delimiters
  1658. \*------------------------------------------------------------------*/
  1659. CTokenizer::CTokenizer(const CString& cs, const CString& csDelim):
  1660. m_cs(cs),
  1661. m_nCurPos(0)
  1662. {
  1663. SetDelimiters(csDelim);
  1664. }
  1665. void CTokenizer::SetDelimiters(const CString& csDelim)
  1666. {
  1667. for(int i = 0; i < csDelim.GetLength(); ++i)
  1668. m_delim.set(static_cast<BYTE>(csDelim[i]));
  1669. }
  1670. bool CTokenizer::Next(CString& cs)
  1671. {
  1672. int len = m_cs.GetLength();
  1673. cs.Empty();
  1674. while(m_nCurPos < len && m_delim[static_cast<BYTE>(m_cs[m_nCurPos])])
  1675. ++m_nCurPos;
  1676. if(m_nCurPos >= len)
  1677. return false;
  1678. int nStartPos = m_nCurPos;
  1679. while(m_nCurPos < len && !m_delim[static_cast<BYTE>(m_cs[m_nCurPos])])
  1680. ++m_nCurPos;
  1681. cs = m_cs.Mid(nStartPos, m_nCurPos - nStartPos);
  1682. return true;
  1683. }
  1684. CString CTokenizer::Tail() const
  1685. {
  1686. int len = m_cs.GetLength();
  1687. int nCurPos = m_nCurPos;
  1688. while(nCurPos < len && m_delim[static_cast<BYTE>(m_cs[nCurPos])])
  1689. ++nCurPos;
  1690. CString csResult;
  1691. if(nCurPos < len)
  1692. csResult = m_cs.Mid(nCurPos);
  1693. return csResult;
  1694. }
  1695. /*------------------------------------------------------------------*\
  1696. Global ToolTip Manual Control Functions
  1697. \*------------------------------------------------------------------*/
  1698. void InitToolInfo( TOOLINFO& ti )
  1699. {
  1700. // INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE
  1701. ti.cbSize = sizeof(TOOLINFO);
  1702. ti.uFlags = TTF_ABSOLUTE | TTF_TRACK;
  1703. ti.hwnd = NULL;
  1704. ti.hinst = NULL;
  1705. ti.uId = 0; // CPopup only uses uid 0
  1706. ti.lpszText = NULL;
  1707. // ToolTip control will cover the whole window
  1708. ti.rect.left = 0;
  1709. ti.rect.top = 0;
  1710. ti.rect.right = 0;
  1711. ti.rect.bottom = 0;
  1712. }
  1713. /*------------------------------------------------------------------*\
  1714. CPopup - a tooltip that pops up manually (when Show is called).
  1715. - technique learned from codeproject "ToolTipZen" by "Zarembo Maxim"
  1716. \*------------------------------------------------------------------*/
  1717. CPopup::CPopup()
  1718. {
  1719. Init();
  1720. }
  1721. // HWND_TOP
  1722. CPopup::CPopup( int x, int y, HWND hWndPosRelativeTo, HWND hWndInsertAfter )
  1723. {
  1724. Init();
  1725. m_hWndPosRelativeTo = hWndPosRelativeTo;
  1726. m_hWndInsertAfter = hWndInsertAfter;
  1727. SetPos( CPoint(x,y) );
  1728. }
  1729. CPopup::~CPopup()
  1730. {
  1731. Hide();
  1732. if( m_bOwnTT && ::IsWindow(m_hTTWnd) )
  1733. ::DestroyWindow( m_hTTWnd );
  1734. }
  1735. void CPopup::Init()
  1736. {
  1737. // initialize variables
  1738. m_bOwnTT = false;
  1739. m_hTTWnd = NULL;
  1740. m_bIsShowing = false;
  1741. m_bAllowShow = true; // used by AllowShow()
  1742. m_Pos.x = m_Pos.y = 0;
  1743. m_bTop = true;
  1744. m_bLeft = true;
  1745. m_bCenterX = false;
  1746. m_bCenterY = false;
  1747. m_hWndPosRelativeTo = NULL;
  1748. RECT rcScreen;
  1749. GetMonitorRect(-1, &rcScreen);
  1750. m_ScreenMaxX = rcScreen.right;
  1751. m_ScreenMaxY = rcScreen.bottom;
  1752. m_hWndInsertAfter = HWND_TOP; //HWND_TOPMOST
  1753. SetTTWnd();
  1754. }
  1755. void CPopup::SetTTWnd( HWND hTTWnd, TOOLINFO* pTI )
  1756. {
  1757. if( pTI )
  1758. m_TI = *pTI;
  1759. else
  1760. InitToolInfo( m_TI );
  1761. if( m_bOwnTT && ::IsWindow(m_hTTWnd) )
  1762. {
  1763. if( !::IsWindow(hTTWnd) )
  1764. return; // we would have to recreate the one that already exists
  1765. ::DestroyWindow( m_hTTWnd );
  1766. }
  1767. m_hTTWnd = hTTWnd;
  1768. if( ::IsWindow(m_hTTWnd) )
  1769. {
  1770. m_bOwnTT = false;
  1771. // if our uid tooltip already exists, get the data, else add it.
  1772. if( ! ::SendMessage(m_hTTWnd, TTM_GETTOOLINFO, 0, (LPARAM)(LPTOOLINFO) &m_TI) )
  1773. ::SendMessage(m_hTTWnd, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &m_TI);
  1774. }
  1775. else
  1776. {
  1777. m_bOwnTT = true;
  1778. CreateToolTip();
  1779. }
  1780. }
  1781. void CPopup::CreateToolTip()
  1782. {
  1783. if( m_hTTWnd != NULL )
  1784. return;
  1785. // CREATE A TOOLTIP WINDOW
  1786. m_hTTWnd = CreateWindowEx(
  1787. WS_EX_TOPMOST,
  1788. TOOLTIPS_CLASS,
  1789. NULL,
  1790. TTS_NOPREFIX | TTS_ALWAYSTIP,
  1791. CW_USEDEFAULT,
  1792. CW_USEDEFAULT,
  1793. CW_USEDEFAULT,
  1794. CW_USEDEFAULT,
  1795. NULL,
  1796. NULL,
  1797. NULL,
  1798. NULL
  1799. );
  1800. m_bOwnTT = true;
  1801. // SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW
  1802. ::SendMessage(m_hTTWnd, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &m_TI);
  1803. }
  1804. void CPopup::SetTimeout( int timeout )
  1805. {
  1806. if( m_hTTWnd == NULL )
  1807. return;
  1808. ::SendMessage(m_hTTWnd, TTM_SETDELAYTIME, TTDT_AUTOMATIC, timeout);
  1809. }
  1810. void CPopup::SetPos( CPoint& pos )
  1811. {
  1812. m_Pos = pos;
  1813. }
  1814. void CPopup::SetPosInfo( bool bTop, bool bCenterY, bool bLeft, bool bCenterX )
  1815. {
  1816. m_bTop = bTop;
  1817. m_bCenterY = bCenterY;
  1818. m_bLeft = bLeft;
  1819. m_bCenterX = bCenterX;
  1820. }
  1821. void CPopup::AdjustPos( CPoint& pos )
  1822. {
  1823. CRect rel(0,0,0,0);
  1824. CRect rect(0,0,0,0);
  1825. // ::SendMessage(m_hTTWnd, TTM_ADJUSTRECT, TRUE, (LPARAM)&rect);
  1826. ::GetWindowRect(m_hTTWnd,&rect);
  1827. if( ::IsWindow(m_hWndPosRelativeTo) )
  1828. ::GetWindowRect(m_hWndPosRelativeTo, &rel);
  1829. // move the rect to the relative origin
  1830. rect.bottom = rect.Height() + rel.top;
  1831. rect.top = rel.top;
  1832. rect.right = rect.Width() + rel.left;
  1833. rect.left = rel.left;
  1834. // adjust the y position
  1835. rect.OffsetRect( 0, pos.y - (m_bCenterY? rect.Height()/2: (m_bTop? 0: rect.Height())) );
  1836. if( rect.bottom > m_ScreenMaxY )
  1837. rect.OffsetRect( 0, m_ScreenMaxY - rect.bottom );
  1838. // adjust the x position
  1839. rect.OffsetRect( pos.x - (m_bCenterX? rect.Width()/2: (m_bLeft? 0: rect.Width())), 0 );
  1840. if( rect.right > m_ScreenMaxX )
  1841. rect.OffsetRect( m_ScreenMaxX - rect.right, 0 );
  1842. pos.x = rect.left;
  1843. pos.y = rect.top;
  1844. }
  1845. void CPopup::SendToolTipText( CString text )
  1846. {
  1847. m_csToolTipText = text;
  1848. //Replace the tabs with spaces, the tooltip didn't like the \t s
  1849. text.Replace("\t", " ");
  1850. m_TI.lpszText = (LPSTR) (LPCTSTR) text;
  1851. // this allows \n and \r to be interpreted correctly
  1852. ::SendMessage(m_hTTWnd, TTM_SETMAXTIPWIDTH, 0, 500);
  1853. // set the text
  1854. ::SendMessage(m_hTTWnd, TTM_SETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &m_TI);
  1855. }
  1856. void CPopup::Show( CString text, CPoint pos, bool bAdjustPos )
  1857. {
  1858. if( m_hTTWnd == NULL )
  1859. return;
  1860. m_csToolTipText = text;
  1861. if( !m_bIsShowing )
  1862. ::SendMessage(m_hTTWnd, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG(-10000,-10000));
  1863. SendToolTipText( text );
  1864. ::SendMessage(m_hTTWnd, TTM_TRACKACTIVATE, true, (LPARAM)(LPTOOLINFO) &m_TI);
  1865. if( bAdjustPos )
  1866. AdjustPos(pos);
  1867. // set the position
  1868. ::SendMessage(m_hTTWnd, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG(pos.x,pos.y));
  1869. // make sure the tooltip will be on top.
  1870. ::SetWindowPos( m_hTTWnd, m_hWndInsertAfter, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE );
  1871. m_bIsShowing = true;
  1872. }
  1873. void CPopup::Show( CString text )
  1874. {
  1875. m_csToolTipText = text;
  1876. Show( text, m_Pos );
  1877. }
  1878. void CPopup::AllowShow( CString text )
  1879. {
  1880. m_csToolTipText = text;
  1881. if( m_bAllowShow )
  1882. Show( text, m_Pos );
  1883. }
  1884. void CPopup::Hide()
  1885. {
  1886. if( m_hTTWnd == NULL )
  1887. return;
  1888. // deactivate if it is currently activated
  1889. ::SendMessage(m_hTTWnd, TTM_TRACKACTIVATE, FALSE, (LPARAM)(LPTOOLINFO) &m_TI);
  1890. m_bIsShowing = false;
  1891. }
  1892. #include "Encryption.h"
  1893. #define STRING_PASSWORD "*4ei)"
  1894. BOOL EncryptString(CString &csIn, UCHAR *&pOutput, int &nLenOutput)
  1895. {
  1896. BOOL bRet = FALSE;
  1897. CEncryption *pEncryptor;
  1898. pEncryptor = new CEncryption;
  1899. if(pEncryptor)
  1900. {
  1901. UCHAR *pData = (UCHAR*)csIn.GetBuffer(csIn.GetLength());
  1902. nLenOutput = 0;
  1903. if(pEncryptor->Encrypt(pData, csIn.GetLength(), STRING_PASSWORD, pOutput, nLenOutput))
  1904. {
  1905. bRet = TRUE;
  1906. }
  1907. delete pEncryptor;
  1908. }
  1909. return bRet;
  1910. }
  1911. BOOL DecryptString(UCHAR *pData, int nLenIn, UCHAR *&pOutput, int &nLenOutput)
  1912. {
  1913. BOOL bRet = FALSE;
  1914. CEncryption *pEncryptor;
  1915. pEncryptor = new CEncryption;
  1916. if(pEncryptor)
  1917. {
  1918. if(pEncryptor->Decrypt(pData, nLenIn, STRING_PASSWORD, pOutput, nLenOutput))
  1919. {
  1920. bRet = TRUE;
  1921. }
  1922. delete pEncryptor;
  1923. }
  1924. return bRet;
  1925. }
  1926. LPCSTR GetMonthAbb(long lMonth)
  1927. {
  1928. switch(lMonth)
  1929. {
  1930. case 1:
  1931. return "Jan";
  1932. case 2:
  1933. return "Feb";
  1934. case 3:
  1935. return "Mar";
  1936. case 4:
  1937. return "Apr";
  1938. case 5:
  1939. return "May";
  1940. case 6:
  1941. return "Jun";
  1942. case 7:
  1943. return "Jul";
  1944. case 8:
  1945. return "Aug";
  1946. case 9:
  1947. return "Sep";
  1948. case 10:
  1949. return "Oct";
  1950. case 11:
  1951. return "Nov";
  1952. case 12:
  1953. return "Dec";
  1954. }
  1955. return "";
  1956. }