DittoWindow.cpp 23 KB

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