DittoWindow.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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_28, Close_Black_32_32, _T("PNG"));
  48. m_chevronRightButton.LoadStdImageDPI(ChevronRight_Black_16_16, ChevronRight_Black_20_20, ChevronRight_Black_24_24, ChevronRight_Black_28, ChevronRight_Black_32_32, _T("PNG"));
  49. m_chevronLeftButton.LoadStdImageDPI(ChevronLeft_Black_16_16, ChevronLeft_Black_20_20, ChevronLeft_Black_24_24, ChevronLeft_Black_28, ChevronLeft_Black_32_32, _T("PNG"));
  50. m_maximizeButton.LoadStdImageDPI(IDB_MAXIMIZE_16_16, maximize_20, maximize_24, maximize_28, maximize_32, _T("PNG"));
  51. m_minimizeButton.LoadStdImageDPI(minimize_16, minimize_20, minimize_24, minimize_28, 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), 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. int top = IndexToPos(closeIndex, false);
  249. m_crCloseBT.SetRect(left, top, right, top+ widthHeight);
  250. top = IndexToPos(chevronIndex, false);
  251. m_crChevronBT.SetRect(left, top, right, top + widthHeight);
  252. top = IndexToPos(maxIndex, false);
  253. m_crMaximizeBT.SetRect(left, top, right, top + widthHeight);
  254. top = IndexToPos(minIndex, false);
  255. m_crMinimizeBT.SetRect(left, top, right, top + widthHeight);
  256. 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);
  257. bVertical = TRUE;
  258. }
  259. else if(m_lLeftBorder == CAPTION_BORDER)
  260. {
  261. rightRect.SetRect(rcBorder.left, rcBorder.top, rcBorder.left + CAPTION_BORDER - border, rcBorder.top + IndexToPos(index, false));
  262. leftRect.SetRect(rcBorder.left, rcBorder.top + IndexToPos(index, false), rcBorder.left + CAPTION_BORDER - border, rcBorder.bottom);
  263. 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));
  264. int left = theApp.m_metrics.ScaleX(5);
  265. int right = theApp.m_metrics.ScaleX(21);
  266. int top = IndexToPos(closeIndex, false);
  267. m_crCloseBT.SetRect(left, top, right, top + widthHeight);
  268. top = IndexToPos(chevronIndex, false);
  269. m_crChevronBT.SetRect(left, top, right, top + widthHeight);
  270. top = IndexToPos(maxIndex, false);
  271. m_crMaximizeBT.SetRect(left, top, right, top + widthHeight);
  272. top = IndexToPos(minIndex, false);
  273. m_crMinimizeBT.SetRect(left, top, right, top + widthHeight);
  274. 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);
  275. bVertical = TRUE;
  276. }
  277. else if(m_lTopBorder == CAPTION_BORDER)
  278. {
  279. leftRect.SetRect(rcBorder.left, rcBorder.top, rcBorder.right - IndexToPos(index-1, true)- theApp.m_metrics.ScaleX(8), CAPTION_BORDER);
  280. rightRect.SetRect(leftRect.right, rcBorder.top, rcBorder.right, CAPTION_BORDER);
  281. textRect.SetRect(leftRect.right, leftRect.top, leftRect.right, leftRect.bottom);
  282. int top = theApp.m_metrics.ScaleX(5);
  283. int bottom = theApp.m_metrics.ScaleX(21);
  284. int left = rcBorder.right - IndexToPos(closeIndex, true);
  285. m_crCloseBT.SetRect(left, top, left + widthHeight, bottom);
  286. left = rcBorder.right - IndexToPos(chevronIndex, true);
  287. m_crChevronBT.SetRect(left, top, left + widthHeight, bottom);
  288. left = rcBorder.right - IndexToPos(maxIndex, true);
  289. m_crMaximizeBT.SetRect(left, top, left + widthHeight, bottom);
  290. left = rcBorder.right - IndexToPos(minIndex, true);
  291. m_crMinimizeBT.SetRect(left, top, left + widthHeight, bottom);
  292. left = rcBorder.left + theApp.m_metrics.ScaleX(10);
  293. m_crWindowIconBT.SetRect(left, top, left + theApp.m_metrics.ScaleX(24), bottom);
  294. bVertical = FALSE;
  295. }
  296. else if(m_lBottomBorder == CAPTION_BORDER)
  297. {
  298. leftRect.SetRect(rcBorder.left, rcBorder.bottom-CAPTION_BORDER+ border, rcBorder.right - IndexToPos(index - 1, true) - theApp.m_metrics.ScaleX(8), rcBorder.bottom);
  299. rightRect.SetRect(leftRect.right, rcBorder.bottom - CAPTION_BORDER+ border, rcBorder.right, rcBorder.bottom);
  300. textRect.SetRect(leftRect.right, leftRect.top, leftRect.right, leftRect.bottom);
  301. int top = leftRect.top + theApp.m_metrics.ScaleX(4);
  302. int bottom = leftRect.top + theApp.m_metrics.ScaleX(20);
  303. int left = rcBorder.right - IndexToPos(closeIndex, true);
  304. m_crCloseBT.SetRect(left, top, left + widthHeight, bottom);
  305. left = rcBorder.right - IndexToPos(chevronIndex, true);
  306. m_crChevronBT.SetRect(left, top, left+ widthHeight, bottom);
  307. left = rcBorder.right - IndexToPos(maxIndex, true);
  308. m_crMaximizeBT.SetRect(left, top, left + widthHeight, bottom);
  309. left = rcBorder.right - IndexToPos(minIndex, true);
  310. m_crMinimizeBT.SetRect(left, top, left + widthHeight, bottom);
  311. left = rcBorder.left + theApp.m_metrics.ScaleX(10);
  312. m_crWindowIconBT.SetRect(left, top, left + theApp.m_metrics.ScaleX(24), bottom);
  313. bVertical = FALSE;
  314. }
  315. HBRUSH leftColor = CreateSolidBrush(m_CaptionColorLeft);
  316. HBRUSH rightColor = CreateSolidBrush(m_CaptionColorRight);
  317. ::FillRect(dc, &leftRect, leftColor);
  318. ::FillRect(dc, &rightRect, rightColor);
  319. DeleteObject(leftColor);
  320. DeleteObject(rightColor);
  321. int nOldBKMode = dc.SetBkMode(TRANSPARENT);
  322. COLORREF oldColor = dc.SetTextColor(m_CaptionTextColor);
  323. CFont *pOldFont = NULL;
  324. if (bVertical)
  325. pOldFont = dc.SelectObject(&m_VertFont);
  326. else
  327. pOldFont = dc.SelectObject(&m_HorFont);
  328. CString csText = m_customWindowTitle;
  329. if (m_useCustomWindowTitle == false)
  330. {
  331. pWnd->GetWindowText(csText);
  332. }
  333. int flags = DT_SINGLELINE;
  334. if (bVertical == false)
  335. {
  336. CRect size(0, 0, 0, 0);
  337. dc.DrawText(csText, size, DT_CALCRECT);
  338. textRect.left = textRect.right - size.Width() - theApp.m_metrics.ScaleX(10);
  339. flags |= DT_VCENTER;
  340. }
  341. dc.DrawText(csText, textRect, flags);
  342. dc.SelectObject(pOldFont);
  343. dc.SetBkMode(nOldBKMode);
  344. /*
  345. int r1 = GetRValue(m_CaptionColorLeft);
  346. int g1 = GetGValue(m_CaptionColorLeft);
  347. int b1 = GetBValue(m_CaptionColorLeft);
  348. int r2 = GetRValue(m_CaptionColorRight);
  349. int g2 = GetGValue(m_CaptionColorRight);
  350. int b2 = GetBValue(m_CaptionColorRight);
  351. bool bGradient = true;
  352. if(m_CaptionColorLeft == m_CaptionColorRight)
  353. {
  354. bGradient = false;
  355. }
  356. HBRUSH color;
  357. long lHeight = rcBorder.Height();
  358. CRect cr = rcBorder;
  359. long lCount = rcBorder.Width();
  360. if(bVertical)
  361. lCount = lHeight;
  362. for(int i = 0; i < lCount; i++)
  363. {
  364. int r, g, b;
  365. r = r1 + (i * (r2 - r1) / lCount);
  366. g = g1 + (i * (g2 - g1) / lCount);
  367. b = b1 + (i * (b2 - b1) / lCount);
  368. if(bVertical)
  369. {
  370. cr.top = i;
  371. cr.bottom = i + 1;
  372. }
  373. else
  374. {
  375. cr.left = i;
  376. cr.right = i + 1;
  377. }
  378. if(bGradient || i == 0)
  379. {
  380. color = CreateSolidBrush(RGB(r, g, b));
  381. }
  382. ::FillRect(dc, &cr, color);
  383. if(bGradient)
  384. DeleteObject(color);
  385. }
  386. if(bGradient == false)
  387. DeleteObject(color);
  388. int nOldBKMode = dc.SetBkMode(TRANSPARENT);
  389. COLORREF oldColor = dc.SetTextColor(m_CaptionTextColor);
  390. CFont *pOldFont = NULL;
  391. if(bVertical)
  392. pOldFont=dc.SelectObject(&m_VertFont);
  393. else
  394. pOldFont=dc.SelectObject(&m_HorFont);
  395. CString csText = m_customWindowTitle;
  396. if (m_useCustomWindowTitle == false)
  397. {
  398. pWnd->GetWindowText(csText);
  399. }
  400. if(m_lRightBorder == CAPTION_BORDER)
  401. {
  402. int nTop = largeBorder;
  403. if (m_bDrawClose)
  404. nTop += widthHeight + largeBorder;
  405. if (m_bDrawMaximize)
  406. nTop += widthHeight + largeBorder;
  407. if (m_bDrawMaximize)
  408. nTop += widthHeight + largeBorder;
  409. cr.SetRect(rcBorder.right - 1, nTop, rcBorder.right - theApp.m_metrics.ScaleX(13), rcBorder.bottom - theApp.m_metrics.ScaleY(20));
  410. dc.DrawText(csText, cr, DT_SINGLELINE);
  411. }
  412. else if(m_lBottomBorder == CAPTION_BORDER)
  413. {
  414. cr.SetRect(theApp.m_metrics.ScaleX(20), rcBorder.bottom - theApp.m_metrics.ScaleY(15), rcBorder.right - theApp.m_metrics.ScaleX(20), rcBorder.bottom - 1);
  415. dc.DrawText(csText, cr, DT_SINGLELINE);
  416. }
  417. else if(m_lLeftBorder == CAPTION_BORDER)
  418. {
  419. int nTop = largeBorder;
  420. if(m_bDrawClose)
  421. nTop += widthHeight + largeBorder;
  422. if(m_bDrawMaximize)
  423. nTop += widthHeight + largeBorder;
  424. if(m_bDrawMaximize)
  425. nTop += widthHeight + largeBorder;
  426. cr.SetRect(theApp.m_metrics.ScaleX(15) , nTop, 2, rcBorder.bottom - theApp.m_metrics.ScaleY(20));
  427. dc.DrawText(csText, cr, DT_SINGLELINE);
  428. }
  429. else if(m_lTopBorder == CAPTION_BORDER)
  430. {
  431. cr.SetRect(theApp.m_metrics.ScaleX(20), 1, rcBorder.right - theApp.m_metrics.ScaleX(20), theApp.m_metrics.ScaleY(15));
  432. dc.DrawText(csText, cr, DT_SINGLELINE);
  433. }
  434. DrawChevronBtn(dc, pWnd);
  435. DrawMaximizeBtn(dc, pWnd);
  436. DrawMinimizeBtn(dc);
  437. dc.SelectObject(pOldFont);
  438. dc.SetTextColor(oldColor);
  439. dc.SetBkMode(nOldBKMode);*/
  440. DrawWindowIcon(dc, pWnd);
  441. DrawChevronBtn(dc, pWnd);
  442. DrawCloseBtn(dc, pWnd);
  443. DrawMaximizeBtn(dc, pWnd);
  444. DrawMinimizeBtn(dc, pWnd);
  445. }
  446. void CDittoWindow::DoSetRegion(CWnd *pWnd)
  447. {
  448. return;
  449. //Create the region for drawing the rounded top edge
  450. CRect rect;
  451. CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
  452. pWnd->GetWindowRect(rect);
  453. if(rect.Width() < 0)
  454. return;
  455. CRect r;
  456. pWnd->GetClientRect(&r);
  457. int seven = theApp.m_metrics.ScaleX(7);
  458. int fifteen = theApp.m_metrics.ScaleX(15);
  459. int one = theApp.m_metrics.ScaleX(1);
  460. if((m_lRightBorder == CAPTION_BORDER) ||
  461. (m_lTopBorder == CAPTION_BORDER))
  462. {
  463. rgnRect.CreateRectRgn(0, 0, rect.Width() - seven, rect.Height());
  464. rgnRound.CreateRoundRectRgn(0, 0, rect.Width() + one, rect.Height(), fifteen, fifteen);
  465. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  466. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  467. rgnRect2.CreateRectRgn(0, seven, rect.Width(), rect.Height());
  468. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  469. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  470. //Set the region
  471. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  472. }
  473. else if(m_lLeftBorder == CAPTION_BORDER)
  474. {
  475. rgnRect.CreateRectRgn(0, seven, rect.Width(), rect.Height());
  476. rgnRound.CreateRoundRectRgn(0, 0, rect.Width(), rect.Height(), fifteen, fifteen);
  477. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  478. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  479. rgnRect2.CreateRectRgn(seven, 0, rect.Width(), rect.Height());
  480. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  481. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  482. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  483. }
  484. else if(m_lBottomBorder == CAPTION_BORDER)
  485. {
  486. rgnRect.CreateRectRgn(0, 0, rect.Width(), rect.Height() - seven);
  487. rgnRound.CreateRoundRectRgn(0, 0, rect.Width() + one, rect.Height() + one, fifteen, fifteen);
  488. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  489. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  490. rgnRect2.CreateRectRgn(0, 0, rect.Width() - fifteen, rect.Height());
  491. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  492. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  493. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  494. }
  495. }
  496. void CDittoWindow::DrawChevronBtn(CWindowDC &dc, CWnd *pWnd)
  497. {
  498. if(m_bDrawChevron == false)
  499. {
  500. return;
  501. }
  502. if(this->m_bMinimized)
  503. {
  504. m_chevronLeftButton.Draw(&dc, pWnd, m_crChevronBT.left, m_crChevronBT.top, m_bMouseOverChevron, m_bMouseDownOnChevron);
  505. }
  506. else
  507. {
  508. m_chevronRightButton.Draw(&dc, pWnd, m_crChevronBT.left, m_crChevronBT.top, m_bMouseOverChevron, m_bMouseDownOnChevron);
  509. }
  510. }
  511. void CDittoWindow::DrawWindowIcon(CWindowDC &dc, CWnd *pWnd)
  512. {
  513. //m_windowIcon.Draw(&dc, pWnd, m_crWindowIconBT.left, m_crWindowIconBT.top, false, false);
  514. }
  515. void CDittoWindow::DrawCloseBtn(CWindowDC &dc, CWnd *pWnd)
  516. {
  517. if(m_bDrawClose == false)
  518. {
  519. return;
  520. }
  521. m_closeButton.Draw(&dc, pWnd, m_crCloseBT.left, m_crCloseBT.top, m_bMouseOverClose, m_bMouseDownOnClose);
  522. }
  523. void CDittoWindow::DrawMinimizeBtn(CWindowDC &dc, CWnd *pWnd)
  524. {
  525. if(m_bDrawMinimize == false)
  526. {
  527. return;
  528. }
  529. m_minimizeButton.Draw(&dc, pWnd, m_crMinimizeBT.left, m_crMinimizeBT.top, m_bMouseOverClose, m_bMouseDownOnClose);
  530. }
  531. void CDittoWindow::DrawMaximizeBtn(CWindowDC &dc, CWnd *pWnd)
  532. {
  533. if(m_bDrawMaximize == false)
  534. {
  535. return;
  536. }
  537. m_maximizeButton.Draw(&dc, pWnd, m_crMaximizeBT.left, m_crMaximizeBT.top, m_bMouseOverMaximize, m_bMouseDownOnMaximize);
  538. }
  539. void CDittoWindow::DoNcLButtonDown(CWnd *pWnd, UINT nHitTest, CPoint point)
  540. {
  541. //ReleaseCapture();
  542. CPoint clPoint(point);
  543. pWnd->ScreenToClient(&clPoint);
  544. clPoint.x += m_lLeftBorder;
  545. clPoint.y += m_lTopBorder;
  546. if(m_crCloseBT.PtInRect(clPoint))
  547. {
  548. m_bMouseDownOnClose = true;
  549. //InvalidateRect(pWnd->m_hWnd, m_crCloseBT, TRUE);
  550. //pWnd->InvalidateRect(m_crCloseBT);
  551. //pWnd->UpdateWindow();
  552. //DoNcPaint(pWnd);
  553. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  554. }
  555. else if(m_crChevronBT.PtInRect(clPoint))
  556. {
  557. m_bMouseDownOnChevron = true;
  558. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  559. }
  560. else if(m_crMinimizeBT.PtInRect(clPoint))
  561. {
  562. m_bMouseDownOnMinimize = true;
  563. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  564. }
  565. else if(m_crMaximizeBT.PtInRect(clPoint))
  566. {
  567. m_bMouseDownOnMaximize = true;
  568. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  569. }
  570. else if(m_bMinimized)
  571. {
  572. //MinMaxWindow(FORCE_MAX);
  573. }
  574. }
  575. long CDittoWindow::DoNcLButtonUp(CWnd *pWnd, UINT nHitTest, CPoint point)
  576. {
  577. CRect crWindow;
  578. pWnd->GetWindowRect(crWindow);
  579. CPoint localPoint(point.x - crWindow.left, point.y - crWindow.top);
  580. long lRet = 0;
  581. if(m_bMouseDownOnClose)
  582. {
  583. m_bMouseDownOnClose = false;
  584. m_bMouseOverClose = false;
  585. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  586. if(m_crCloseBT.PtInRect(localPoint))
  587. {
  588. if(m_sendWMClose)
  589. {
  590. pWnd->SendMessage(WM_CLOSE, 0, 0);
  591. }
  592. lRet = BUTTON_CLOSE;
  593. }
  594. }
  595. else if(m_bMouseDownOnChevron)
  596. {
  597. m_bMouseDownOnChevron = false;
  598. m_bMouseOverChevron = false;
  599. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  600. if(m_crChevronBT.PtInRect(localPoint))
  601. {
  602. lRet = BUTTON_CHEVRON;
  603. }
  604. }
  605. else if(m_bMouseDownOnMinimize)
  606. {
  607. m_bMouseDownOnMinimize = false;
  608. m_bMouseOverMinimize = false;
  609. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  610. if(m_crMinimizeBT.PtInRect(localPoint))
  611. {
  612. pWnd->ShowWindow(SW_MINIMIZE);
  613. lRet = BUTTON_MINIMIZE;
  614. }
  615. }
  616. else if(m_bMouseDownOnMaximize)
  617. {
  618. m_bMouseDownOnMaximize = false;
  619. m_bMouseOverMaximize = false;
  620. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  621. if(m_crMaximizeBT.PtInRect(localPoint))
  622. {
  623. if(pWnd->GetStyle() & WS_MAXIMIZE)
  624. pWnd->ShowWindow(SW_RESTORE);
  625. else
  626. pWnd->ShowWindow(SW_SHOWMAXIMIZED);
  627. lRet = BUTTON_MAXIMIZE;
  628. }
  629. }
  630. return lRet;
  631. }
  632. void CDittoWindow::DoNcMouseMove(CWnd *pWnd, UINT nHitTest, CPoint point)
  633. {
  634. return;
  635. CRect crWindow;
  636. pWnd->GetWindowRect(crWindow);
  637. CPoint localPoint(point.x - crWindow.left, point.y - crWindow.top);
  638. if(m_crCloseBT.PtInRect(localPoint))
  639. {
  640. m_bMouseOverClose = true;
  641. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  642. }
  643. else if(m_bMouseOverClose)
  644. {
  645. m_bMouseOverClose = false;
  646. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  647. }
  648. if(m_crChevronBT.PtInRect(localPoint))
  649. {
  650. m_bMouseOverChevron = true;
  651. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  652. }
  653. else if(m_bMouseOverChevron)
  654. {
  655. m_bMouseOverChevron = false;
  656. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  657. }
  658. if(m_crMinimizeBT.PtInRect(localPoint))
  659. {
  660. m_bMouseOverMinimize = true;
  661. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  662. }
  663. else if(m_bMouseOverMinimize)
  664. {
  665. m_bMouseOverMinimize = false;
  666. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  667. }
  668. if(m_crMaximizeBT.PtInRect(localPoint))
  669. {
  670. m_bMouseOverMaximize = true;
  671. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  672. }
  673. else if(m_bMouseOverMaximize)
  674. {
  675. m_bMouseOverMaximize = false;
  676. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  677. }
  678. }
  679. bool CDittoWindow::DoPreTranslateMessage(MSG* pMsg)
  680. {
  681. return true;
  682. }
  683. void CDittoWindow::SetCaptionOn(CWnd *pWnd, int nPos, bool bOnstartup)
  684. {
  685. m_lTopBorder = BORDER;
  686. m_lRightBorder = BORDER;
  687. m_lBottomBorder = BORDER;
  688. m_lLeftBorder = BORDER;
  689. if(nPos == CAPTION_RIGHT)
  690. m_lRightBorder = CAPTION_BORDER;
  691. if(nPos == CAPTION_BOTTOM)
  692. m_lBottomBorder = CAPTION_BORDER;
  693. if(nPos == CAPTION_LEFT)
  694. m_lLeftBorder = CAPTION_BORDER;
  695. if(nPos == CAPTION_TOP)
  696. m_lTopBorder = CAPTION_BORDER;
  697. DoSetRegion(pWnd);
  698. if(!bOnstartup)
  699. {
  700. pWnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  701. }
  702. pWnd->Invalidate();
  703. pWnd->RedrawWindow();
  704. }
  705. bool CDittoWindow::SetCaptionColors(COLORREF left, COLORREF right, COLORREF border)
  706. {
  707. m_CaptionColorLeft = left;
  708. m_CaptionColorRight = right;
  709. m_border = border;
  710. return true;
  711. }
  712. void CDittoWindow::SetCaptionTextColor(COLORREF color)
  713. {
  714. m_CaptionTextColor = color;
  715. }