DittoWindow.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. #include "stdafx.h"
  2. #include ".\dittowindow.h"
  3. #include "CP_Main.h"
  4. #include "Options.h"
  5. CDittoWindow::CDittoWindow(void)
  6. {
  7. m_lTopBorder = CAPTION_BORDER;
  8. m_lRightBorder = BORDER;
  9. m_lBottomBorder = BORDER;
  10. m_lLeftBorder = BORDER;
  11. m_bMouseOverChevron = false;
  12. m_bMouseDownOnChevron = false;
  13. m_bMouseDownOnClose = false;
  14. m_bMouseOverClose = false;
  15. m_bMouseDownOnCaption = false;
  16. m_bMouseDownOnMinimize = false;
  17. m_bMouseOverMinimize = false;
  18. m_bMouseDownOnMaximize = false;
  19. m_bMouseOverMaximize = false;
  20. m_bDrawClose = true;
  21. m_bDrawChevron = true;
  22. m_bDrawMaximize = true;
  23. m_bDrawMinimize = true;
  24. m_bMinimized = false;
  25. m_crCloseBT.SetRectEmpty();
  26. m_crChevronBT.SetRectEmpty();
  27. m_crMaximizeBT.SetRectEmpty();
  28. m_crMinimizeBT.SetRectEmpty();
  29. m_CaptionColorLeft = RGB(0, 84, 230);
  30. m_CaptionColorRight = RGB(61, 149, 255);
  31. m_CaptionTextColor = RGB(255, 255, 255);
  32. }
  33. CDittoWindow::~CDittoWindow(void)
  34. {
  35. }
  36. void CDittoWindow::DoCreate(CWnd *pWnd)
  37. {
  38. m_VertFont.CreateFont(14,0,-900,0,400,FALSE,FALSE,0,ANSI_CHARSET,
  39. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  40. DEFAULT_PITCH|FF_SWISS, _T("Arial"));
  41. m_HorFont.CreateFont(14,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,
  42. OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
  43. DEFAULT_PITCH|FF_SWISS, _T("Arial"));
  44. }
  45. void CDittoWindow::DoNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  46. {
  47. //Decrease the client area
  48. lpncsp->rgrc[0].left+= m_lLeftBorder;
  49. lpncsp->rgrc[0].top+= m_lTopBorder;
  50. lpncsp->rgrc[0].right-= m_lRightBorder;
  51. lpncsp->rgrc[0].bottom-= m_lBottomBorder;
  52. }
  53. UINT CDittoWindow::DoNcHitTest(CWnd *pWnd, CPoint point)
  54. {
  55. CRect crWindow;
  56. pWnd->GetWindowRect(crWindow);
  57. if(crWindow.PtInRect(point) == false)
  58. {
  59. return -1;
  60. }
  61. if(m_bMinimized == false)
  62. {
  63. if ((point.y < crWindow.top + BORDER * 2) &&
  64. (point.x < crWindow.left + BORDER * 2))
  65. return HTTOPLEFT;
  66. else if ((point.y < crWindow.top + BORDER * 2) &&
  67. (point.x > crWindow.right - BORDER * 2))
  68. return HTTOPRIGHT;
  69. else if ((point.y > crWindow.bottom - BORDER * 2) &&
  70. (point.x > crWindow.right - BORDER * 2))
  71. return HTBOTTOMRIGHT;
  72. else if ((point.y > crWindow.bottom - BORDER * 2) &&
  73. (point.x < crWindow.left + BORDER * 2))
  74. return HTBOTTOMLEFT;
  75. }
  76. if((((m_lTopBorder == CAPTION_BORDER) || (m_lBottomBorder == CAPTION_BORDER)) &&
  77. (m_bMinimized)) == false)
  78. {
  79. if (point.y < crWindow.top + BORDER * 2)
  80. return HTTOP;
  81. if (point.y > crWindow.bottom - BORDER * 2)
  82. return HTBOTTOM;
  83. }
  84. if((((m_lLeftBorder == CAPTION_BORDER) || (m_lRightBorder == CAPTION_BORDER)) &&
  85. (m_bMinimized)) == false)
  86. {
  87. if (point.x > crWindow.right - BORDER * 2)
  88. return HTRIGHT;
  89. if (point.x < crWindow.left + BORDER * 2)
  90. return HTLEFT;
  91. }
  92. if(m_lRightBorder == CAPTION_BORDER)
  93. {
  94. if (point.x > crWindow.right - m_lRightBorder)
  95. return HTCAPTION;
  96. }
  97. else if(m_lBottomBorder == CAPTION_BORDER)
  98. {
  99. if(point.y > crWindow.bottom - m_lBottomBorder)
  100. return HTCAPTION;
  101. }
  102. else if(m_lLeftBorder == CAPTION_BORDER)
  103. {
  104. if (point.x < crWindow.left + m_lLeftBorder)
  105. return HTCAPTION;
  106. }
  107. else if(m_lTopBorder == CAPTION_BORDER)
  108. {
  109. if (point.y < crWindow.top + m_lTopBorder)
  110. return HTCAPTION;
  111. }
  112. return -1;
  113. }
  114. void CDittoWindow::DoNcPaint(CWnd *pWnd)
  115. {
  116. CWindowDC dc(pWnd);
  117. CRect rcFrame;
  118. pWnd->GetWindowRect(rcFrame);
  119. pWnd->ScreenToClient(rcFrame);
  120. CRect rc;
  121. pWnd->GetClientRect(rc);
  122. pWnd->ClientToScreen(rc);
  123. long lWidth = rcFrame.Width();
  124. // Draw the window border
  125. CRect rcBorder(0, 0, lWidth, rcFrame.Height());
  126. dc.Draw3dRect(rcBorder, m_CaptionColorLeft, m_CaptionColorLeft);
  127. rcBorder.DeflateRect(1, 1, 1, 1);
  128. dc.Draw3dRect(rcBorder, m_CaptionColorLeft, m_CaptionColorLeft);
  129. rcBorder.InflateRect(1, 1, 1, 1);
  130. BOOL bVertical = FALSE;
  131. if(m_lRightBorder == CAPTION_BORDER)
  132. {
  133. m_crCloseBT.SetRect(rcBorder.right - m_lRightBorder + 2, 7, rcBorder.right - m_lRightBorder + 14, 18);
  134. m_crChevronBT.SetRect(rcBorder.right - m_lRightBorder + 2, rcBorder.bottom - 18, rcBorder.right - m_lRightBorder + 14, rcBorder.bottom - 7);
  135. m_crMaximizeBT = m_crCloseBT;
  136. m_crMaximizeBT.top += m_crCloseBT.Height() + 5;
  137. m_crMaximizeBT.bottom += m_crCloseBT.Height() + 5;
  138. m_crMinimizeBT = m_crMaximizeBT;
  139. m_crMinimizeBT.top += m_crCloseBT.Height() + 5;
  140. m_crMinimizeBT.bottom += m_crCloseBT.Height() + 5;
  141. rcBorder.left = rcBorder.right - m_lRightBorder;
  142. bVertical = TRUE;
  143. }
  144. else if(m_lLeftBorder == CAPTION_BORDER)
  145. {
  146. m_crCloseBT.SetRect(2, 7, 14, 18);
  147. m_crChevronBT.SetRect(2, rcBorder.bottom - 18, 14, rcBorder.bottom - 7);
  148. m_crMaximizeBT = m_crCloseBT;
  149. m_crMaximizeBT.top += m_crCloseBT.Height() + 5;
  150. m_crMaximizeBT.bottom += m_crCloseBT.Height() + 5;
  151. m_crMinimizeBT = m_crMaximizeBT;
  152. m_crMinimizeBT.top += m_crCloseBT.Height() + 5;
  153. m_crMinimizeBT.bottom += m_crCloseBT.Height() + 5;
  154. rcBorder.right = rcBorder.left + m_lLeftBorder;
  155. bVertical = TRUE;
  156. }
  157. else if(m_lTopBorder == CAPTION_BORDER)
  158. {
  159. m_crCloseBT.SetRect(rcBorder.right - 18, 3, rcBorder.right - 6, 14);
  160. m_crChevronBT.SetRect(4, 2, 15, 14);
  161. m_crMaximizeBT = m_crCloseBT;
  162. m_crMaximizeBT.left -= m_crCloseBT.Width() + 5;
  163. m_crMaximizeBT.right -= m_crCloseBT.Width() + 5;
  164. m_crMinimizeBT = m_crMaximizeBT;
  165. m_crMinimizeBT.left -= m_crCloseBT.Width() + 5;
  166. m_crMinimizeBT.right -= m_crCloseBT.Width() + 5;
  167. rcBorder.bottom = rcBorder.top + m_lTopBorder;
  168. bVertical = FALSE;
  169. }
  170. else if(m_lBottomBorder == CAPTION_BORDER)
  171. {
  172. m_crCloseBT.SetRect(rcBorder.right - 18, rcBorder.bottom - 13, rcBorder.right - 6, rcBorder.bottom - 2);
  173. m_crChevronBT.SetRect(4, rcBorder.bottom - 14, 15, rcBorder.bottom - 2);
  174. m_crMaximizeBT = m_crCloseBT;
  175. m_crMaximizeBT.left -= m_crCloseBT.Width() + 5;
  176. m_crMaximizeBT.right -= m_crCloseBT.Width() + 5;
  177. m_crMinimizeBT = m_crMaximizeBT;
  178. m_crMinimizeBT.left -= m_crCloseBT.Width() + 5;
  179. m_crMinimizeBT.right -= m_crCloseBT.Width() + 5;
  180. rcBorder.top = rcBorder.bottom - m_lBottomBorder;
  181. bVertical = FALSE;
  182. }
  183. if(m_bDrawClose == false)
  184. {
  185. m_crCloseBT.SetRectEmpty();
  186. }
  187. if(m_bDrawChevron == false)
  188. {
  189. m_crChevronBT.SetRectEmpty();
  190. }
  191. if(m_bDrawMaximize == false)
  192. {
  193. m_crMaximizeBT.SetRectEmpty();
  194. }
  195. if(m_bDrawMinimize == false)
  196. {
  197. m_crMinimizeBT.SetRectEmpty();
  198. }
  199. int r1 = GetRValue(m_CaptionColorLeft);
  200. int g1 = GetGValue(m_CaptionColorLeft);
  201. int b1 = GetBValue(m_CaptionColorLeft);
  202. int r2 = GetRValue(m_CaptionColorRight);
  203. int g2 = GetGValue(m_CaptionColorRight);
  204. int b2 = GetBValue(m_CaptionColorRight);
  205. bool bGradient = true;
  206. if(m_CaptionColorLeft == m_CaptionColorRight)
  207. {
  208. bGradient = false;
  209. }
  210. HBRUSH color;
  211. long lHeight = rcBorder.Height();
  212. CRect cr = rcBorder;
  213. long lCount = rcBorder.Width();
  214. if(bVertical)
  215. lCount = lHeight;
  216. for(int i = 0; i < lCount; i++)
  217. {
  218. int r, g, b;
  219. r = r1 + (i * (r2 - r1) / lCount);
  220. g = g1 + (i * (g2 - g1) / lCount);
  221. b = b1 + (i * (b2 - b1) / lCount);
  222. if(bVertical)
  223. {
  224. cr.top = i;
  225. cr.bottom = i + 1;
  226. }
  227. else
  228. {
  229. cr.left = i;
  230. cr.right = i + 1;
  231. }
  232. if(bGradient || i == 0)
  233. {
  234. color = CreateSolidBrush(RGB(r, g, b));
  235. }
  236. ::FillRect(dc, &cr, color);
  237. if(bGradient)
  238. DeleteObject(color);
  239. }
  240. if(bGradient == false)
  241. DeleteObject(color);
  242. int nOldBKMode = dc.SetBkMode(TRANSPARENT);
  243. COLORREF oldColor = dc.SetTextColor(m_CaptionTextColor);
  244. CFont *pOldFont = NULL;
  245. if(bVertical)
  246. pOldFont=dc.SelectObject(&m_VertFont);
  247. else
  248. pOldFont=dc.SelectObject(&m_HorFont);
  249. CString csText;
  250. pWnd->GetWindowText(csText);
  251. if(m_lRightBorder == CAPTION_BORDER)
  252. {
  253. int nTop = 0;
  254. if(m_bDrawClose)
  255. nTop += 20;
  256. if(m_bDrawMaximize)
  257. nTop += 20;
  258. if(m_bDrawMaximize)
  259. nTop += 20;
  260. cr.SetRect(rcBorder.right-1, nTop, rcBorder.right - 13, rcBorder.bottom - 20);
  261. dc.DrawText(csText, cr, DT_SINGLELINE);
  262. }
  263. else if(m_lBottomBorder == CAPTION_BORDER)
  264. {
  265. cr.SetRect(20, rcBorder.bottom - 15, rcBorder.right - 20, rcBorder.bottom - 1);
  266. dc.DrawText(csText, cr, DT_SINGLELINE);
  267. }
  268. else if(m_lLeftBorder == CAPTION_BORDER)
  269. {
  270. int nTop = 0;
  271. if(m_bDrawClose)
  272. nTop += 20;
  273. if(m_bDrawMaximize)
  274. nTop += 20;
  275. if(m_bDrawMaximize)
  276. nTop += 20;
  277. cr.SetRect(15, nTop, 2, rcBorder.bottom - 20);
  278. dc.DrawText(csText, cr, DT_SINGLELINE);
  279. }
  280. else if(m_lTopBorder == CAPTION_BORDER)
  281. {
  282. cr.SetRect(20, 1, rcBorder.right - 20, 15);
  283. dc.DrawText(csText, cr, DT_SINGLELINE);
  284. }
  285. DrawCloseBtn(dc);
  286. DrawChevronBtn(dc);
  287. DrawMaximizeBtn(dc);
  288. DrawMinimizeBtn(dc);
  289. dc.SelectObject(pOldFont);
  290. dc.SetTextColor(oldColor);
  291. dc.SetBkMode(nOldBKMode);
  292. }
  293. void CDittoWindow::DoSetRegion(CWnd *pWnd)
  294. {
  295. //Create the region for drawing the rounded top edge
  296. CRect rect;
  297. CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
  298. pWnd->GetWindowRect(rect);
  299. if((m_lRightBorder == CAPTION_BORDER) ||
  300. (m_lTopBorder == CAPTION_BORDER))
  301. {
  302. rgnRect.CreateRectRgn(0, 0, rect.Width() - 7, rect.Height());
  303. rgnRound.CreateRoundRectRgn(0, 0, rect.Width()+1, rect.Height(), 15, 15);
  304. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  305. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  306. rgnRect2.CreateRectRgn(0, 7, rect.Width(), rect.Height());
  307. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  308. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  309. //Set the region
  310. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  311. }
  312. else if(m_lLeftBorder == CAPTION_BORDER)
  313. {
  314. rgnRect.CreateRectRgn(0, 7, rect.Width(), rect.Height());
  315. rgnRound.CreateRoundRectRgn(0, 0, rect.Width(), rect.Height(), 15, 15);
  316. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  317. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  318. rgnRect2.CreateRectRgn(7, 0, rect.Width(), rect.Height());
  319. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  320. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  321. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  322. }
  323. else if(m_lBottomBorder == CAPTION_BORDER)
  324. {
  325. rgnRect.CreateRectRgn(0, 0, rect.Width(), rect.Height()-7);
  326. rgnRound.CreateRoundRectRgn(0, 0, rect.Width()+1, rect.Height()+1, 15, 15);
  327. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  328. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  329. rgnRect2.CreateRectRgn(0, 0, rect.Width()-15, rect.Height());
  330. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  331. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  332. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  333. }
  334. }
  335. void CDittoWindow::DrawChevronBtn(CWindowDC &dc)
  336. {
  337. if(m_bDrawChevron == false)
  338. {
  339. return;
  340. }
  341. bool bTopOrBottom = false;
  342. int Points[5][8];
  343. int Points2[8][5];
  344. if(((m_lRightBorder == CAPTION_BORDER) && (m_bMinimized == false)) ||
  345. ((m_lLeftBorder == CAPTION_BORDER) && (m_bMinimized)))
  346. {
  347. int nTemp[5][8] =
  348. {
  349. 1,1,0,0,1,1,0,0,
  350. 0,1,1,0,0,1,1,0,
  351. 0,0,1,1,0,0,1,1,
  352. 0,1,1,0,0,1,1,0,
  353. 1,1,0,0,1,1,0,0
  354. };
  355. memcpy(&Points, &nTemp, sizeof(nTemp));
  356. }
  357. else if(((m_lRightBorder == CAPTION_BORDER) && (m_bMinimized)) ||
  358. ((m_lLeftBorder == CAPTION_BORDER) && (m_bMinimized == false)))
  359. {
  360. int nTemp[5][8] =
  361. {
  362. 0,0,1,1,0,0,1,1,
  363. 0,1,1,0,0,1,1,0,
  364. 1,1,0,0,1,1,0,0,
  365. 0,1,1,0,0,1,1,0,
  366. 0,0,1,1,0,0,1,1
  367. };
  368. memcpy(&Points, &nTemp, sizeof(nTemp));
  369. }
  370. else if(((m_lTopBorder == CAPTION_BORDER) && (m_bMinimized == false)) ||
  371. ((m_lBottomBorder == CAPTION_BORDER) && (m_bMinimized)))
  372. {
  373. bTopOrBottom = true;
  374. int nTemp[8][5] =
  375. {
  376. 0,0,1,0,0,
  377. 0,1,1,1,0,
  378. 1,1,0,1,1,
  379. 1,0,0,0,1,
  380. 0,0,1,0,0,
  381. 0,1,1,1,0,
  382. 1,1,0,1,1,
  383. 1,0,0,0,1
  384. };
  385. memcpy(&Points2, &nTemp, sizeof(nTemp));
  386. }
  387. else if(((m_lTopBorder == CAPTION_BORDER) && (m_bMinimized)) ||
  388. ((m_lBottomBorder == CAPTION_BORDER) && (m_bMinimized == false)))
  389. {
  390. bTopOrBottom = true;
  391. int nTemp[8][5] =
  392. {
  393. 1,0,0,0,1,
  394. 1,1,0,1,1,
  395. 0,1,1,1,0,
  396. 0,0,1,0,0,
  397. 1,0,0,0,1,
  398. 1,1,0,1,1,
  399. 0,1,1,1,0,
  400. 0,0,1,0,0
  401. };
  402. memcpy(&Points2, &nTemp, sizeof(nTemp));
  403. }
  404. COLORREF shaddow = RGB(GetRValue(m_CaptionColorLeft) * 1.16, GetGValue(m_CaptionColorLeft) * 1.12, GetBValue(m_CaptionColorLeft) * 1.12);
  405. if(m_bMouseDownOnChevron)
  406. dc.Draw3dRect(m_crChevronBT, shaddow, RGB(255, 255, 255));
  407. else if(m_bMouseOverChevron)
  408. dc.Draw3dRect(m_crChevronBT, RGB(255, 255, 255), shaddow);
  409. if(bTopOrBottom == false)
  410. {
  411. CPoint ptShift = m_crChevronBT.TopLeft();
  412. ptShift.Offset(2, 3);
  413. for (int iRow = 0; iRow < 5; iRow++)
  414. {
  415. for (int iCol = 0; iCol < 8; iCol++)
  416. {
  417. if (Points[iRow][iCol] == 1)
  418. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  419. }
  420. }
  421. }
  422. else
  423. {
  424. CPoint ptShift = m_crChevronBT.TopLeft();
  425. ptShift.Offset(3, 2);
  426. for (int iRow = 0; iRow < 8; iRow++)
  427. {
  428. for (int iCol = 0; iCol < 5; iCol++)
  429. {
  430. if (Points2[iRow][iCol] == 1)
  431. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  432. }
  433. }
  434. }
  435. }
  436. void CDittoWindow::DrawCloseBtn(CWindowDC &dc)
  437. {
  438. if(m_bDrawClose == false)
  439. {
  440. return;
  441. }
  442. //rows first then columns
  443. int Points[5][6] =
  444. {
  445. 1,1,0,0,1,1,
  446. 0,1,1,1,1,0,
  447. 0,0,1,1,0,0,
  448. 0,1,1,1,1,0,
  449. 1,1,0,0,1,1
  450. };
  451. CPoint ptShift = m_crCloseBT.TopLeft();
  452. ptShift.Offset(3, 3);
  453. if(m_bMouseDownOnClose)
  454. {
  455. dc.Draw3dRect(m_crCloseBT, RGB(255, 255, 255), RGB(255, 255, 255));
  456. CRect cr(m_crCloseBT);
  457. cr.DeflateRect(1, 1, 1, 1);
  458. dc.Draw3dRect(cr, RGB(255, 255, 255), RGB(255, 255, 255));
  459. }
  460. else if(m_bMouseOverClose)
  461. {
  462. dc.Draw3dRect(m_crCloseBT, RGB(255, 255, 255), RGB(255, 255, 255));
  463. }
  464. for (int iRow = 0; iRow < 5; iRow++)
  465. {
  466. for (int iCol = 0; iCol < 6; iCol++)
  467. {
  468. if (Points[iRow][iCol] == 1)
  469. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  470. }
  471. }
  472. }
  473. void CDittoWindow::DrawMinimizeBtn(CWindowDC &dc)
  474. {
  475. if(m_bDrawMinimize == false)
  476. {
  477. return;
  478. }
  479. //rows first then columns
  480. int Points[5][6] =
  481. {
  482. 0,0,0,0,0,0,
  483. 0,0,0,0,0,0,
  484. 0,0,0,0,0,0,
  485. 1,1,1,1,1,0,
  486. 1,1,1,1,1,0
  487. };
  488. CPoint ptShift = m_crMinimizeBT.TopLeft();
  489. ptShift.Offset(3, 3);
  490. if(m_bMouseDownOnMinimize)
  491. {
  492. dc.Draw3dRect(m_crMinimizeBT, RGB(255, 255, 255), RGB(255, 255, 255));
  493. CRect cr(m_crMinimizeBT);
  494. cr.DeflateRect(1, 1, 1, 1);
  495. dc.Draw3dRect(cr, RGB(255, 255, 255), RGB(255, 255, 255));
  496. }
  497. else if(m_bMouseOverMinimize)
  498. {
  499. dc.Draw3dRect(m_crMinimizeBT, RGB(255, 255, 255), RGB(255, 255, 255));
  500. }
  501. for (int iRow = 0; iRow < 5; iRow++)
  502. {
  503. for (int iCol = 0; iCol < 6; iCol++)
  504. {
  505. if (Points[iRow][iCol] == 1)
  506. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  507. }
  508. }
  509. }
  510. void CDittoWindow::DrawMaximizeBtn(CWindowDC &dc)
  511. {
  512. if(m_bDrawMaximize == false)
  513. {
  514. return;
  515. }
  516. //rows first then columns
  517. int Points[6][7] =
  518. {
  519. 0,0,1,1,1,1,1,
  520. 1,1,1,1,1,1,1,
  521. 1,0,0,0,0,1,1,
  522. 1,0,0,0,0,1,1,
  523. 1,0,0,0,0,1,0,
  524. 1,1,1,1,1,1,0,
  525. };
  526. CPoint ptShift = m_crMaximizeBT.TopLeft();
  527. ptShift.Offset(3, 3);
  528. if(m_bMouseDownOnMaximize)
  529. {
  530. dc.Draw3dRect(m_crMaximizeBT, RGB(255, 255, 255), RGB(255, 255, 255));
  531. CRect cr(m_crMaximizeBT);
  532. cr.DeflateRect(1, 1, 1, 1);
  533. dc.Draw3dRect(cr, RGB(255, 255, 255), RGB(255, 255, 255));
  534. }
  535. else if(m_bMouseOverMaximize)
  536. {
  537. dc.Draw3dRect(m_crMaximizeBT, RGB(255, 255, 255), RGB(255, 255, 255));
  538. }
  539. for (int iRow = 0; iRow < 6; iRow++)
  540. {
  541. for (int iCol = 0; iCol < 7; iCol++)
  542. {
  543. if (Points[iRow][iCol] == 1)
  544. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  545. }
  546. }
  547. }
  548. void CDittoWindow::DoNcLButtonDown(CWnd *pWnd, UINT nHitTest, CPoint point)
  549. {
  550. CPoint clPoint(point);
  551. pWnd->ScreenToClient(&clPoint);
  552. clPoint.x += m_lLeftBorder;
  553. clPoint.y += m_lTopBorder;
  554. if(m_crCloseBT.PtInRect(clPoint))
  555. {
  556. pWnd->SetCapture();
  557. m_bMouseDownOnClose = true;
  558. CWindowDC dc(pWnd);
  559. DrawCloseBtn(dc);
  560. }
  561. else if(m_crChevronBT.PtInRect(clPoint))
  562. {
  563. pWnd->SetCapture();
  564. m_bMouseDownOnChevron = true;
  565. CWindowDC dc(pWnd);
  566. DrawChevronBtn(dc);
  567. }
  568. else if(m_crMinimizeBT.PtInRect(clPoint))
  569. {
  570. pWnd->SetCapture();
  571. m_bMouseDownOnMinimize = true;
  572. CWindowDC dc(pWnd);
  573. DrawMinimizeBtn(dc);
  574. }
  575. else if(m_crMaximizeBT.PtInRect(clPoint))
  576. {
  577. pWnd->SetCapture();
  578. m_bMouseDownOnMaximize = true;
  579. CWindowDC dc(pWnd);
  580. DrawMaximizeBtn(dc);
  581. }
  582. else if(m_bMinimized)
  583. {
  584. //MinMaxWindow(FORCE_MAX);
  585. }
  586. }
  587. long CDittoWindow::DoNcLButtonUp(CWnd *pWnd, UINT nHitTest, CPoint point)
  588. {
  589. long lRet = 0;
  590. if(m_bMouseDownOnClose)
  591. {
  592. ReleaseCapture();
  593. m_bMouseDownOnClose = false;
  594. m_bMouseOverClose = false;
  595. DoNcPaint(pWnd);
  596. CPoint clPoint(point);
  597. clPoint.x += m_lLeftBorder;
  598. clPoint.y += m_lTopBorder;
  599. if(m_crCloseBT.PtInRect(clPoint))
  600. {
  601. pWnd->SendMessage(WM_CLOSE, 0, 0);
  602. lRet = BUTTON_CLOSE;
  603. }
  604. }
  605. else if(m_bMouseDownOnChevron)
  606. {
  607. ReleaseCapture();
  608. m_bMouseDownOnChevron = false;
  609. m_bMouseOverChevron = false;
  610. DoNcPaint(pWnd);
  611. CPoint clPoint(point);
  612. clPoint.x += m_lLeftBorder;
  613. clPoint.y += m_lTopBorder;
  614. if(m_crChevronBT.PtInRect(clPoint))
  615. {
  616. lRet = BUTTON_CHEVRON;
  617. }
  618. }
  619. else if(m_bMouseDownOnMinimize)
  620. {
  621. ReleaseCapture();
  622. m_bMouseDownOnMinimize = false;
  623. m_bMouseOverMinimize = false;
  624. DoNcPaint(pWnd);
  625. CPoint clPoint(point);
  626. clPoint.x += m_lLeftBorder;
  627. clPoint.y += m_lTopBorder;
  628. if(m_crMinimizeBT.PtInRect(clPoint))
  629. {
  630. pWnd->ShowWindow(SW_MINIMIZE);
  631. lRet = BUTTON_MINIMIZE;
  632. }
  633. }
  634. else if(m_bMouseDownOnMaximize)
  635. {
  636. ReleaseCapture();
  637. m_bMouseDownOnMaximize = false;
  638. m_bMouseOverMaximize = false;
  639. DoNcPaint(pWnd);
  640. CPoint clPoint(point);
  641. clPoint.x += m_lLeftBorder;
  642. clPoint.y += m_lTopBorder;
  643. if(m_crMaximizeBT.PtInRect(clPoint))
  644. {
  645. if(pWnd->GetStyle() & WS_MAXIMIZE)
  646. pWnd->ShowWindow(SW_RESTORE);
  647. else
  648. pWnd->ShowWindow(SW_SHOWMAXIMIZED);
  649. lRet = BUTTON_MAXIMIZE;
  650. }
  651. }
  652. return lRet;
  653. }
  654. void CDittoWindow::DoNcMouseMove(CWnd *pWnd, UINT nHitTest, CPoint point)
  655. {
  656. CPoint clPoint(point);
  657. pWnd->ScreenToClient(&clPoint);
  658. clPoint.x += m_lLeftBorder;
  659. clPoint.y += m_lTopBorder;
  660. if(m_crCloseBT.PtInRect(clPoint))
  661. {
  662. m_bMouseOverClose = true;
  663. CWindowDC dc(pWnd);
  664. DrawCloseBtn(dc);
  665. }
  666. else if(m_bMouseOverClose)
  667. {
  668. m_bMouseOverClose = false;
  669. DoNcPaint(pWnd);
  670. }
  671. if(m_crChevronBT.PtInRect(clPoint))
  672. {
  673. m_bMouseOverChevron = true;
  674. CWindowDC dc(pWnd);
  675. DrawChevronBtn(dc);
  676. }
  677. else if(m_bMouseOverChevron)
  678. {
  679. m_bMouseOverChevron = false;
  680. DoNcPaint(pWnd);
  681. }
  682. if(m_crMinimizeBT.PtInRect(clPoint))
  683. {
  684. m_bMouseOverMinimize = true;
  685. CWindowDC dc(pWnd);
  686. DrawMinimizeBtn(dc);
  687. }
  688. else if(m_bMouseOverMinimize)
  689. {
  690. m_bMouseOverMinimize = false;
  691. DoNcPaint(pWnd);
  692. }
  693. if(m_crMaximizeBT.PtInRect(clPoint))
  694. {
  695. m_bMouseOverMaximize = true;
  696. CWindowDC dc(pWnd);
  697. DrawMaximizeBtn(dc);
  698. }
  699. else if(m_bMouseOverMaximize)
  700. {
  701. m_bMouseOverMaximize = false;
  702. DoNcPaint(pWnd);
  703. }
  704. }
  705. bool CDittoWindow::DoPreTranslateMessage(MSG* pMsg)
  706. {
  707. if (pMsg->message == WM_NCLBUTTONDOWN)
  708. {
  709. m_bMouseDownOnCaption = true;
  710. }
  711. if ((pMsg->message == WM_LBUTTONUP) && (m_bMouseDownOnCaption))
  712. {
  713. m_bMouseDownOnCaption = false;
  714. pMsg->message = WM_NCLBUTTONUP;
  715. }
  716. return true;
  717. }
  718. void CDittoWindow::SetCaptionOn(CWnd *pWnd, int nPos, bool bOnstartup)
  719. {
  720. m_lTopBorder = BORDER;
  721. m_lRightBorder = BORDER;
  722. m_lBottomBorder = BORDER;
  723. m_lLeftBorder = BORDER;
  724. if(nPos == CAPTION_RIGHT)
  725. m_lRightBorder = CAPTION_BORDER;
  726. if(nPos == CAPTION_BOTTOM)
  727. m_lBottomBorder = CAPTION_BORDER;
  728. if(nPos == CAPTION_LEFT)
  729. m_lLeftBorder = CAPTION_BORDER;
  730. if(nPos == CAPTION_TOP)
  731. m_lTopBorder = CAPTION_BORDER;
  732. DoSetRegion(pWnd);
  733. if(!bOnstartup)
  734. {
  735. pWnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  736. }
  737. pWnd->RedrawWindow();
  738. }
  739. bool CDittoWindow::SetCaptionColors(COLORREF left, COLORREF right)
  740. {
  741. m_CaptionColorLeft = left;
  742. m_CaptionColorRight = right;
  743. return true;
  744. }
  745. void CDittoWindow::SetCaptionTextColor(COLORREF color)
  746. {
  747. m_CaptionTextColor = color;
  748. }