Misc.cpp 53 KB

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