Misc.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233
  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. CGetSetOptions g_Opt;
  430. CGetSetOptions::CGetSetOptions()
  431. {
  432. m_nLinesPerRow = GetLinesPerRow();
  433. m_bUseCtrlNumAccel = GetUseCtrlNumForFirstTenHotKeys();
  434. m_bAllowDuplicates = GetAllowDuplicates();
  435. m_bUpdateTimeOnPaste = GetUpdateTimeOnPaste();
  436. m_bSaveMultiPaste = GetSaveMultiPaste();
  437. m_bShowPersistent = GetShowPersistent();
  438. m_bHistoryStartTop = GetHistoryStartTop();
  439. m_bDescTextSize = GetDescTextSize();
  440. m_bDescShowLeadingWhiteSpace = GetDescShowLeadingWhiteSpace();
  441. m_bAllwaysShowDescription = GetAllwaysShowDescription();
  442. m_bDoubleClickingOnCaptionDoes = GetDoubleClickingOnCaptionDoes();
  443. m_bPrompForNewGroupName = GetPrompForNewGroupName();
  444. m_bSendPasteOnFirstTenHotKeys = GetSendPasteOnFirstTenHotKeys();
  445. m_csIPListToPutOnClipboard = GetListToPutOnClipboard();
  446. m_bLogSendReceiveErrors = GetLogSendReceiveErrors();
  447. m_bUseHookDllForFocus = GetProfileLong("UseHookDllForFocus", TRUE);
  448. m_HideDittoOnHotKeyIfAlreadyShown = GetHideDittoOnHotKeyIfAlreadyShown();
  449. m_lPort = GetPort();
  450. m_bDrawThumbnail = GetDrawThumbnail();
  451. m_csPassword = GetNetworkPassword();
  452. m_bDrawRTF = GetDrawRTF();
  453. m_bMultiPasteReverse = GetMultiPasteReverse();
  454. m_csPlaySoundOnCopy = GetPlaySoundOnCopy();
  455. m_bSendPasteMessageAfterSelection = GetSendPasteAfterSelection();
  456. m_bFindAsYouType = GetFindAsYouType();
  457. m_bEnsureEntireWindowCanBeSeen = GetEnsureEntireWindowCanBeSeen();
  458. m_bShowAllClipsInMainList = GetShowAllClipsInMainList();
  459. m_csNetworkPasswordArray.RemoveAll();
  460. CString cs = GetProfileString("NetorkPassword1", "");
  461. m_csNetworkPasswordArray.Add(cs);
  462. cs = GetProfileString("NetworkPassword2", "");
  463. m_csNetworkPasswordArray.Add(cs);
  464. cs = GetProfileString("NetworkPassword3", "");
  465. m_csNetworkPasswordArray.Add(cs);
  466. cs = GetProfileString("NetworkPassword4", "");
  467. m_csNetworkPasswordArray.Add(cs);
  468. cs = GetProfileString("NetworkPassword5", "");
  469. m_csNetworkPasswordArray.Add(cs);
  470. cs = GetProfileString("NetworkPassword6", "");
  471. m_csNetworkPasswordArray.Add(cs);
  472. cs = GetProfileString("NetworkPassword7", "");
  473. m_csNetworkPasswordArray.Add(cs);
  474. cs = GetProfileString("NetworkPassword8", "");
  475. m_csNetworkPasswordArray.Add(cs);
  476. cs = GetProfileString("NetworkPassword9", "");
  477. m_csNetworkPasswordArray.Add(cs);
  478. cs = GetProfileString("NetworkPassword10", "");
  479. m_csNetworkPasswordArray.Add(cs);
  480. #ifdef _DEBUG
  481. m_bUseHookDllForFocus = FALSE;
  482. #endif
  483. for(int i = 0; i < MAX_SEND_CLIENTS; i++)
  484. {
  485. GetSendClients(i);
  486. }
  487. GetClientSendCount();
  488. }
  489. CGetSetOptions::~CGetSetOptions()
  490. {
  491. }
  492. long CGetSetOptions::GetProfileLong(CString csName, long bDefaultValue)
  493. {
  494. HKEY hkKey;
  495. long lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T(REG_PATH),
  496. NULL, KEY_READ, &hkKey);
  497. if(lResult != ERROR_SUCCESS)
  498. return bDefaultValue;
  499. DWORD buffer;
  500. DWORD len = sizeof(buffer);
  501. DWORD type;
  502. lResult = ::RegQueryValueEx(hkKey, csName, 0, &type, (LPBYTE)&buffer, &len);
  503. RegCloseKey(hkKey);
  504. if(lResult == ERROR_SUCCESS)
  505. return (long)buffer;
  506. return bDefaultValue;
  507. }
  508. CString CGetSetOptions::GetProfileString(CString csName, CString csDefault)
  509. {
  510. HKEY hkKey;
  511. long lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T(REG_PATH),
  512. NULL, KEY_READ, &hkKey);
  513. char szString[256];
  514. DWORD dwBufLen = 256;
  515. lResult = ::RegQueryValueEx(hkKey , csName, NULL, NULL, (LPBYTE)szString, &dwBufLen);
  516. if(lResult != ERROR_SUCCESS)
  517. return csDefault;
  518. return CString(szString);
  519. }
  520. BOOL CGetSetOptions::SetProfileLong(CString csName, long lValue)
  521. {
  522. HKEY hkKey;
  523. DWORD dWord;
  524. long lResult = RegCreateKeyEx(HKEY_CURRENT_USER, _T(REG_PATH), NULL,
  525. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  526. NULL, &hkKey, &dWord);
  527. if(lResult != ERROR_SUCCESS)
  528. return FALSE;
  529. DWORD val = (DWORD)lValue;
  530. lResult = ::RegSetValueEx(hkKey, csName, 0, REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
  531. RegCloseKey(hkKey);
  532. return lResult == ERROR_SUCCESS;
  533. }
  534. BOOL CGetSetOptions::SetProfileString(CString csName, CString csValue)
  535. {
  536. HKEY hkKey;
  537. DWORD dWord;
  538. long lResult = RegCreateKeyEx(HKEY_CURRENT_USER, _T(REG_PATH), NULL,
  539. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  540. NULL, &hkKey, &dWord);
  541. if(lResult != ERROR_SUCCESS)
  542. return FALSE;
  543. ::RegSetValueEx(hkKey, csName, NULL, REG_SZ,
  544. (BYTE*)(LPCTSTR)csValue, csValue.GetLength()+sizeof(TCHAR));
  545. RegCloseKey(hkKey);
  546. return lResult == ERROR_SUCCESS;
  547. }
  548. BOOL CGetSetOptions::SetProfileData(CString csName, LPVOID lpData, DWORD dwLength)
  549. {
  550. HKEY hkKey;
  551. DWORD dWord;
  552. long lResult = RegCreateKeyEx(HKEY_CURRENT_USER, _T(REG_PATH), NULL,
  553. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  554. NULL, &hkKey, &dWord);
  555. if(lResult != ERROR_SUCCESS)
  556. return FALSE;
  557. ::RegSetValueEx(hkKey, csName, NULL, REG_BINARY,
  558. (BYTE*)lpData, dwLength);
  559. RegCloseKey(hkKey);
  560. return lResult == ERROR_SUCCESS;
  561. }
  562. LPVOID CGetSetOptions::GetProfileData(CString csName, DWORD &dwLength)
  563. {
  564. HKEY hkKey;
  565. long lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T(REG_PATH),
  566. NULL, KEY_READ, &hkKey);
  567. lResult = ::RegQueryValueEx(hkKey , csName, NULL, NULL, NULL, &dwLength);
  568. if(lResult != ERROR_SUCCESS)
  569. return NULL;
  570. LPVOID lpVoid = new BYTE[dwLength];
  571. lResult = ::RegQueryValueEx(hkKey , csName, NULL, NULL, (LPBYTE)lpVoid, &dwLength);
  572. if(lResult != ERROR_SUCCESS)
  573. return NULL;
  574. return lpVoid;
  575. }
  576. BOOL CGetSetOptions::GetShowIconInSysTray()
  577. {
  578. return GetProfileLong("ShowIconInSystemTray", TRUE);
  579. }
  580. BOOL CGetSetOptions::SetShowIconInSysTray(BOOL bShow)
  581. {
  582. return SetProfileLong("ShowIconInSystemTray", bShow);
  583. }
  584. BOOL CGetSetOptions::SetEnableTransparency(BOOL bCheck)
  585. {
  586. return SetProfileLong("EnableTransparency", bCheck);
  587. }
  588. BOOL CGetSetOptions::GetEnableTransparency()
  589. {
  590. return GetProfileLong("EnableTransparency", FALSE);
  591. }
  592. BOOL CGetSetOptions::SetTransparencyPercent(long lPercent)
  593. {
  594. #ifdef AFTER_98
  595. if(lPercent > OPACITY_MAX)
  596. lPercent = OPACITY_MAX;
  597. if(lPercent < 0)
  598. lPercent = 0;
  599. return SetProfileLong("TransparencyPercent", lPercent);
  600. #endif
  601. return FALSE;
  602. }
  603. long CGetSetOptions::GetTransparencyPercent()
  604. {
  605. #ifdef AFTER_98
  606. long lValue = GetProfileLong("TransparencyPercent", 14);
  607. if(lValue > OPACITY_MAX) lValue = OPACITY_MAX;
  608. if(lValue < 0) lValue = 0;
  609. return lValue;
  610. #endif
  611. return 0;
  612. }
  613. BOOL CGetSetOptions::SetLinesPerRow(long lLines)
  614. {
  615. m_nLinesPerRow = lLines;
  616. return SetProfileLong("LinesPerRow", lLines);
  617. }
  618. long CGetSetOptions::GetLinesPerRow()
  619. {
  620. return GetProfileLong("LinesPerRow", 2);
  621. }
  622. BOOL CGetSetOptions::GetRunOnStartUp()
  623. {
  624. HKEY hkRun;
  625. LONG nResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  626. _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
  627. NULL, KEY_READ, &hkRun);
  628. if(nResult != ERROR_SUCCESS)
  629. return FALSE;
  630. nResult = RegQueryValueEx(hkRun, GetAppName(), NULL, NULL, NULL, NULL);
  631. RegCloseKey(hkRun);
  632. return nResult == ERROR_SUCCESS;
  633. }
  634. void CGetSetOptions::SetRunOnStartUp(BOOL bRun)
  635. {
  636. if(bRun == GetRunOnStartUp())
  637. return;
  638. HKEY hkRun;
  639. LONG nResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  640. _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
  641. NULL, KEY_ALL_ACCESS, &hkRun);
  642. if(nResult != ERROR_SUCCESS)
  643. return;
  644. if(bRun)
  645. {
  646. CString sExeName = GetExeFileName();
  647. ::RegSetValueEx(hkRun, GetAppName(), NULL, REG_SZ,
  648. (BYTE*)(LPCTSTR)sExeName, sExeName.GetLength()+sizeof(TCHAR));
  649. }
  650. else
  651. {
  652. ::RegDeleteValue(hkRun, GetAppName());
  653. }
  654. ::RegCloseKey(hkRun);
  655. }
  656. CString CGetSetOptions::GetExeFileName()
  657. {
  658. CString sExeName;
  659. GetModuleFileName(NULL, sExeName.GetBuffer(_MAX_PATH),_MAX_PATH);
  660. sExeName.ReleaseBuffer();
  661. return sExeName;
  662. }
  663. CString CGetSetOptions::GetAppName()
  664. {
  665. return "Ditto";
  666. }
  667. BOOL CGetSetOptions::SetQuickPastePosition(long lPosition)
  668. {
  669. return SetProfileLong("ShowQuickPastePosition", lPosition);
  670. }
  671. long CGetSetOptions::GetQuickPastePosition()
  672. {
  673. return GetProfileLong("ShowQuickPastePosition", POS_AT_PREVIOUS);
  674. }
  675. BOOL CGetSetOptions::SetQuickPasteSize(CSize size)
  676. {
  677. BOOL bRet = SetProfileLong("QuickPasteCX", size.cx);
  678. bRet = SetProfileLong("QuickPasteCY", size.cy);
  679. return bRet;
  680. }
  681. void CGetSetOptions::GetQuickPasteSize(CSize &size)
  682. {
  683. size.cx = GetProfileLong("QuickPasteCX", 300);
  684. size.cy = GetProfileLong("QuickPasteCY", 300);
  685. }
  686. BOOL CGetSetOptions::SetQuickPastePoint(CPoint point)
  687. {
  688. BOOL bRet = SetProfileLong("QuickPasteX", point.x);
  689. bRet = SetProfileLong("QuickPasteY", point.y);
  690. return bRet;
  691. }
  692. void CGetSetOptions::GetQuickPastePoint(CPoint &point)
  693. {
  694. point.x = GetProfileLong("QuickPasteX", 300);
  695. point.y = GetProfileLong("QuickPasteY", 300);
  696. }
  697. long CGetSetOptions::GetCopyGap()
  698. {
  699. return GetProfileLong("CopyGap", 150);
  700. }
  701. BOOL CGetSetOptions::SetDBPath(CString csPath)
  702. {
  703. return SetProfileString("DBPath", csPath);
  704. }
  705. CString CGetSetOptions::GetDBPath(BOOL bDefault/* = TRUE*/)
  706. {
  707. //First check the reg string
  708. CString csDefaultPath = GetProfileString("DBPath", "");
  709. //If there is nothing in the regesty then get the default
  710. //In the users application data in my documents
  711. if(bDefault)
  712. {
  713. if(csDefaultPath.IsEmpty())
  714. csDefaultPath = GetDefaultDBName();
  715. }
  716. return csDefaultPath;
  717. }
  718. void CGetSetOptions::SetCheckForMaxEntries(BOOL bVal)
  719. {
  720. SetProfileLong("CheckForMaxEntries", bVal);
  721. }
  722. BOOL CGetSetOptions::GetCheckForMaxEntries()
  723. {
  724. return GetProfileLong("CheckForMaxEntries", 0);
  725. }
  726. void CGetSetOptions::SetCheckForExpiredEntries(BOOL bVal)
  727. {
  728. SetProfileLong("CheckForExpiredEntries", bVal);
  729. }
  730. BOOL CGetSetOptions::GetCheckForExpiredEntries()
  731. {
  732. return GetProfileLong("CheckForExpiredEntries", 0);
  733. }
  734. void CGetSetOptions::SetMaxEntries(long lVal)
  735. {
  736. SetProfileLong("MaxEntries", lVal);
  737. }
  738. long CGetSetOptions::GetMaxEntries()
  739. {
  740. return GetProfileLong("MaxEntries", 500);
  741. }
  742. void CGetSetOptions::SetExpiredEntries(long lVal)
  743. {
  744. SetProfileLong("ExpiredEntries", lVal);
  745. }
  746. long CGetSetOptions::GetExpiredEntries()
  747. {
  748. return GetProfileLong("ExpiredEntries", 5);
  749. }
  750. void CGetSetOptions::SetTripCopyCount(long lVal)
  751. {
  752. // negative means a relative offset
  753. if(lVal < 0)
  754. lVal = GetTripCopyCount() - lVal; // add the absolute value
  755. if(GetTripDate() == 0)
  756. SetTripDate(-1);
  757. SetProfileLong("TripCopies", lVal);
  758. }
  759. long CGetSetOptions::GetTripCopyCount()
  760. {
  761. return GetProfileLong("TripCopies", 0);
  762. }
  763. void CGetSetOptions::SetTripPasteCount(long lVal)
  764. {
  765. // negative means a relative offset
  766. if(lVal < 0)
  767. lVal = GetTripPasteCount() - lVal; // add the absolute value
  768. if(GetTripDate() == 0)
  769. SetTripDate(-1);
  770. SetProfileLong("TripPastes", lVal);
  771. }
  772. long CGetSetOptions::GetTripPasteCount()
  773. {
  774. return GetProfileLong("TripPastes", 0);
  775. }
  776. void CGetSetOptions::SetTripDate(long lDate)
  777. {
  778. if(lDate == -1)
  779. lDate = (long)CTime::GetCurrentTime().GetTime();
  780. SetProfileLong("TripDate", lDate);
  781. }
  782. long CGetSetOptions::GetTripDate()
  783. {
  784. return GetProfileLong("TripDate", 0);
  785. }
  786. void CGetSetOptions::SetTotalCopyCount(long lVal)
  787. {
  788. // negative means a relative offset
  789. if(lVal < 0)
  790. lVal = GetTotalCopyCount() - lVal; // add the absolute value
  791. if(GetTotalDate() == 0)
  792. SetTotalDate(-1);
  793. SetProfileLong("TotalCopies", lVal);
  794. }
  795. long CGetSetOptions::GetTotalCopyCount()
  796. {
  797. return GetProfileLong("TotalCopies", 0);
  798. }
  799. void CGetSetOptions::SetTotalPasteCount(long lVal)
  800. {
  801. // negative means a relative offset
  802. if(lVal < 0)
  803. lVal = GetTotalPasteCount() - lVal; // add the absolute value
  804. if(GetTotalDate() == 0)
  805. SetTotalDate(-1);
  806. SetProfileLong("TotalPastes", lVal);
  807. }
  808. long CGetSetOptions::GetTotalPasteCount()
  809. {
  810. return GetProfileLong("TotalPastes", 0);
  811. }
  812. void CGetSetOptions::SetTotalDate(long lDate)
  813. {
  814. if(lDate == -1)
  815. lDate = (long)CTime::GetCurrentTime().GetTime();
  816. SetProfileLong("TotalDate", lDate);
  817. }
  818. long CGetSetOptions::GetTotalDate()
  819. {
  820. return GetProfileLong("TotalDate", 0);
  821. }
  822. void CGetSetOptions::SetCompactAndRepairOnExit(BOOL bVal)
  823. {
  824. SetProfileLong("CompactAndRepairOnExit", bVal);
  825. }
  826. BOOL CGetSetOptions::GetCompactAndRepairOnExit()
  827. {
  828. return GetProfileLong("CompactAndRepairOnExit", 0);
  829. }
  830. // the implementations for the following functions were moved out-of-line.
  831. // when they were declared inline, the compiler failed to notice when
  832. // these functions were changed (the linker used an old compiled version)
  833. // (maybe because they are also static?)
  834. CString CGetSetOptions::GetUpdateFilePath() { return GetProfileString("UpdateFilePath", ""); }
  835. BOOL CGetSetOptions::SetUpdateFilePath(CString cs) { return SetProfileString("UpdateFilePath", cs); }
  836. CString CGetSetOptions::GetUpdateInstallPath() { return GetProfileString("UpdateInstallPath", ""); }
  837. BOOL CGetSetOptions::SetUpdateInstallPath(CString cs) { return SetProfileString("UpdateInstallPath", cs); }
  838. long CGetSetOptions::GetLastUpdate() { return GetProfileLong("LastUpdateDay", 0); }
  839. long CGetSetOptions::SetLastUpdate(long lValue) { return SetProfileLong("LastUpdateDay", lValue); }
  840. BOOL CGetSetOptions::GetCheckForUpdates() { return GetProfileLong("CheckForUpdates", TRUE); }
  841. BOOL CGetSetOptions::SetCheckForUpdates(BOOL bCheck) { return SetProfileLong("CheckForUpdates", bCheck); }
  842. void CGetSetOptions::SetUseCtrlNumForFirstTenHotKeys(BOOL bVal) { SetProfileLong("UseCtrlNumForFirstTenHotKeys", bVal); m_bUseCtrlNumAccel = bVal; }
  843. BOOL CGetSetOptions::GetUseCtrlNumForFirstTenHotKeys() { return GetProfileLong("UseCtrlNumForFirstTenHotKeys", 0); }
  844. void CGetSetOptions::SetAllowDuplicates(BOOL bVal) { SetProfileLong("AllowDuplicates", bVal); m_bAllowDuplicates = bVal; }
  845. BOOL CGetSetOptions::GetAllowDuplicates() { return GetProfileLong("AllowDuplicates", 0); }
  846. void CGetSetOptions::SetUpdateTimeOnPaste(BOOL bVal) { SetProfileLong("UpdateTimeOnPaste", bVal); m_bUpdateTimeOnPaste = bVal; }
  847. BOOL CGetSetOptions::GetUpdateTimeOnPaste() { return GetProfileLong("UpdateTimeOnPaste", TRUE); }
  848. void CGetSetOptions::SetSaveMultiPaste(BOOL bVal) { SetProfileLong("SaveMultiPaste", bVal); m_bSaveMultiPaste = bVal; }
  849. BOOL CGetSetOptions::GetSaveMultiPaste() { return GetProfileLong("SaveMultiPaste", 0); }
  850. void CGetSetOptions::SetShowPersistent(BOOL bVal) { SetProfileLong("ShowPersistent", bVal); m_bShowPersistent = bVal; }
  851. BOOL CGetSetOptions::GetShowPersistent() { return GetProfileLong("ShowPersistent", 0); }
  852. void CGetSetOptions::SetHistoryStartTop(BOOL bVal) { SetProfileLong("HistoryStartTop", bVal); m_bHistoryStartTop = bVal; }
  853. BOOL CGetSetOptions::GetHistoryStartTop() { return GetProfileLong("HistoryStartTop", TRUE); }
  854. void CGetSetOptions::SetShowTextForFirstTenHotKeys(BOOL bVal) { SetProfileLong("ShowTextForFirstTenHotKeys", bVal); }
  855. BOOL CGetSetOptions::GetShowTextForFirstTenHotKeys() { return GetProfileLong("ShowTextForFirstTenHotKeys", TRUE); }
  856. void CGetSetOptions::SetMainHWND(long lhWnd) { SetProfileLong("MainhWnd", lhWnd); }
  857. BOOL CGetSetOptions::GetMainHWND() { return GetProfileLong("MainhWnd", 0); }
  858. void CGetSetOptions::SetCaptionPos(long lPos) { SetProfileLong("CaptionPos", lPos); }
  859. long CGetSetOptions::GetCaptionPos() { return GetProfileLong("CaptionPos", CAPTION_RIGHT); }
  860. void CGetSetOptions::SetAutoHide(BOOL bAutoHide){ SetProfileLong("AutoHide", bAutoHide); }
  861. BOOL CGetSetOptions::GetAutoHide() { return GetProfileLong("AutoHide", FALSE); }
  862. void CGetSetOptions::SetDescTextSize(long lSize){ SetProfileLong("DescTextSize", lSize); m_bDescTextSize = lSize; }
  863. long CGetSetOptions::GetDescTextSize() { return GetProfileLong("DescTextSize", 500); }
  864. void CGetSetOptions::SetDescShowLeadingWhiteSpace(BOOL bVal){ SetProfileLong("DescShowLeadingWhiteSpace", bVal); m_bDescShowLeadingWhiteSpace = bVal; }
  865. BOOL CGetSetOptions::GetDescShowLeadingWhiteSpace() { return GetProfileLong("DescShowLeadingWhiteSpace", FALSE); }
  866. void CGetSetOptions::SetAllwaysShowDescription(long bShow) { SetProfileLong("AllwaysShowDescription", bShow); m_bAllwaysShowDescription = bShow; }
  867. BOOL CGetSetOptions::GetAllwaysShowDescription() { return GetProfileLong("AllwaysShowDescription", FALSE); }
  868. void CGetSetOptions::SetDoubleClickingOnCaptionDoes(long lOption) { SetProfileLong("DoubleClickingOnCaptionDoes", lOption); m_bDoubleClickingOnCaptionDoes = lOption; }
  869. long CGetSetOptions::GetDoubleClickingOnCaptionDoes() { return GetProfileLong("DoubleClickingOnCaptionDoes", TOGGLES_ALLWAYS_ON_TOP); }
  870. void CGetSetOptions::SetPrompForNewGroupName(BOOL bOption) { SetProfileLong("PrompForNewGroupName", bOption); m_bPrompForNewGroupName = bOption; }
  871. BOOL CGetSetOptions::GetPrompForNewGroupName() { return GetProfileLong("PrompForNewGroupName", TRUE); }
  872. void CGetSetOptions::SetSendPasteOnFirstTenHotKeys(BOOL bOption) { SetProfileLong("SendPasteOnFirstTenHotKeys", bOption); m_bSendPasteOnFirstTenHotKeys = bOption; }
  873. BOOL CGetSetOptions::GetSendPasteOnFirstTenHotKeys() { return GetProfileLong("SendPasteOnFirstTenHotKeys", TRUE); }
  874. void CGetSetOptions::SetSendClients(CSendClients Client, int nPos)
  875. {
  876. CString cs;
  877. cs.Format("sendclient_ip_%d", nPos);
  878. SetProfileString(cs, Client.csIP);
  879. cs.Format("sendclient_autosend_%d", nPos);
  880. SetProfileLong(cs, Client.bSendAll);
  881. cs.Format("sendclient_description_%d", nPos);
  882. SetProfileString(cs, Client.csDescription);
  883. m_SendClients[nPos] = Client;
  884. }
  885. CSendClients CGetSetOptions::GetSendClients(int nPos)
  886. {
  887. CSendClients Client;
  888. CString cs;
  889. cs.Format("sendclient_ip_%d", nPos);
  890. Client.csIP = GetProfileString(cs, "");
  891. cs.Format("sendclient_autosend_%d", nPos);
  892. Client.bSendAll = GetProfileLong(cs, FALSE);
  893. cs.Format("sendclient_description_%d", nPos);
  894. Client.csDescription = GetProfileString(cs, "");
  895. m_SendClients[nPos] = Client;
  896. return Client;
  897. }
  898. void CGetSetOptions::GetClientSendCount()
  899. {
  900. m_lAutoSendClientCount = 0;
  901. for(int i = 0; i < MAX_SEND_CLIENTS; i++)
  902. {
  903. if(m_SendClients[i].csIP.GetLength() > 0)
  904. {
  905. if(m_SendClients[i].bSendAll)
  906. m_lAutoSendClientCount++;
  907. }
  908. }
  909. }
  910. CString CGetSetOptions::GetListToPutOnClipboard()
  911. {
  912. CString cs = GetProfileString("ListToPutOnClipboard", "");
  913. cs.MakeUpper();
  914. return cs;
  915. }
  916. BOOL CGetSetOptions::SetListToPutOnClipboard(CString cs)
  917. {
  918. cs.MakeUpper();
  919. m_csIPListToPutOnClipboard = cs;
  920. return SetProfileString("ListToPutOnClipboard", cs);
  921. }
  922. void CGetSetOptions::SetLogSendReceiveErrors(BOOL bOption)
  923. {
  924. m_bLogSendReceiveErrors = bOption;
  925. SetProfileLong("LogSendReceiveErrors", bOption);
  926. }
  927. BOOL CGetSetOptions::GetLogSendReceiveErrors()
  928. {
  929. return GetProfileLong("LogSendReceiveErrors", FALSE);
  930. }
  931. BOOL CGetSetOptions::GetHideDittoOnHotKeyIfAlreadyShown()
  932. {
  933. return GetProfileLong("HideDittoOnHotKeyIfAlreadyShown", TRUE);
  934. }
  935. void CGetSetOptions::SetHideDittoOnHotKeyIfAlreadyShown(BOOL bVal)
  936. {
  937. m_HideDittoOnHotKeyIfAlreadyShown = bVal;
  938. SetProfileLong("HideDittoOnHotKeyIfAlreadyShown", bVal);
  939. }
  940. void CGetSetOptions::SetPort(long lPort)
  941. {
  942. m_lPort = lPort;
  943. SetProfileLong("SendRecvPort", lPort);
  944. }
  945. long CGetSetOptions::GetPort()
  946. {
  947. return GetProfileLong("SendRecvPort", 23443);
  948. }
  949. BOOL CGetSetOptions::GetDisableRecieve()
  950. {
  951. return GetProfileLong("DisableRecieve", FALSE);
  952. }
  953. void CGetSetOptions::SetDisableRecieve(BOOL bVal)
  954. {
  955. SetProfileLong("DisableRecieve", bVal);
  956. }
  957. BOOL CGetSetOptions::GetFont(LOGFONT &font)
  958. {
  959. DWORD dwLength;
  960. LPVOID lpVoid = GetProfileData("DisplayFont", dwLength);
  961. if(lpVoid)
  962. {
  963. memcpy(&font, lpVoid, dwLength);
  964. return TRUE;
  965. }
  966. return FALSE;
  967. }
  968. void CGetSetOptions::SetFont(LOGFONT &font)
  969. {
  970. SetProfileData("DisplayFont", &font, sizeof(LOGFONT));
  971. }
  972. void CGetSetOptions::SetDrawThumbnail(long bDraw)
  973. {
  974. SetProfileLong("DrawThumbnail", bDraw);
  975. m_bDrawThumbnail = bDraw;
  976. }
  977. BOOL CGetSetOptions::GetDrawThumbnail()
  978. {
  979. return GetProfileLong("DrawThumbnail", TRUE);
  980. }
  981. void CGetSetOptions::SetNetworkPassword(CString csPassword)
  982. {
  983. m_csPassword = csPassword;
  984. UCHAR *pData = NULL;
  985. int nLength = 0;
  986. if(EncryptString(csPassword, pData, nLength))
  987. {
  988. SetProfileData("NetworkPassword", pData, nLength);
  989. }
  990. else
  991. {
  992. SetProfileData("NetworkPassword", NULL, 0);
  993. }
  994. DELETE_PTR(pData);
  995. }
  996. CString CGetSetOptions::GetNetworkPassword()
  997. {
  998. CString cs = "";
  999. DWORD dwLength = 0;
  1000. LPVOID lpVoid = GetProfileData("NetworkPassword", dwLength);
  1001. if(lpVoid)
  1002. {
  1003. UCHAR *pData = NULL;
  1004. int nLength = 0;
  1005. if(DecryptString((UCHAR *)lpVoid, dwLength, pData, nLength))
  1006. cs = pData;
  1007. DELETE_PTR(pData);
  1008. DELETE_PTR(lpVoid);
  1009. }
  1010. if(cs == "")
  1011. cs = "LetMeIn";
  1012. return cs;
  1013. }
  1014. void CGetSetOptions::SetDrawRTF(long bDraw)
  1015. {
  1016. SetProfileLong("DrawRTF", bDraw);
  1017. m_bDrawRTF = bDraw;
  1018. }
  1019. BOOL CGetSetOptions::GetDrawRTF()
  1020. {
  1021. return GetProfileLong("DrawRTF", FALSE);
  1022. }
  1023. void CGetSetOptions::SetMultiPasteReverse(bool bVal)
  1024. {
  1025. SetProfileLong("MultiPasteReverse", bVal);
  1026. m_bMultiPasteReverse = bVal;
  1027. }
  1028. BOOL CGetSetOptions::GetMultiPasteReverse()
  1029. {
  1030. return GetProfileLong("MultiPasteReverse", TRUE);
  1031. }
  1032. void CGetSetOptions::SetPlaySoundOnCopy(CString cs)
  1033. {
  1034. m_csPlaySoundOnCopy = cs;
  1035. SetProfileString("PlaySoundOnCopy", cs);
  1036. }
  1037. CString CGetSetOptions::GetPlaySoundOnCopy()
  1038. {
  1039. return GetProfileString("PlaySoundOnCopy", "");
  1040. }
  1041. void CGetSetOptions::SetSendPasteAfterSelection(BOOL bVal)
  1042. {
  1043. m_bSendPasteMessageAfterSelection = bVal;
  1044. SetProfileLong("SendPasteMessageAfterSelection", bVal);
  1045. }
  1046. BOOL CGetSetOptions::GetSendPasteAfterSelection()
  1047. {
  1048. return GetProfileLong("SendPasteMessageAfterSelection", TRUE);
  1049. }
  1050. void CGetSetOptions::SetFindAsYouType(BOOL bVal)
  1051. {
  1052. m_bFindAsYouType = bVal;
  1053. SetProfileLong("FindAsYouType", bVal);
  1054. }
  1055. BOOL CGetSetOptions::GetFindAsYouType()
  1056. {
  1057. return GetProfileLong("FindAsYouType", TRUE);
  1058. }
  1059. void CGetSetOptions::SetEnsureEntireWindowCanBeSeen(BOOL bVal)
  1060. {
  1061. m_bEnsureEntireWindowCanBeSeen = bVal;
  1062. SetProfileLong("EnsureEntireWindowCanBeSeen", bVal);
  1063. }
  1064. BOOL CGetSetOptions::GetEnsureEntireWindowCanBeSeen()
  1065. {
  1066. return GetProfileLong("EnsureEntireWindowCanBeSeen", TRUE);
  1067. }
  1068. void CGetSetOptions::SetShowAllClipsInMainList(BOOL bVal)
  1069. {
  1070. m_bShowAllClipsInMainList = bVal;
  1071. SetProfileLong("ShowAllClipsInMainList", bVal);
  1072. }
  1073. BOOL CGetSetOptions::GetShowAllClipsInMainList()
  1074. {
  1075. return GetProfileLong("ShowAllClipsInMainList", TRUE);
  1076. }
  1077. /*------------------------------------------------------------------*\
  1078. CHotKey - a single system-wide hotkey
  1079. \*------------------------------------------------------------------*/
  1080. CHotKey::CHotKey( CString name, DWORD defKey, bool bUnregOnShowDitto )
  1081. : m_Name(name), m_bIsRegistered(false), m_bUnRegisterOnShowDitto(bUnregOnShowDitto)
  1082. {
  1083. m_Atom = ::GlobalAddAtom( m_Name );
  1084. ASSERT( m_Atom );
  1085. m_Key = (DWORD) g_Opt.GetProfileLong( m_Name, (long) defKey );
  1086. g_HotKeys.Add( this );
  1087. }
  1088. CHotKey::~CHotKey()
  1089. {
  1090. Unregister();
  1091. }
  1092. void CHotKey::SetKey( DWORD key, bool bSave )
  1093. {
  1094. if( m_Key == key )
  1095. return;
  1096. if( m_bIsRegistered )
  1097. Unregister();
  1098. m_Key = key;
  1099. if( bSave )
  1100. SaveKey();
  1101. }
  1102. void CHotKey::LoadKey()
  1103. {
  1104. SetKey( (DWORD) g_Opt.GetProfileLong( m_Name, 0 ) );
  1105. }
  1106. bool CHotKey::SaveKey()
  1107. {
  1108. return g_Opt.SetProfileLong( m_Name, (long) m_Key ) != FALSE;
  1109. }
  1110. // CString GetKeyAsText();
  1111. // void SetKeyFromText( CString text );
  1112. BOOL CHotKey::ValidateHotKey(DWORD dwHotKey)
  1113. {
  1114. ATOM id = ::GlobalAddAtom("HK_VALIDATE");
  1115. BOOL bResult = ::RegisterHotKey( g_HotKeys.m_hWnd,
  1116. id,
  1117. GetModifier(dwHotKey),
  1118. LOBYTE(dwHotKey) );
  1119. if(bResult)
  1120. ::UnregisterHotKey(g_HotKeys.m_hWnd, id);
  1121. ::GlobalDeleteAtom(id);
  1122. return bResult;
  1123. }
  1124. void CHotKey::CopyFromCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID)
  1125. {
  1126. long lHotKey = ctrl.GetHotKey();
  1127. short sKeyKode = LOBYTE(lHotKey);
  1128. short sModifers = HIBYTE(lHotKey);
  1129. if(lHotKey && ::IsDlgButtonChecked(hParent, nWindowsCBID))
  1130. {
  1131. sModifers |= HOTKEYF_EXT;
  1132. }
  1133. SetKey(MAKEWORD(sKeyKode, sModifers));
  1134. }
  1135. void CHotKey::CopyToCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID)
  1136. {
  1137. long lModifiers = HIBYTE(m_Key);
  1138. ctrl.SetHotKey(LOBYTE(m_Key), lModifiers);
  1139. if(lModifiers & HOTKEYF_EXT)
  1140. {
  1141. ::CheckDlgButton(hParent, nWindowsCBID, BST_CHECKED);
  1142. }
  1143. }
  1144. UINT CHotKey::GetModifier(DWORD dwHotKey)
  1145. {
  1146. UINT uMod = 0;
  1147. if( HIBYTE(dwHotKey) & HOTKEYF_SHIFT ) uMod |= MOD_SHIFT;
  1148. if( HIBYTE(dwHotKey) & HOTKEYF_CONTROL ) uMod |= MOD_CONTROL;
  1149. if( HIBYTE(dwHotKey) & HOTKEYF_ALT ) uMod |= MOD_ALT;
  1150. if( HIBYTE(dwHotKey) & HOTKEYF_EXT ) uMod |= MOD_WIN;
  1151. return uMod;
  1152. }
  1153. bool CHotKey::Register()
  1154. {
  1155. if( m_Key )
  1156. {
  1157. if(m_bIsRegistered == false)
  1158. {
  1159. ASSERT( g_HotKeys.m_hWnd );
  1160. m_bIsRegistered = ::RegisterHotKey( g_HotKeys.m_hWnd,
  1161. m_Atom,
  1162. GetModifier(),
  1163. LOBYTE(m_Key) ) == TRUE;
  1164. }
  1165. }
  1166. else
  1167. m_bIsRegistered = true;
  1168. return m_bIsRegistered;
  1169. }
  1170. bool CHotKey::Unregister(bool bOnShowingDitto)
  1171. {
  1172. if( !m_bIsRegistered )
  1173. return true;
  1174. if(bOnShowingDitto)
  1175. {
  1176. if(m_bUnRegisterOnShowDitto == false)
  1177. return true;
  1178. }
  1179. if(m_Key)
  1180. {
  1181. ASSERT(g_HotKeys.m_hWnd);
  1182. if( ::UnregisterHotKey( g_HotKeys.m_hWnd, m_Atom ) )
  1183. {
  1184. m_bIsRegistered = false;
  1185. return true;
  1186. }
  1187. else
  1188. {
  1189. LOG("Unregister" "FAILED!");
  1190. ASSERT(0);
  1191. }
  1192. }
  1193. else
  1194. {
  1195. m_bIsRegistered = false;
  1196. return true;
  1197. }
  1198. return false;
  1199. }
  1200. /*------------------------------------------------------------------*\
  1201. CHotKeys - Manages system-wide hotkeys
  1202. \*------------------------------------------------------------------*/
  1203. CHotKeys g_HotKeys;
  1204. CHotKeys::CHotKeys() : m_hWnd(NULL) {}
  1205. CHotKeys::~CHotKeys()
  1206. {
  1207. CHotKey* pHotKey;
  1208. int count = GetSize();
  1209. for( int i=0; i < count; i++ )
  1210. {
  1211. pHotKey = ElementAt(i);
  1212. if( pHotKey )
  1213. delete pHotKey;
  1214. }
  1215. }
  1216. int CHotKeys::Find( CHotKey* pHotKey )
  1217. {
  1218. int count = GetSize();
  1219. for( int i=0; i < count; i++ )
  1220. {
  1221. if( pHotKey == ElementAt(i) )
  1222. return i;
  1223. }
  1224. return -1;
  1225. }
  1226. bool CHotKeys::Remove( CHotKey* pHotKey )
  1227. {
  1228. int i = Find(pHotKey);
  1229. if( i >= 0 )
  1230. {
  1231. RemoveAt(i);
  1232. return true;
  1233. }
  1234. return false;
  1235. }
  1236. void CHotKeys::LoadAllKeys()
  1237. {
  1238. int count = GetSize();
  1239. for( int i=0; i < count; i++ )
  1240. ElementAt(i)->LoadKey();
  1241. }
  1242. void CHotKeys::SaveAllKeys()
  1243. {
  1244. int count = GetSize();
  1245. for( int i=0; i < count; i++ )
  1246. ElementAt(i)->SaveKey();
  1247. }
  1248. void CHotKeys::RegisterAll( bool bMsgOnError )
  1249. {
  1250. CString str;
  1251. CHotKey* pHotKey;
  1252. int count = GetSize();
  1253. for( int i=0; i < count; i++ )
  1254. {
  1255. pHotKey = ElementAt(i);
  1256. if( !pHotKey->Register() )
  1257. {
  1258. str = "Error Registering ";
  1259. str += pHotKey->GetName();
  1260. LOG( str );
  1261. if( bMsgOnError )
  1262. AfxMessageBox(str);
  1263. }
  1264. }
  1265. }
  1266. void CHotKeys::UnregisterAll(bool bMsgOnError, bool bOnShowDitto)
  1267. {
  1268. CString str;
  1269. CHotKey* pHotKey;
  1270. int count = GetSize();
  1271. for( int i=0; i < count; i++ )
  1272. {
  1273. pHotKey = ElementAt(i);
  1274. if(!pHotKey->Unregister(bOnShowDitto))
  1275. {
  1276. str = "Error Unregistering ";
  1277. str += pHotKey->GetName();
  1278. LOG( str );
  1279. if( bMsgOnError )
  1280. AfxMessageBox(str);
  1281. }
  1282. }
  1283. }
  1284. void CHotKeys::GetKeys( ARRAY& keys )
  1285. {
  1286. int count = GetSize();
  1287. keys.SetSize( count );
  1288. for( int i=0; i < count; i++ )
  1289. keys[i] = ElementAt(i)->GetKey();
  1290. }
  1291. // caution! this alters hotkeys based upon corresponding indexes
  1292. void CHotKeys::SetKeys( ARRAY& keys, bool bSave )
  1293. {
  1294. int count = GetSize();
  1295. ASSERT( count == keys.GetSize() );
  1296. for( int i=0; i < count; i++ )
  1297. ElementAt(i)->SetKey( keys[i], bSave );
  1298. }
  1299. bool CHotKeys::FindFirstConflict( ARRAY& keys, int* pX, int* pY )
  1300. {
  1301. bool bConflict = false;
  1302. int i, j;
  1303. int count = keys.GetSize();
  1304. DWORD key;
  1305. for( i=0; i < count && !bConflict; i++ )
  1306. {
  1307. key = keys.ElementAt(i);
  1308. // only check valid keys
  1309. if( key == 0 )
  1310. continue;
  1311. // scan the array for a duplicate
  1312. for( j=i+1; j < count; j++ )
  1313. {
  1314. if( keys.ElementAt(j) == key )
  1315. {
  1316. bConflict = true;
  1317. break;
  1318. }
  1319. }
  1320. }
  1321. if( bConflict )
  1322. {
  1323. if( pX )
  1324. *pX = i-1;
  1325. if( pY )
  1326. *pY = j;
  1327. }
  1328. return bConflict;
  1329. }
  1330. // if true, pX and pY (if valid) are set to the indexes of the conflicting hotkeys.
  1331. bool CHotKeys::FindFirstConflict( int* pX, int* pY )
  1332. {
  1333. ARRAY keys;
  1334. GetKeys( keys );
  1335. return FindFirstConflict( keys, pX, pY );
  1336. }
  1337. /****************************************************************************************************
  1338. BOOL CALLBACK MyMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
  1339. ***************************************************************************************************/
  1340. typedef struct
  1341. {
  1342. long lFlags; // Flags
  1343. LPRECT pVirtualRect; // Ptr to rect that receives the results, or the src of the monitor search method
  1344. int iMonitor; // Ndx to the mointor to look at, -1 for all, -or- result of the monitor search method
  1345. int nMonitorCount; // Total number of monitors found, -1 for monitor search method
  1346. } MONITOR_ENUM_PARAM;
  1347. #define MONITOR_SEARCH_METOHD 0x00000001
  1348. BOOL CALLBACK MyMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
  1349. {
  1350. // Typecast param
  1351. MONITOR_ENUM_PARAM* pParam = (MONITOR_ENUM_PARAM*)dwData;
  1352. if(pParam)
  1353. {
  1354. // If a dest rect was passed
  1355. if(pParam->pVirtualRect)
  1356. {
  1357. // If MONITOR_SEARCH_METOHD then we are being asked for the index of the monitor
  1358. // that the rect falls inside of
  1359. if(pParam->lFlags & MONITOR_SEARCH_METOHD)
  1360. {
  1361. if( (pParam->pVirtualRect->right < lprcMonitor->left) ||
  1362. (pParam->pVirtualRect->left > lprcMonitor->right) ||
  1363. (pParam->pVirtualRect->bottom < lprcMonitor->top) ||
  1364. (pParam->pVirtualRect->top > lprcMonitor->bottom))
  1365. {
  1366. // Nothing
  1367. }
  1368. else
  1369. {
  1370. // This is the one
  1371. pParam->iMonitor = pParam->nMonitorCount;
  1372. // Stop the enumeration
  1373. return FALSE;
  1374. }
  1375. }
  1376. else
  1377. {
  1378. if(pParam->iMonitor == pParam->nMonitorCount)
  1379. {
  1380. *pParam->pVirtualRect = *lprcMonitor;
  1381. }
  1382. else
  1383. if(pParam->iMonitor == -1)
  1384. {
  1385. pParam->pVirtualRect->left = min(pParam->pVirtualRect->left, lprcMonitor->left);
  1386. pParam->pVirtualRect->top = min(pParam->pVirtualRect->top, lprcMonitor->top);
  1387. pParam->pVirtualRect->right = max(pParam->pVirtualRect->right, lprcMonitor->right);
  1388. pParam->pVirtualRect->bottom = max(pParam->pVirtualRect->bottom, lprcMonitor->bottom);
  1389. }
  1390. }
  1391. }
  1392. // Up the count if necessary
  1393. pParam->nMonitorCount++;
  1394. }
  1395. return TRUE;
  1396. }
  1397. int GetScreenWidth(void)
  1398. {
  1399. OSVERSIONINFO OS_Version_Info;
  1400. DWORD dwPlatform = 0;
  1401. if(GetVersionEx(&OS_Version_Info) != 0)
  1402. {
  1403. dwPlatform = OS_Version_Info.dwPlatformId;
  1404. }
  1405. if(dwPlatform == VER_PLATFORM_WIN32_NT)
  1406. {
  1407. int width, height;
  1408. width = GetSystemMetrics(SM_CXSCREEN);
  1409. height = GetSystemMetrics(SM_CYSCREEN);
  1410. switch(width)
  1411. {
  1412. default:
  1413. case 640:
  1414. case 800:
  1415. case 1024:
  1416. return(width);
  1417. case 1280:
  1418. if(height == 480)
  1419. {
  1420. return(width / 2);
  1421. }
  1422. return(width);
  1423. case 1600:
  1424. if(height == 600)
  1425. {
  1426. return(width / 2);
  1427. }
  1428. return(width);
  1429. case 2048:
  1430. if(height == 768)
  1431. {
  1432. return(width / 2);
  1433. }
  1434. return(width);
  1435. }
  1436. }
  1437. else
  1438. {
  1439. return(GetSystemMetrics(SM_CXSCREEN));
  1440. }
  1441. }
  1442. int GetScreenHeight(void)
  1443. {
  1444. OSVERSIONINFO OS_Version_Info;
  1445. DWORD dwPlatform = 0;
  1446. if(GetVersionEx(&OS_Version_Info) != 0)
  1447. {
  1448. dwPlatform = OS_Version_Info.dwPlatformId;
  1449. }
  1450. if(dwPlatform == VER_PLATFORM_WIN32_NT)
  1451. {
  1452. int width, height;
  1453. width = GetSystemMetrics(SM_CXSCREEN);
  1454. height = GetSystemMetrics(SM_CYSCREEN);
  1455. switch(height)
  1456. {
  1457. default:
  1458. case 480:
  1459. case 600:
  1460. case 768:
  1461. return(height);
  1462. case 960:
  1463. if(width == 640)
  1464. {
  1465. return(height / 2);
  1466. }
  1467. return(height);
  1468. case 1200:
  1469. if(width == 800)
  1470. {
  1471. return(height / 2);
  1472. }
  1473. return(height);
  1474. case 1536:
  1475. if(width == 1024)
  1476. {
  1477. return(height / 2);
  1478. }
  1479. return(height);
  1480. }
  1481. }
  1482. else
  1483. {
  1484. return(GetSystemMetrics(SM_CYSCREEN));
  1485. }
  1486. }
  1487. int GetMonitorFromRect(LPRECT lpMonitorRect)
  1488. {
  1489. // Build up the param
  1490. MONITOR_ENUM_PARAM EnumParam;
  1491. ZeroMemory(&EnumParam, sizeof(EnumParam));
  1492. EnumParam.lFlags = MONITOR_SEARCH_METOHD;
  1493. EnumParam.pVirtualRect = lpMonitorRect;
  1494. EnumParam.iMonitor = -1;
  1495. // Enum Displays
  1496. EnumDisplayMonitors(NULL, NULL, MyMonitorEnumProc, (long)&EnumParam);
  1497. // Return the result
  1498. return EnumParam.iMonitor;
  1499. }
  1500. void GetMonitorRect(int iMonitor, LPRECT lpDestRect)
  1501. {
  1502. // Build up the param
  1503. MONITOR_ENUM_PARAM EnumParam;
  1504. ZeroMemory(&EnumParam, sizeof(EnumParam));
  1505. EnumParam.iMonitor = iMonitor;
  1506. EnumParam.pVirtualRect = lpDestRect;
  1507. // Zero out dest rect
  1508. lpDestRect->bottom = lpDestRect->left = lpDestRect->right = lpDestRect->top = 0;
  1509. // Enum Displays
  1510. EnumDisplayMonitors(NULL, NULL, MyMonitorEnumProc, (long)&EnumParam);
  1511. // If not successful, default to the screen dimentions
  1512. if(lpDestRect->right == 0 || lpDestRect->bottom == 0)
  1513. {
  1514. lpDestRect->right = GetScreenWidth();
  1515. lpDestRect->bottom = GetScreenHeight();
  1516. }
  1517. }
  1518. /*------------------------------------------------------------------*\
  1519. CAccel - an Accelerator (in-app hotkey)
  1520. - the win32 CreateAcceleratorTable using ACCEL was insufficient
  1521. because it only allowed a WORD for the cmd associated with it.
  1522. \*------------------------------------------------------------------*/
  1523. /*------------------------------------------------------------------*\
  1524. CAccels - Manages a set of CAccel
  1525. \*------------------------------------------------------------------*/
  1526. int CompareAccel( const void* pLeft, const void* pRight )
  1527. {
  1528. WORD w;
  1529. int l,r;
  1530. // swap bytes: place the VirtualKey in the MSB and the modifier in the LSB
  1531. // so that Accels based upon the same vkey are grouped together.
  1532. // this is required by our use of m_Index
  1533. // alternatively, we could store them this way in CAccel.
  1534. w = (WORD) ((CAccel*)pLeft)->Key;
  1535. l = (ACCEL_VKEY(w) << 8) | ACCEL_MOD(w);
  1536. w = (WORD) ((CAccel*)pRight)->Key;
  1537. r = (ACCEL_VKEY(w) << 8) | ACCEL_MOD(w);
  1538. return l - r;
  1539. }
  1540. CAccels::CAccels()
  1541. {}
  1542. void CAccels::AddAccel( CAccel& a )
  1543. {
  1544. m_Map.SetAt(a.Key, a.Cmd);
  1545. }
  1546. bool CAccels::OnMsg( MSG* pMsg, DWORD &dID)
  1547. {
  1548. // bit 30 (0x40000000) is 1 if this is NOT the first msg of the key
  1549. // i.e. auto-repeat may cause multiple msgs of the same key
  1550. if( (pMsg->lParam & 0x40000000) ||
  1551. (pMsg->message != WM_KEYDOWN &&
  1552. pMsg->message != WM_SYSKEYDOWN) )
  1553. {
  1554. return NULL;
  1555. }
  1556. if( !pMsg || m_Map.GetCount() <= 0 )
  1557. return NULL;
  1558. BYTE vkey = LOBYTE(pMsg->wParam);
  1559. BYTE mod = GetKeyStateModifiers();
  1560. DWORD key = ACCEL_MAKEKEY( vkey, mod );
  1561. if(m_Map.Lookup(key, dID))
  1562. return true;;
  1563. return false;
  1564. }
  1565. BYTE GetKeyStateModifiers()
  1566. {
  1567. BYTE m=0;
  1568. if( GetKeyState(VK_SHIFT) & 0x8000 )
  1569. m |= HOTKEYF_SHIFT;
  1570. if( GetKeyState(VK_CONTROL) & 0x8000 )
  1571. m |= HOTKEYF_CONTROL;
  1572. if( GetKeyState(VK_MENU) & 0x8000 )
  1573. m |= HOTKEYF_ALT;
  1574. return m;
  1575. }
  1576. /*------------------------------------------------------------------*\
  1577. CTokenizer - Tokenizes a string using given delimiters
  1578. \*------------------------------------------------------------------*/
  1579. CTokenizer::CTokenizer(const CString& cs, const CString& csDelim):
  1580. m_cs(cs),
  1581. m_nCurPos(0)
  1582. {
  1583. SetDelimiters(csDelim);
  1584. }
  1585. void CTokenizer::SetDelimiters(const CString& csDelim)
  1586. {
  1587. for(int i = 0; i < csDelim.GetLength(); ++i)
  1588. m_delim.set(static_cast<BYTE>(csDelim[i]));
  1589. }
  1590. bool CTokenizer::Next(CString& cs)
  1591. {
  1592. int len = m_cs.GetLength();
  1593. cs.Empty();
  1594. while(m_nCurPos < len && m_delim[static_cast<BYTE>(m_cs[m_nCurPos])])
  1595. ++m_nCurPos;
  1596. if(m_nCurPos >= len)
  1597. return false;
  1598. int nStartPos = m_nCurPos;
  1599. while(m_nCurPos < len && !m_delim[static_cast<BYTE>(m_cs[m_nCurPos])])
  1600. ++m_nCurPos;
  1601. cs = m_cs.Mid(nStartPos, m_nCurPos - nStartPos);
  1602. return true;
  1603. }
  1604. CString CTokenizer::Tail() const
  1605. {
  1606. int len = m_cs.GetLength();
  1607. int nCurPos = m_nCurPos;
  1608. while(nCurPos < len && m_delim[static_cast<BYTE>(m_cs[nCurPos])])
  1609. ++nCurPos;
  1610. CString csResult;
  1611. if(nCurPos < len)
  1612. csResult = m_cs.Mid(nCurPos);
  1613. return csResult;
  1614. }
  1615. /*------------------------------------------------------------------*\
  1616. Global ToolTip Manual Control Functions
  1617. \*------------------------------------------------------------------*/
  1618. void InitToolInfo( TOOLINFO& ti )
  1619. {
  1620. // INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE
  1621. ti.cbSize = sizeof(TOOLINFO);
  1622. ti.uFlags = TTF_ABSOLUTE | TTF_TRACK;
  1623. ti.hwnd = NULL;
  1624. ti.hinst = NULL;
  1625. ti.uId = 0; // CPopup only uses uid 0
  1626. ti.lpszText = NULL;
  1627. // ToolTip control will cover the whole window
  1628. ti.rect.left = 0;
  1629. ti.rect.top = 0;
  1630. ti.rect.right = 0;
  1631. ti.rect.bottom = 0;
  1632. }
  1633. /*------------------------------------------------------------------*\
  1634. CPopup - a tooltip that pops up manually (when Show is called).
  1635. - technique learned from codeproject "ToolTipZen" by "Zarembo Maxim"
  1636. \*------------------------------------------------------------------*/
  1637. CPopup::CPopup()
  1638. {
  1639. Init();
  1640. }
  1641. // HWND_TOP
  1642. CPopup::CPopup( int x, int y, HWND hWndPosRelativeTo, HWND hWndInsertAfter )
  1643. {
  1644. Init();
  1645. m_hWndPosRelativeTo = hWndPosRelativeTo;
  1646. m_hWndInsertAfter = hWndInsertAfter;
  1647. SetPos( CPoint(x,y) );
  1648. }
  1649. CPopup::~CPopup()
  1650. {
  1651. Hide();
  1652. if( m_bOwnTT && ::IsWindow(m_hTTWnd) )
  1653. ::DestroyWindow( m_hTTWnd );
  1654. }
  1655. void CPopup::Init()
  1656. {
  1657. // initialize variables
  1658. m_bOwnTT = false;
  1659. m_hTTWnd = NULL;
  1660. m_bIsShowing = false;
  1661. m_bAllowShow = true; // used by AllowShow()
  1662. m_Pos.x = m_Pos.y = 0;
  1663. m_bTop = true;
  1664. m_bLeft = true;
  1665. m_bCenterX = false;
  1666. m_bCenterY = false;
  1667. m_hWndPosRelativeTo = NULL;
  1668. RECT rcScreen;
  1669. GetMonitorRect(-1, &rcScreen);
  1670. m_ScreenMaxX = rcScreen.right;
  1671. m_ScreenMaxY = rcScreen.bottom;
  1672. m_hWndInsertAfter = HWND_TOP; //HWND_TOPMOST
  1673. SetTTWnd();
  1674. }
  1675. void CPopup::SetTTWnd( HWND hTTWnd, TOOLINFO* pTI )
  1676. {
  1677. if( pTI )
  1678. m_TI = *pTI;
  1679. else
  1680. InitToolInfo( m_TI );
  1681. if( m_bOwnTT && ::IsWindow(m_hTTWnd) )
  1682. {
  1683. if( !::IsWindow(hTTWnd) )
  1684. return; // we would have to recreate the one that already exists
  1685. ::DestroyWindow( m_hTTWnd );
  1686. }
  1687. m_hTTWnd = hTTWnd;
  1688. if( ::IsWindow(m_hTTWnd) )
  1689. {
  1690. m_bOwnTT = false;
  1691. // if our uid tooltip already exists, get the data, else add it.
  1692. if( ! ::SendMessage(m_hTTWnd, TTM_GETTOOLINFO, 0, (LPARAM)(LPTOOLINFO) &m_TI) )
  1693. ::SendMessage(m_hTTWnd, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &m_TI);
  1694. }
  1695. else
  1696. {
  1697. m_bOwnTT = true;
  1698. CreateToolTip();
  1699. }
  1700. }
  1701. void CPopup::CreateToolTip()
  1702. {
  1703. if( m_hTTWnd != NULL )
  1704. return;
  1705. // CREATE A TOOLTIP WINDOW
  1706. m_hTTWnd = CreateWindowEx(
  1707. WS_EX_TOPMOST,
  1708. TOOLTIPS_CLASS,
  1709. NULL,
  1710. TTS_NOPREFIX | TTS_ALWAYSTIP,
  1711. CW_USEDEFAULT,
  1712. CW_USEDEFAULT,
  1713. CW_USEDEFAULT,
  1714. CW_USEDEFAULT,
  1715. NULL,
  1716. NULL,
  1717. NULL,
  1718. NULL
  1719. );
  1720. m_bOwnTT = true;
  1721. // SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW
  1722. ::SendMessage(m_hTTWnd, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &m_TI);
  1723. }
  1724. void CPopup::SetTimeout( int timeout )
  1725. {
  1726. if( m_hTTWnd == NULL )
  1727. return;
  1728. ::SendMessage(m_hTTWnd, TTM_SETDELAYTIME, TTDT_AUTOMATIC, timeout);
  1729. }
  1730. void CPopup::SetPos( CPoint& pos )
  1731. {
  1732. m_Pos = pos;
  1733. }
  1734. void CPopup::SetPosInfo( bool bTop, bool bCenterY, bool bLeft, bool bCenterX )
  1735. {
  1736. m_bTop = bTop;
  1737. m_bCenterY = bCenterY;
  1738. m_bLeft = bLeft;
  1739. m_bCenterX = bCenterX;
  1740. }
  1741. void CPopup::AdjustPos( CPoint& pos )
  1742. {
  1743. CRect rel(0,0,0,0);
  1744. CRect rect(0,0,0,0);
  1745. // ::SendMessage(m_hTTWnd, TTM_ADJUSTRECT, TRUE, (LPARAM)&rect);
  1746. ::GetWindowRect(m_hTTWnd,&rect);
  1747. if( ::IsWindow(m_hWndPosRelativeTo) )
  1748. ::GetWindowRect(m_hWndPosRelativeTo, &rel);
  1749. // move the rect to the relative origin
  1750. rect.bottom = rect.Height() + rel.top;
  1751. rect.top = rel.top;
  1752. rect.right = rect.Width() + rel.left;
  1753. rect.left = rel.left;
  1754. // adjust the y position
  1755. rect.OffsetRect( 0, pos.y - (m_bCenterY? rect.Height()/2: (m_bTop? 0: rect.Height())) );
  1756. if( rect.bottom > m_ScreenMaxY )
  1757. rect.OffsetRect( 0, m_ScreenMaxY - rect.bottom );
  1758. // adjust the x position
  1759. rect.OffsetRect( pos.x - (m_bCenterX? rect.Width()/2: (m_bLeft? 0: rect.Width())), 0 );
  1760. if( rect.right > m_ScreenMaxX )
  1761. rect.OffsetRect( m_ScreenMaxX - rect.right, 0 );
  1762. pos.x = rect.left;
  1763. pos.y = rect.top;
  1764. }
  1765. void CPopup::SendToolTipText( CString text )
  1766. {
  1767. m_csToolTipText = text;
  1768. //Replace the tabs with spaces, the tooltip didn't like the \t s
  1769. text.Replace("\t", " ");
  1770. m_TI.lpszText = (LPSTR) (LPCTSTR) text;
  1771. // this allows \n and \r to be interpreted correctly
  1772. ::SendMessage(m_hTTWnd, TTM_SETMAXTIPWIDTH, 0, 500);
  1773. // set the text
  1774. ::SendMessage(m_hTTWnd, TTM_SETTOOLINFO, 0, (LPARAM) (LPTOOLINFO) &m_TI);
  1775. }
  1776. void CPopup::Show( CString text, CPoint pos, bool bAdjustPos )
  1777. {
  1778. if( m_hTTWnd == NULL )
  1779. return;
  1780. m_csToolTipText = text;
  1781. if( !m_bIsShowing )
  1782. ::SendMessage(m_hTTWnd, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG(-10000,-10000));
  1783. SendToolTipText( text );
  1784. ::SendMessage(m_hTTWnd, TTM_TRACKACTIVATE, true, (LPARAM)(LPTOOLINFO) &m_TI);
  1785. if( bAdjustPos )
  1786. AdjustPos(pos);
  1787. // set the position
  1788. ::SendMessage(m_hTTWnd, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG(pos.x,pos.y));
  1789. // make sure the tooltip will be on top.
  1790. ::SetWindowPos( m_hTTWnd, m_hWndInsertAfter, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE );
  1791. m_bIsShowing = true;
  1792. }
  1793. void CPopup::Show( CString text )
  1794. {
  1795. m_csToolTipText = text;
  1796. Show( text, m_Pos );
  1797. }
  1798. void CPopup::AllowShow( CString text )
  1799. {
  1800. m_csToolTipText = text;
  1801. if( m_bAllowShow )
  1802. Show( text, m_Pos );
  1803. }
  1804. void CPopup::Hide()
  1805. {
  1806. if( m_hTTWnd == NULL )
  1807. return;
  1808. // deactivate if it is currently activated
  1809. ::SendMessage(m_hTTWnd, TTM_TRACKACTIVATE, FALSE, (LPARAM)(LPTOOLINFO) &m_TI);
  1810. m_bIsShowing = false;
  1811. }
  1812. #include "Encryption.h"
  1813. #define STRING_PASSWORD "*4ei)"
  1814. BOOL EncryptString(CString &csIn, UCHAR *&pOutput, int &nLenOutput)
  1815. {
  1816. BOOL bRet = FALSE;
  1817. CEncryption *pEncryptor;
  1818. pEncryptor = new CEncryption;
  1819. if(pEncryptor)
  1820. {
  1821. UCHAR *pData = (UCHAR*)csIn.GetBuffer(csIn.GetLength());
  1822. nLenOutput = 0;
  1823. if(pEncryptor->Encrypt(pData, csIn.GetLength(), STRING_PASSWORD, pOutput, nLenOutput))
  1824. {
  1825. bRet = TRUE;
  1826. }
  1827. delete pEncryptor;
  1828. }
  1829. return bRet;
  1830. }
  1831. BOOL DecryptString(UCHAR *pData, int nLenIn, UCHAR *&pOutput, int &nLenOutput)
  1832. {
  1833. BOOL bRet = FALSE;
  1834. CEncryption *pEncryptor;
  1835. pEncryptor = new CEncryption;
  1836. if(pEncryptor)
  1837. {
  1838. if(pEncryptor->Decrypt(pData, nLenIn, STRING_PASSWORD, pOutput, nLenOutput))
  1839. {
  1840. bRet = TRUE;
  1841. }
  1842. delete pEncryptor;
  1843. }
  1844. return bRet;
  1845. }