DittoWindow.cpp 23 KB

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