Misc.cpp 53 KB

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