Misc.cpp 52 KB

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