Misc.cpp 52 KB

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