Misc.cpp 51 KB

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