Misc.cpp 44 KB

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