DittoWindow.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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_border = RGB(204, 204, 204);
  32. m_sendWMClose = true;
  33. m_customWindowTitle = _T("");
  34. m_useCustomWindowTitle = false;
  35. }
  36. CDittoWindow::~CDittoWindow(void)
  37. {
  38. }
  39. void CDittoWindow::DoCreate(CWnd *pWnd)
  40. {
  41. m_VertFont.CreateFont(theApp.m_metrics.PointsToPixels(18), 0, -900, 0, 400, FALSE, FALSE, 0, DEFAULT_CHARSET,
  42. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  43. DEFAULT_PITCH|FF_SWISS, _T("Segoe UI"));
  44. m_HorFont.CreateFont(theApp.m_metrics.PointsToPixels(18), 0, 0, 0, 500, FALSE, FALSE, 0, DEFAULT_CHARSET,
  45. OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
  46. DEFAULT_PITCH|FF_SWISS, _T("Segoe UI"));
  47. m_closeButton.LoadStdImageDPI(Close_Black_16_16, Close_Black_20_20, Close_Black_24_24, Close_Black_32_32, _T("PNG"));
  48. m_chevronRightButton.LoadStdImageDPI(ChevronRight_Black_16_16, ChevronRight_Black_24_24, ChevronRight_Black_24_24, ChevronRight_Black_32_32, _T("PNG"));
  49. m_chevronLeftButton.LoadStdImageDPI(ChevronLeft_Black_16_16, ChevronLeft_Black_24_24, ChevronLeft_Black_24_24, ChevronLeft_Black_32_32, _T("PNG"));
  50. m_maximizeButton.LoadStdImageDPI(IDB_MAXIMIZE_16_16, maximize_20, maximize_24, maximize_32, _T("PNG"));
  51. m_minimizeButton.LoadStdImageDPI(minimize_16, minimize_20, minimize_24, minimize_32, _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_border, m_border);
  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, rcBorder.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(0), rcBorder.bottom - theApp.m_metrics.ScaleX(50));
  246. int left = rcBorder.right - theApp.m_metrics.ScaleX(19);
  247. int right = rcBorder.right - theApp.m_metrics.ScaleX(3);
  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(24), rcBorder.bottom - theApp.m_metrics.ScaleX(28), rcBorder.right - theApp.m_metrics.ScaleX(2), rcBorder.bottom);
  253. bVertical = TRUE;
  254. }
  255. else if(m_lLeftBorder == CAPTION_BORDER)
  256. {
  257. rightRect.SetRect(rcBorder.left, rcBorder.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(0), rightRect.bottom + theApp.m_metrics.ScaleX(10), rcBorder.left - theApp.m_metrics.ScaleX(5), rcBorder.bottom - theApp.m_metrics.ScaleX(50));
  260. int left = theApp.m_metrics.ScaleX(5);
  261. int right = theApp.m_metrics.ScaleX(21);
  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(0), rcBorder.bottom - theApp.m_metrics.ScaleX(28), rcBorder.left + theApp.m_metrics.ScaleX(25), 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(5);
  275. int bottom = theApp.m_metrics.ScaleX(21);
  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(4);
  289. int bottom = leftRect.top + theApp.m_metrics.ScaleX(20);
  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. DrawMaximizeBtn(dc, pWnd);
  426. DrawMinimizeBtn(dc, pWnd);
  427. }
  428. void CDittoWindow::DoSetRegion(CWnd *pWnd)
  429. {
  430. return;
  431. //Create the region for drawing the rounded top edge
  432. CRect rect;
  433. CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
  434. pWnd->GetWindowRect(rect);
  435. if(rect.Width() < 0)
  436. return;
  437. CRect r;
  438. pWnd->GetClientRect(&r);
  439. int seven = theApp.m_metrics.ScaleX(7);
  440. int fifteen = theApp.m_metrics.ScaleX(15);
  441. int one = theApp.m_metrics.ScaleX(1);
  442. if((m_lRightBorder == CAPTION_BORDER) ||
  443. (m_lTopBorder == CAPTION_BORDER))
  444. {
  445. rgnRect.CreateRectRgn(0, 0, rect.Width() - seven, rect.Height());
  446. rgnRound.CreateRoundRectRgn(0, 0, rect.Width() + one, rect.Height(), fifteen, fifteen);
  447. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  448. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  449. rgnRect2.CreateRectRgn(0, seven, rect.Width(), rect.Height());
  450. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  451. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  452. //Set the region
  453. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  454. }
  455. else if(m_lLeftBorder == CAPTION_BORDER)
  456. {
  457. rgnRect.CreateRectRgn(0, seven, rect.Width(), rect.Height());
  458. rgnRound.CreateRoundRectRgn(0, 0, rect.Width(), rect.Height(), fifteen, fifteen);
  459. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  460. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  461. rgnRect2.CreateRectRgn(seven, 0, rect.Width(), rect.Height());
  462. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  463. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  464. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  465. }
  466. else if(m_lBottomBorder == CAPTION_BORDER)
  467. {
  468. rgnRect.CreateRectRgn(0, 0, rect.Width(), rect.Height() - seven);
  469. rgnRound.CreateRoundRectRgn(0, 0, rect.Width() + one, rect.Height() + one, fifteen, fifteen);
  470. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  471. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  472. rgnRect2.CreateRectRgn(0, 0, rect.Width() - fifteen, rect.Height());
  473. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  474. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  475. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  476. }
  477. }
  478. void CDittoWindow::DrawChevronBtn(CWindowDC &dc, CWnd *pWnd)
  479. {
  480. if(m_bDrawChevron == false)
  481. {
  482. return;
  483. }
  484. if(this->m_bMinimized)
  485. {
  486. m_chevronLeftButton.Draw(&dc, pWnd, m_crChevronBT.left, m_crChevronBT.top, m_bMouseOverChevron, m_bMouseDownOnChevron);
  487. }
  488. else
  489. {
  490. m_chevronRightButton.Draw(&dc, pWnd, m_crChevronBT.left, m_crChevronBT.top, m_bMouseOverChevron, m_bMouseDownOnChevron);
  491. }
  492. }
  493. void CDittoWindow::DrawWindowIcon(CWindowDC &dc, CWnd *pWnd)
  494. {
  495. //m_windowIcon.Draw(&dc, pWnd, m_crWindowIconBT.left, m_crWindowIconBT.top, false, false);
  496. }
  497. void CDittoWindow::DrawCloseBtn(CWindowDC &dc, CWnd *pWnd)
  498. {
  499. if(m_bDrawClose == false)
  500. {
  501. return;
  502. }
  503. m_closeButton.Draw(&dc, pWnd, m_crCloseBT.left, m_crCloseBT.top, m_bMouseOverClose, m_bMouseDownOnClose);
  504. }
  505. void CDittoWindow::DrawMinimizeBtn(CWindowDC &dc, CWnd *pWnd)
  506. {
  507. if(m_bDrawMinimize == false)
  508. {
  509. return;
  510. }
  511. m_minimizeButton.Draw(&dc, pWnd, m_crMinimizeBT.left, m_crMinimizeBT.top, m_bMouseOverClose, m_bMouseDownOnClose);
  512. }
  513. void CDittoWindow::DrawMaximizeBtn(CWindowDC &dc, CWnd *pWnd)
  514. {
  515. if(m_bDrawMaximize == false)
  516. {
  517. return;
  518. }
  519. m_maximizeButton.Draw(&dc, pWnd, m_crMaximizeBT.left, m_crMaximizeBT.top, m_bMouseOverMaximize, m_bMouseDownOnMaximize);
  520. }
  521. void CDittoWindow::DoNcLButtonDown(CWnd *pWnd, UINT nHitTest, CPoint point)
  522. {
  523. //ReleaseCapture();
  524. CPoint clPoint(point);
  525. pWnd->ScreenToClient(&clPoint);
  526. clPoint.x += m_lLeftBorder;
  527. clPoint.y += m_lTopBorder;
  528. if(m_crCloseBT.PtInRect(clPoint))
  529. {
  530. m_bMouseDownOnClose = true;
  531. //InvalidateRect(pWnd->m_hWnd, m_crCloseBT, TRUE);
  532. //pWnd->InvalidateRect(m_crCloseBT);
  533. //pWnd->UpdateWindow();
  534. //DoNcPaint(pWnd);
  535. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  536. }
  537. else if(m_crChevronBT.PtInRect(clPoint))
  538. {
  539. m_bMouseDownOnChevron = true;
  540. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  541. }
  542. else if(m_crMinimizeBT.PtInRect(clPoint))
  543. {
  544. m_bMouseDownOnMinimize = true;
  545. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  546. }
  547. else if(m_crMaximizeBT.PtInRect(clPoint))
  548. {
  549. m_bMouseDownOnMaximize = true;
  550. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  551. }
  552. else if(m_bMinimized)
  553. {
  554. //MinMaxWindow(FORCE_MAX);
  555. }
  556. }
  557. long CDittoWindow::DoNcLButtonUp(CWnd *pWnd, UINT nHitTest, CPoint point)
  558. {
  559. CRect crWindow;
  560. pWnd->GetWindowRect(crWindow);
  561. CPoint localPoint(point.x - crWindow.left, point.y - crWindow.top);
  562. long lRet = 0;
  563. if(m_bMouseDownOnClose)
  564. {
  565. m_bMouseDownOnClose = false;
  566. m_bMouseOverClose = false;
  567. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  568. if(m_crCloseBT.PtInRect(localPoint))
  569. {
  570. if(m_sendWMClose)
  571. {
  572. pWnd->SendMessage(WM_CLOSE, 0, 0);
  573. }
  574. lRet = BUTTON_CLOSE;
  575. }
  576. }
  577. else if(m_bMouseDownOnChevron)
  578. {
  579. m_bMouseDownOnChevron = false;
  580. m_bMouseOverChevron = false;
  581. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  582. if(m_crChevronBT.PtInRect(localPoint))
  583. {
  584. lRet = BUTTON_CHEVRON;
  585. }
  586. }
  587. else if(m_bMouseDownOnMinimize)
  588. {
  589. m_bMouseDownOnMinimize = false;
  590. m_bMouseOverMinimize = false;
  591. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  592. if(m_crMinimizeBT.PtInRect(localPoint))
  593. {
  594. pWnd->ShowWindow(SW_MINIMIZE);
  595. lRet = BUTTON_MINIMIZE;
  596. }
  597. }
  598. else if(m_bMouseDownOnMaximize)
  599. {
  600. m_bMouseDownOnMaximize = false;
  601. m_bMouseOverMaximize = false;
  602. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  603. if(m_crMaximizeBT.PtInRect(localPoint))
  604. {
  605. if(pWnd->GetStyle() & WS_MAXIMIZE)
  606. pWnd->ShowWindow(SW_RESTORE);
  607. else
  608. pWnd->ShowWindow(SW_SHOWMAXIMIZED);
  609. lRet = BUTTON_MAXIMIZE;
  610. }
  611. }
  612. return lRet;
  613. }
  614. void CDittoWindow::DoNcMouseMove(CWnd *pWnd, UINT nHitTest, CPoint point)
  615. {
  616. return;
  617. CRect crWindow;
  618. pWnd->GetWindowRect(crWindow);
  619. CPoint localPoint(point.x - crWindow.left, point.y - crWindow.top);
  620. if(m_crCloseBT.PtInRect(localPoint))
  621. {
  622. m_bMouseOverClose = true;
  623. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  624. }
  625. else if(m_bMouseOverClose)
  626. {
  627. m_bMouseOverClose = false;
  628. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  629. }
  630. if(m_crChevronBT.PtInRect(localPoint))
  631. {
  632. m_bMouseOverChevron = true;
  633. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  634. }
  635. else if(m_bMouseOverChevron)
  636. {
  637. m_bMouseOverChevron = false;
  638. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  639. }
  640. if(m_crMinimizeBT.PtInRect(localPoint))
  641. {
  642. m_bMouseOverMinimize = true;
  643. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  644. }
  645. else if(m_bMouseOverMinimize)
  646. {
  647. m_bMouseOverMinimize = false;
  648. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  649. }
  650. if(m_crMaximizeBT.PtInRect(localPoint))
  651. {
  652. m_bMouseOverMaximize = true;
  653. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  654. }
  655. else if(m_bMouseOverMaximize)
  656. {
  657. m_bMouseOverMaximize = false;
  658. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  659. }
  660. }
  661. bool CDittoWindow::DoPreTranslateMessage(MSG* pMsg)
  662. {
  663. return true;
  664. }
  665. void CDittoWindow::SetCaptionOn(CWnd *pWnd, int nPos, bool bOnstartup)
  666. {
  667. m_lTopBorder = BORDER;
  668. m_lRightBorder = BORDER;
  669. m_lBottomBorder = BORDER;
  670. m_lLeftBorder = BORDER;
  671. if(nPos == CAPTION_RIGHT)
  672. m_lRightBorder = CAPTION_BORDER;
  673. if(nPos == CAPTION_BOTTOM)
  674. m_lBottomBorder = CAPTION_BORDER;
  675. if(nPos == CAPTION_LEFT)
  676. m_lLeftBorder = CAPTION_BORDER;
  677. if(nPos == CAPTION_TOP)
  678. m_lTopBorder = CAPTION_BORDER;
  679. DoSetRegion(pWnd);
  680. if(!bOnstartup)
  681. {
  682. pWnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  683. }
  684. pWnd->Invalidate();
  685. pWnd->RedrawWindow();
  686. }
  687. bool CDittoWindow::SetCaptionColors(COLORREF left, COLORREF right, COLORREF border)
  688. {
  689. m_CaptionColorLeft = left;
  690. m_CaptionColorRight = right;
  691. m_border = border;
  692. return true;
  693. }
  694. void CDittoWindow::SetCaptionTextColor(COLORREF color)
  695. {
  696. m_CaptionTextColor = color;
  697. }