DittoWindow.cpp 23 KB

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