Misc.cpp 53 KB

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