WndEx.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. // WndEx.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "WndEx.h"
  6. #include ".\wndex.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CWndEx
  14. #define CLOSE_WIDTH 12
  15. #define CLOSE_HEIGHT 11
  16. #define CLOSE_BORDER 2
  17. #define TIMER_AUTO_MAX 1
  18. #define TIMER_AUTO_MIN 2
  19. CWndEx::CWndEx()
  20. {
  21. m_bResizable = true;
  22. m_bMouseDownOnClose = false;
  23. m_bMouseOverClose = false;
  24. m_bMouseDownOnCaption = false;
  25. m_bMouseOverMinimize = false;
  26. m_bMouseDownOnMinimize = false;
  27. m_bMinimized = false;
  28. m_bMaxSetTimer = false;
  29. SetCaptionColorActive(false);
  30. }
  31. CWndEx::~CWndEx()
  32. {
  33. }
  34. void CWndEx::InvalidateNc()
  35. {
  36. ::RedrawWindow( m_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_NOINTERNALPAINT );
  37. }
  38. void CWndEx::GetWindowRectEx(LPRECT lpRect)
  39. {
  40. if(m_bMinimized)
  41. {
  42. lpRect = m_crFullSizeWindow;
  43. return;
  44. }
  45. CWnd::GetWindowRect(lpRect);
  46. }
  47. bool CWndEx::SetCaptionColors( COLORREF left, COLORREF right )
  48. {
  49. if( left == m_CaptionColorLeft || right == m_CaptionColorRight )
  50. return false;
  51. m_CaptionColorLeft = left;
  52. m_CaptionColorRight = right;
  53. return true;
  54. }
  55. bool CWndEx::SetCaptionColorActive( bool bVal )
  56. {
  57. bool bResult;
  58. if( bVal )
  59. bResult = SetCaptionColors( ::GetSysColor(COLOR_ACTIVECAPTION), ::GetSysColor(COLOR_GRADIENTACTIVECAPTION) );
  60. else
  61. bResult = SetCaptionColors( ::GetSysColor(COLOR_INACTIVECAPTION), ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION) );
  62. return bResult;
  63. }
  64. BEGIN_MESSAGE_MAP(CWndEx, CWnd)
  65. //{{AFX_MSG_MAP(CWndEx)
  66. ON_WM_CREATE()
  67. ON_WM_NCPAINT()
  68. ON_WM_NCCALCSIZE()
  69. ON_WM_NCHITTEST()
  70. ON_WM_NCLBUTTONDOWN()
  71. ON_WM_NCMOUSEMOVE()
  72. ON_WM_NCLBUTTONUP()
  73. ON_WM_ERASEBKGND()
  74. ON_WM_TIMER()
  75. ON_WM_WINDOWPOSCHANGING()
  76. //}}AFX_MSG_MAP
  77. // ON_WM_NCLBUTTONDBLCLK()
  78. // ON_WM_NCACTIVATE()
  79. ON_WM_SIZE()
  80. END_MESSAGE_MAP()
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CWndEx message handlers
  83. BOOL CWndEx::Create(const CRect& crStart, CWnd* pParentWnd)
  84. {
  85. WNDCLASS wc;
  86. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  87. wc.lpfnWndProc = AfxWndProc;
  88. wc.cbClsExtra = 0;
  89. wc.cbWndExtra = 0;
  90. wc.hInstance = AfxGetInstanceHandle();
  91. wc.hIcon = NULL;
  92. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  93. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  94. wc.lpszMenuName = NULL;
  95. wc.lpszClassName = "QPasteClass";
  96. // Create the QPaste window class
  97. if (!AfxRegisterClass(&wc))
  98. return FALSE;
  99. return CWndEx::CreateEx(0, "QPasteClass", "Quick Paste", WS_POPUP,
  100. crStart, pParentWnd, 0);
  101. }
  102. int CWndEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
  103. {
  104. if (CWnd::OnCreate(lpCreateStruct) == -1)
  105. return -1;
  106. m_TitleFont.CreateFont(14,0,-900,0,400,FALSE,FALSE,0,ANSI_CHARSET,
  107. OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
  108. DEFAULT_PITCH|FF_SWISS,"Arial");
  109. m_HorFont.CreateFont(14,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,
  110. OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
  111. DEFAULT_PITCH|FF_SWISS,"Arial");
  112. SetCaptionOn(CGetSetOptions::GetCaptionPos(), true);
  113. SetAutoHide(CGetSetOptions::GetAutoHide());
  114. return 0;
  115. }
  116. void CWndEx::SetAutoHide(BOOL bAutoHide)
  117. {
  118. if(bAutoHide)
  119. {
  120. SetTimer(TIMER_AUTO_MIN, 500, NULL);
  121. }
  122. else
  123. {
  124. KillTimer(TIMER_AUTO_MIN);
  125. }
  126. }
  127. void CWndEx::SetCaptionOn(int nPos, bool bOnstartup)
  128. {
  129. m_lTopBorder = BORDER;
  130. m_lRightBorder = BORDER;
  131. m_lBottomBorder = BORDER;
  132. m_lLeftBorder = BORDER;
  133. if(nPos == CAPTION_RIGHT)
  134. m_lRightBorder = CAPTION_BORDER;
  135. if(nPos == CAPTION_BOTTOM)
  136. m_lBottomBorder = CAPTION_BORDER;
  137. if(nPos == CAPTION_LEFT)
  138. m_lLeftBorder = CAPTION_BORDER;
  139. if(nPos == CAPTION_TOP)
  140. m_lTopBorder = CAPTION_BORDER;
  141. SetRegion();
  142. if(!bOnstartup)
  143. {
  144. SetWindowPos (NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
  145. }
  146. RedrawWindow();
  147. }
  148. void CWndEx::OnNcPaint()
  149. {
  150. CWindowDC dc(this);
  151. CRect rcFrame;
  152. GetWindowRect(rcFrame);
  153. ScreenToClient(rcFrame);
  154. CRect rc;
  155. GetClientRect(rc);
  156. ClientToScreen(rc);
  157. long lWidth = rcFrame.Width();
  158. // Draw the window border
  159. CRect rcBorder(0, 0, lWidth, rcFrame.Height());
  160. COLORREF left = m_CaptionColorLeft;
  161. COLORREF right = m_CaptionColorRight;
  162. dc.Draw3dRect(rcBorder, left, left);
  163. rcBorder.DeflateRect(1, 1, 1, 1);
  164. dc.Draw3dRect(rcBorder, left, left);
  165. rcBorder.InflateRect(1, 1, 1, 1);
  166. BOOL bVertical;
  167. if(m_lRightBorder == CAPTION_BORDER)
  168. {
  169. m_crCloseBT.SetRect(rcBorder.right - m_lRightBorder + 2,
  170. 7,
  171. rcBorder.right - m_lRightBorder + 14,
  172. 18);
  173. m_crMinimizeBT.SetRect(rcBorder.right - m_lRightBorder + 2,
  174. rcBorder.bottom - 18,
  175. rcBorder.right - m_lRightBorder + 14,
  176. rcBorder.bottom - 7);
  177. rcBorder.left = rcBorder.right - m_lRightBorder;
  178. bVertical = TRUE;
  179. }
  180. else if(m_lLeftBorder == CAPTION_BORDER)
  181. {
  182. m_crCloseBT.SetRect(2,
  183. 7,
  184. 2 + 12,
  185. 7 + 11);
  186. m_crMinimizeBT.SetRect(2,
  187. rcBorder.bottom - 18,
  188. 2 + 12,
  189. rcBorder.bottom - 7);
  190. rcBorder.right = rcBorder.left + m_lLeftBorder;
  191. bVertical = TRUE;
  192. }
  193. else if(m_lTopBorder == CAPTION_BORDER)
  194. {
  195. m_crCloseBT.SetRect(rcBorder.right - 18,
  196. 3,
  197. rcBorder.right - 6,
  198. 3 + 11);
  199. m_crMinimizeBT.SetRect(4,
  200. 2,
  201. 15,
  202. 2 + 12);
  203. rcBorder.bottom = rcBorder.top + m_lTopBorder;
  204. bVertical = FALSE;
  205. }
  206. else if(m_lBottomBorder == CAPTION_BORDER)
  207. {
  208. m_crCloseBT.SetRect(rcBorder.right - 18,
  209. rcBorder.bottom - 13,
  210. rcBorder.right - 6,
  211. rcBorder.bottom - 2);
  212. m_crMinimizeBT.SetRect(4,
  213. rcBorder.bottom - 14,
  214. 15,
  215. rcBorder.bottom - 2);
  216. rcBorder.top = rcBorder.bottom - m_lBottomBorder;
  217. bVertical = FALSE;
  218. }
  219. float gR = 0;
  220. float gG = 0;
  221. float gB = 0;
  222. float sR = GetRValue(left);
  223. float sG = GetGValue(left);
  224. float sB = GetBValue(left);
  225. float eR = GetRValue(right);
  226. float eG = GetGValue(right);
  227. float eB = GetBValue(right);
  228. // calculate the slope for color gradient
  229. if(bVertical)
  230. {
  231. gR = (eR - sR) / rcBorder.Height();
  232. gG = (eG - sG) / rcBorder.Height();
  233. gB = (eB - sB) / rcBorder.Height();
  234. }
  235. else
  236. {
  237. gR = (eR - sR) / rcBorder.Width();
  238. gG = (eG - sG) / rcBorder.Width();
  239. gB = (eB - sB) / rcBorder.Width();
  240. }
  241. HBRUSH color;
  242. long lHeight = rcBorder.Height();
  243. CRect cr = rcBorder;
  244. long lCount = rcBorder.Width();
  245. if(bVertical)
  246. lCount = lHeight;
  247. for(int i = 0; i < lCount; i++)
  248. {
  249. if(bVertical)
  250. {
  251. cr.top = i;
  252. cr.bottom = i + 1;
  253. }
  254. else
  255. {
  256. cr.left = i;
  257. cr.right = i + 1;
  258. }
  259. color = CreateSolidBrush(RGB(int(gR * (float) i + gR),
  260. int(gG * (float) i + sG),
  261. int(gB * (float) i + sB)));
  262. ::FillRect(dc, &cr, color);
  263. DeleteObject(color);
  264. }
  265. /*
  266. HBRUSH color;
  267. color = CreateSolidBrush(left);
  268. ::FillRect(dc, &rcBorder, color);
  269. DeleteObject(color);
  270. */
  271. int nOldBKMode = dc.SetBkMode(TRANSPARENT);
  272. COLORREF oldColor = dc.SetTextColor(RGB(255, 255, 255));
  273. CFont *pOldFont = NULL;
  274. if(bVertical)
  275. pOldFont=dc.SelectObject(&m_TitleFont);
  276. else
  277. pOldFont=dc.SelectObject(&m_HorFont);
  278. CString csText;
  279. GetWindowText(csText);
  280. if(m_lRightBorder == CAPTION_BORDER)
  281. {
  282. CRect cr;
  283. cr.SetRect(rcBorder.right-1, 20, rcBorder.right - 13, rcBorder.bottom - 20);
  284. dc.DrawText(csText, cr, DT_SINGLELINE);
  285. }
  286. else if(m_lBottomBorder == CAPTION_BORDER)
  287. {
  288. CRect cr;
  289. cr.SetRect(20, rcBorder.bottom - 15, rcBorder.right - 20, rcBorder.bottom - 1);
  290. dc.DrawText(csText, cr, DT_SINGLELINE);
  291. }
  292. else if(m_lLeftBorder == CAPTION_BORDER)
  293. {
  294. CRect cr;
  295. cr.SetRect(15, 20, 2, rcBorder.bottom - 20);
  296. dc.DrawText(csText, cr, DT_SINGLELINE);
  297. }
  298. else if(m_lTopBorder == CAPTION_BORDER)
  299. {
  300. CRect cr;
  301. cr.SetRect(20, 1, rcBorder.right - 20, 15);
  302. dc.DrawText(csText, cr, DT_SINGLELINE);
  303. }
  304. DrawCloseBtn(dc, left);
  305. DrawMinimizeBtn(dc, left);
  306. dc.SelectObject(pOldFont);
  307. dc.SetTextColor(oldColor);
  308. dc.SetBkMode(nOldBKMode);
  309. }
  310. void CWndEx::DrawCloseBtn(CWindowDC &dc, COLORREF left)
  311. {
  312. if(left == 0)
  313. left = GetSysColor(COLOR_ACTIVECAPTION);
  314. //rows first then columns
  315. int Points[5][6] =
  316. {
  317. 1,1,0,0,1,1,
  318. 0,1,1,1,1,0,
  319. 0,0,1,1,0,0,
  320. 0,1,1,1,1,0,
  321. 1,1,0,0,1,1
  322. };
  323. CPoint ptShift = m_crCloseBT.TopLeft();
  324. ptShift.Offset(3, 3);
  325. COLORREF shaddow = RGB(GetRValue(left) * 1.16,
  326. GetGValue(left) * 1.12,
  327. GetBValue(left) * 1.12);
  328. if(m_bMouseDownOnClose)
  329. dc.Draw3dRect(m_crCloseBT, shaddow, RGB(255, 255, 255));
  330. else if(m_bMouseOverClose)
  331. dc.Draw3dRect(m_crCloseBT, RGB(255, 255, 255), shaddow);
  332. for (int iRow = 0; iRow < 5; iRow++)
  333. {
  334. for (int iCol = 0; iCol < 6; iCol++)
  335. {
  336. if (Points[iRow][iCol] == 1)
  337. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  338. }
  339. }
  340. }
  341. void CWndEx::DrawMinimizeBtn(CWindowDC &dc, COLORREF left)
  342. {
  343. if(left == 0)
  344. left = GetSysColor(COLOR_ACTIVECAPTION);
  345. bool bTopOrBottom = false;
  346. int Points[5][8];
  347. int Points2[8][5];
  348. if(((m_lRightBorder == CAPTION_BORDER) && (m_bMinimized == false)) ||
  349. ((m_lLeftBorder == CAPTION_BORDER) && (m_bMinimized)))
  350. {
  351. int nTemp[5][8] =
  352. {
  353. 1,1,0,0,1,1,0,0,
  354. 0,1,1,0,0,1,1,0,
  355. 0,0,1,1,0,0,1,1,
  356. 0,1,1,0,0,1,1,0,
  357. 1,1,0,0,1,1,0,0
  358. };
  359. memcpy(&Points, &nTemp, sizeof(nTemp));
  360. }
  361. else if(((m_lRightBorder == CAPTION_BORDER) && (m_bMinimized)) ||
  362. ((m_lLeftBorder == CAPTION_BORDER) && (m_bMinimized == false)))
  363. {
  364. int nTemp[5][8] =
  365. {
  366. 0,0,1,1,0,0,1,1,
  367. 0,1,1,0,0,1,1,0,
  368. 1,1,0,0,1,1,0,0,
  369. 0,1,1,0,0,1,1,0,
  370. 0,0,1,1,0,0,1,1
  371. };
  372. memcpy(&Points, &nTemp, sizeof(nTemp));
  373. }
  374. else if(((m_lTopBorder == CAPTION_BORDER) && (m_bMinimized == false)) ||
  375. ((m_lBottomBorder == CAPTION_BORDER) && (m_bMinimized)))
  376. {
  377. bTopOrBottom = true;
  378. int nTemp[8][5] =
  379. {
  380. 0,0,1,0,0,
  381. 0,1,1,1,0,
  382. 1,1,0,1,1,
  383. 1,0,0,0,1,
  384. 0,0,1,0,0,
  385. 0,1,1,1,0,
  386. 1,1,0,1,1,
  387. 1,0,0,0,1
  388. };
  389. memcpy(&Points2, &nTemp, sizeof(nTemp));
  390. }
  391. else if(((m_lTopBorder == CAPTION_BORDER) && (m_bMinimized)) ||
  392. ((m_lBottomBorder == CAPTION_BORDER) && (m_bMinimized == false)))
  393. {
  394. bTopOrBottom = true;
  395. int nTemp[8][5] =
  396. {
  397. 1,0,0,0,1,
  398. 1,1,0,1,1,
  399. 0,1,1,1,0,
  400. 0,0,1,0,0,
  401. 1,0,0,0,1,
  402. 1,1,0,1,1,
  403. 0,1,1,1,0,
  404. 0,0,1,0,0
  405. };
  406. memcpy(&Points2, &nTemp, sizeof(nTemp));
  407. }
  408. COLORREF shaddow = RGB(GetRValue(left) * 1.16,
  409. GetGValue(left) * 1.12,
  410. GetBValue(left) * 1.12);
  411. if(m_bMouseDownOnMinimize)
  412. dc.Draw3dRect(m_crMinimizeBT, shaddow, RGB(255, 255, 255));
  413. else if(m_bMouseOverMinimize)
  414. dc.Draw3dRect(m_crMinimizeBT, RGB(255, 255, 255), shaddow);
  415. if(bTopOrBottom == false)
  416. {
  417. CPoint ptShift = m_crMinimizeBT.TopLeft();
  418. ptShift.Offset(2, 3);
  419. for (int iRow = 0; iRow < 5; iRow++)
  420. {
  421. for (int iCol = 0; iCol < 8; iCol++)
  422. {
  423. if (Points[iRow][iCol] == 1)
  424. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  425. }
  426. }
  427. }
  428. else
  429. {
  430. CPoint ptShift = m_crMinimizeBT.TopLeft();
  431. ptShift.Offset(3, 2);
  432. for (int iRow = 0; iRow < 8; iRow++)
  433. {
  434. for (int iCol = 0; iCol < 5; iCol++)
  435. {
  436. if (Points2[iRow][iCol] == 1)
  437. dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
  438. }
  439. }
  440. }
  441. }
  442. void CWndEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  443. {
  444. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  445. //Decrease the client area
  446. lpncsp->rgrc[0].left+= m_lLeftBorder;
  447. lpncsp->rgrc[0].top+= m_lTopBorder;
  448. lpncsp->rgrc[0].right-= m_lRightBorder;
  449. lpncsp->rgrc[0].bottom-= m_lBottomBorder;
  450. }
  451. UINT CWndEx::OnNcHitTest(CPoint point)
  452. {
  453. if(!m_bResizable)
  454. return CWnd::OnNcHitTest(point);
  455. //Hit the close button
  456. // CPoint clPoint(point);
  457. // ScreenToClient(&clPoint);
  458. // if(m_crCloseBT.PtInRect(clPoint))
  459. // return HTCLOSE;
  460. CRect crWindow;
  461. GetWindowRect(crWindow);
  462. if(crWindow.PtInRect(point) == false)
  463. {
  464. return CWnd::OnNcHitTest(point);
  465. }
  466. if(m_bMinimized == false)
  467. {
  468. if ((point.y < crWindow.top + BORDER * 2) &&
  469. (point.x < crWindow.left + BORDER * 2))
  470. return HTTOPLEFT;
  471. else if ((point.y < crWindow.top + BORDER * 2) &&
  472. (point.x > crWindow.right - BORDER * 2))
  473. return HTTOPRIGHT;
  474. else if ((point.y > crWindow.bottom - BORDER * 2) &&
  475. (point.x > crWindow.right - BORDER * 2))
  476. return HTBOTTOMRIGHT;
  477. else if ((point.y > crWindow.bottom - BORDER * 2) &&
  478. (point.x < crWindow.left + BORDER * 2))
  479. return HTBOTTOMLEFT;
  480. }
  481. if((((m_lTopBorder == CAPTION_BORDER) || (m_lBottomBorder == CAPTION_BORDER)) &&
  482. (m_bMinimized)) == false)
  483. {
  484. if (point.y < crWindow.top + BORDER * 2)
  485. return HTTOP;
  486. if (point.y > crWindow.bottom - BORDER * 2)
  487. return HTBOTTOM;
  488. }
  489. if((((m_lLeftBorder == CAPTION_BORDER) || (m_lRightBorder == CAPTION_BORDER)) &&
  490. (m_bMinimized)) == false)
  491. {
  492. if (point.x > crWindow.right - BORDER * 2)
  493. return HTRIGHT;
  494. if (point.x < crWindow.left + BORDER * 2)
  495. return HTLEFT;
  496. }
  497. if(m_lRightBorder == CAPTION_BORDER)
  498. {
  499. if (point.x > crWindow.right - m_lRightBorder)
  500. return HTCAPTION;
  501. }
  502. else if(m_lBottomBorder == CAPTION_BORDER)
  503. {
  504. if(point.y > crWindow.bottom - m_lBottomBorder)
  505. return HTCAPTION;
  506. }
  507. else if(m_lLeftBorder == CAPTION_BORDER)
  508. {
  509. if (point.x < crWindow.left + m_lLeftBorder)
  510. return HTCAPTION;
  511. }
  512. else if(m_lTopBorder == CAPTION_BORDER)
  513. {
  514. if (point.y < crWindow.top + m_lTopBorder)
  515. return HTCAPTION;
  516. }
  517. return CWnd::OnNcHitTest(point); // The default handler
  518. }
  519. void CWndEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  520. {
  521. CPoint clPoint(point);
  522. ScreenToClient(&clPoint);
  523. clPoint.x += m_lLeftBorder;
  524. clPoint.y += m_lTopBorder;
  525. if(m_crCloseBT.PtInRect(clPoint))
  526. {
  527. SetCapture();
  528. m_bMouseDownOnClose = true;
  529. CWindowDC dc(this);
  530. DrawCloseBtn(dc);
  531. }
  532. else if(m_crMinimizeBT.PtInRect(clPoint))
  533. {
  534. SetCapture();
  535. m_bMouseDownOnMinimize = true;
  536. CWindowDC dc(this);
  537. DrawMinimizeBtn(dc);
  538. }
  539. CWnd::OnNcLButtonDown(nHitTest, point);
  540. }
  541. void CWndEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  542. {
  543. if(m_bMouseDownOnClose)
  544. {
  545. ReleaseCapture();
  546. m_bMouseDownOnClose = false;
  547. m_bMouseOverClose = false;
  548. OnNcPaint();
  549. CPoint clPoint(point);
  550. clPoint.x += m_lLeftBorder;
  551. clPoint.y += m_lTopBorder;
  552. if(m_crCloseBT.PtInRect(clPoint))
  553. SendMessage(WM_CLOSE, 0, 0);
  554. }
  555. else if(m_bMouseDownOnMinimize)
  556. {
  557. ReleaseCapture();
  558. m_bMouseDownOnMinimize = false;
  559. m_bMouseOverMinimize = false;
  560. OnNcPaint();
  561. CPoint clPoint(point);
  562. clPoint.x += m_lLeftBorder;
  563. clPoint.y += m_lTopBorder;
  564. if(m_crMinimizeBT.PtInRect(clPoint))
  565. {
  566. MinMaxWindow();
  567. }
  568. }
  569. CWnd::OnNcLButtonUp(nHitTest, point);
  570. }
  571. void CWndEx::MinMaxWindow(long lOption)
  572. {
  573. if((m_bMinimized) && (lOption == FORCE_MIN))
  574. return;
  575. if((m_bMinimized == false) && (lOption == FORCE_MAX))
  576. return;
  577. if(m_lRightBorder == CAPTION_BORDER)
  578. {
  579. if(m_bMinimized == false)
  580. {
  581. GetWindowRect(m_crFullSizeWindow);
  582. MoveWindow(m_crFullSizeWindow.right - CAPTION_BORDER,
  583. m_crFullSizeWindow.top, CAPTION_BORDER,
  584. m_crFullSizeWindow.Height());
  585. m_bMinimized = true;
  586. OnNcPaint();
  587. }
  588. else
  589. {
  590. CRect cr;
  591. GetWindowRect(cr);
  592. MoveWindow(cr.right - m_crFullSizeWindow.Width(),
  593. cr.top, m_crFullSizeWindow.Width(), cr.Height());
  594. m_crFullSizeWindow.SetRectEmpty();
  595. m_bMinimized = false;
  596. OnNcPaint();
  597. }
  598. }
  599. if(m_lLeftBorder == CAPTION_BORDER)
  600. {
  601. if(m_bMinimized == false)
  602. {
  603. GetWindowRect(m_crFullSizeWindow);
  604. MoveWindow(m_crFullSizeWindow.left,
  605. m_crFullSizeWindow.top, CAPTION_BORDER,
  606. m_crFullSizeWindow.Height());
  607. m_bMinimized = true;
  608. OnNcPaint();
  609. }
  610. else
  611. {
  612. CRect cr;
  613. GetWindowRect(cr);
  614. MoveWindow(cr.left, cr.top,
  615. m_crFullSizeWindow.Width(), cr.Height());
  616. m_crFullSizeWindow.SetRectEmpty();
  617. m_bMinimized = false;
  618. OnNcPaint();
  619. }
  620. }
  621. else if(m_lTopBorder == CAPTION_BORDER)
  622. {
  623. if(m_bMinimized == false)
  624. {
  625. GetWindowRect(m_crFullSizeWindow);
  626. MoveWindow(m_crFullSizeWindow.left,
  627. m_crFullSizeWindow.top,
  628. m_crFullSizeWindow.Width(),
  629. CAPTION_BORDER);
  630. m_bMinimized = true;
  631. OnNcPaint();
  632. }
  633. else
  634. {
  635. CRect cr;
  636. GetWindowRect(cr);
  637. MoveWindow(cr.left, cr.top,
  638. cr.Width(), m_crFullSizeWindow.Height());
  639. m_crFullSizeWindow.SetRectEmpty();
  640. m_bMinimized = false;
  641. OnNcPaint();
  642. }
  643. }
  644. else if(m_lBottomBorder == CAPTION_BORDER)
  645. {
  646. if(m_bMinimized == false)
  647. {
  648. GetWindowRect(m_crFullSizeWindow);
  649. MoveWindow(m_crFullSizeWindow.left,
  650. m_crFullSizeWindow.bottom - CAPTION_BORDER,
  651. m_crFullSizeWindow.Width(),
  652. CAPTION_BORDER);
  653. m_bMinimized = true;
  654. OnNcPaint();
  655. }
  656. else
  657. {
  658. CRect cr;
  659. GetWindowRect(cr);
  660. MoveWindow(cr.left,
  661. cr.bottom - m_crFullSizeWindow.Height(),
  662. cr.Width(), m_crFullSizeWindow.Height());
  663. m_crFullSizeWindow.SetRectEmpty();
  664. m_bMinimized = false;
  665. OnNcPaint();
  666. }
  667. }
  668. }
  669. void CWndEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  670. {
  671. CPoint clPoint(point);
  672. ScreenToClient(&clPoint);
  673. clPoint.x += m_lLeftBorder;
  674. clPoint.y += m_lTopBorder;
  675. if(m_crCloseBT.PtInRect(clPoint))
  676. {
  677. m_bMouseOverClose = true;
  678. CWindowDC dc(this);
  679. DrawCloseBtn(dc);
  680. }
  681. else if(m_bMouseOverClose)
  682. {
  683. m_bMouseOverClose = false;
  684. OnNcPaint();
  685. }
  686. if(m_crMinimizeBT.PtInRect(clPoint))
  687. {
  688. m_bMouseOverMinimize = true;
  689. CWindowDC dc(this);
  690. DrawMinimizeBtn(dc);
  691. }
  692. else if(m_bMouseOverMinimize)
  693. {
  694. m_bMouseOverMinimize = false;
  695. OnNcPaint();
  696. }
  697. if((m_bMaxSetTimer == false) && m_bMinimized)
  698. {
  699. SetTimer(TIMER_AUTO_MAX, 1000, NULL);
  700. m_bMaxSetTimer = true;
  701. }
  702. CWnd::OnNcMouseMove(nHitTest, point);
  703. }
  704. BOOL CWndEx::PreTranslateMessage(MSG* pMsg)
  705. {
  706. if (pMsg->message == WM_NCLBUTTONDOWN)
  707. {
  708. m_bMouseDownOnCaption = true;
  709. }
  710. if ((pMsg->message == WM_LBUTTONUP) && (m_bMouseDownOnCaption))
  711. {
  712. m_bMouseDownOnCaption = false;
  713. pMsg->message = WM_NCLBUTTONUP;
  714. }
  715. return CWnd::PreTranslateMessage(pMsg);
  716. }
  717. /*
  718. CBitmap m_bitmap;
  719. CDC dcMem;
  720. void MakeBitmap();
  721. CDC dcMem;
  722. dcMem.CreateCompatibleDC(&dc);
  723. CBitmap *pOldBmp = (CBitmap *)(dcMem.SelectObject(&m_bitmap));
  724. dc.BitBlt(rcBorder.left, 0, rcBorder.Width(), rcBorder.Height(), &dcMem, 0, 0, SRCCOPY);
  725. dcMem.SelectObject(pOldBmp);
  726. dcMem.DeleteDC();
  727. void CWndEx::MakeBitmap()
  728. {
  729. CWindowDC dc(this);
  730. CRect rect;
  731. GetWindowRect(&rect);
  732. CRect rcBorder(0, 0, rect.Width(), rect.Height());
  733. rcBorder.left = rcBorder.right - RIGHT_CAPTION - BORDER + 1;
  734. rect = rcBorder;
  735. int r1=245,g1=190,b1=240;
  736. int r2=130,g2=0,b2=0;
  737. int x1=0,y1=0;
  738. int x2=0,y2=0;
  739. CDC dc2;
  740. dc2.CreateCompatibleDC(&dc);
  741. if(m_bitmap.m_hObject)
  742. m_bitmap.DeleteObject();
  743. m_bitmap.CreateCompatibleBitmap(&dc,rect.Width(),
  744. rect.Height());
  745. CBitmap *oldbmap=dc2.SelectObject(&m_bitmap);
  746. while(x1 < rect.Width() && y1 < rect.Height())
  747. {
  748. if(y1 < rect.Height()-1)
  749. y1++;
  750. else
  751. x1++;
  752. if(x2 < rect.Width()-1)
  753. x2++;
  754. else
  755. y2++;
  756. int r,g,b;
  757. int i = x1+y1;
  758. r = r1 + (i * (r2-r1) / (rect.Width()+rect.Height()));
  759. g = g1 + (i * (g2-g1) / (rect.Width()+rect.Height()));
  760. b = b1 + (i * (b2-b1) / (rect.Width()+rect.Height()));
  761. CPen p(PS_SOLID,1,RGB(r,g,b));
  762. CPen *oldpen = dc2.SelectObject(&p);
  763. dc2.MoveTo(x1,y1);
  764. dc2.LineTo(x2,y2);
  765. dc2.SelectObject(oldpen);
  766. }
  767. dc2.SelectObject(oldbmap);
  768. }
  769. */
  770. BOOL CWndEx::OnEraseBkgnd(CDC* pDC)
  771. {
  772. return CWnd::OnEraseBkgnd(pDC);
  773. }
  774. void CWndEx::OnTimer(UINT nIDEvent)
  775. {
  776. if(nIDEvent == TIMER_AUTO_MAX)
  777. {
  778. if(m_bMinimized)
  779. {
  780. CPoint cp;
  781. GetCursorPos(&cp);
  782. UINT nHitTest = OnNcHitTest(cp);
  783. ScreenToClient(&cp);
  784. if(nHitTest == HTCAPTION)
  785. {
  786. if(m_crCloseBT.PtInRect(cp) == false)
  787. {
  788. if(m_crMinimizeBT.PtInRect(cp) == false)
  789. {
  790. MinMaxWindow(FORCE_MAX);
  791. }
  792. }
  793. }
  794. }
  795. KillTimer(TIMER_AUTO_MAX);
  796. m_bMaxSetTimer = false;
  797. }
  798. else if(nIDEvent == TIMER_AUTO_MIN)
  799. {
  800. if((m_bMinimized == false) && (g_Opt.m_bShowPersistent))
  801. {
  802. CPoint cp;
  803. CRect cr;
  804. GetCursorPos(&cp);
  805. GetWindowRect(&cr);
  806. if(cr.PtInRect(cp) == false)
  807. {
  808. if(GetFocus() == NULL)
  809. {
  810. MinMaxWindow(FORCE_MIN);
  811. }
  812. }
  813. }
  814. }
  815. CWnd::OnTimer(nIDEvent);
  816. }
  817. void CWndEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  818. {
  819. CWnd::OnWindowPosChanging(lpwndpos);
  820. if(m_bMaxSetTimer)
  821. {
  822. KillTimer(TIMER_AUTO_MAX);
  823. m_bMaxSetTimer = false;
  824. }
  825. }
  826. void CWndEx::SetRegion()
  827. {
  828. if((m_lRightBorder == CAPTION_BORDER) ||
  829. (m_lTopBorder == CAPTION_BORDER))
  830. {
  831. //Create the region for drawing the rounded top edge
  832. CRect rect;
  833. GetWindowRect(rect);
  834. CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
  835. rgnRect.CreateRectRgn(0, 0, rect.Width() - 7, rect.Height());
  836. rgnRound.CreateRoundRectRgn(0, 0, rect.Width()+1, rect.Height(), 15, 15);
  837. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  838. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  839. rgnRect2.CreateRectRgn(0, 7, rect.Width(), rect.Height());
  840. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  841. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  842. //Set the region
  843. SetWindowRgn(rgnFinalA, TRUE);
  844. }
  845. else if(m_lLeftBorder == CAPTION_BORDER)
  846. {
  847. CRect rect;
  848. GetWindowRect(rect);
  849. CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
  850. rgnRect.CreateRectRgn(0, 7, rect.Width(), rect.Height());
  851. rgnRound.CreateRoundRectRgn(0, 0, rect.Width(), rect.Height(), 15, 15);
  852. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  853. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  854. rgnRect2.CreateRectRgn(7, 0, rect.Width(), rect.Height());
  855. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  856. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  857. //Set the region
  858. SetWindowRgn(rgnFinalA, TRUE);
  859. }
  860. else if(m_lBottomBorder == CAPTION_BORDER)
  861. {
  862. CRect rect;
  863. GetWindowRect(rect);
  864. CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
  865. rgnRect.CreateRectRgn(0, 0, rect.Width(), rect.Height()-7);
  866. rgnRound.CreateRoundRectRgn(0, 0, rect.Width()+1, rect.Height()+1, 15, 15);
  867. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  868. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  869. rgnRect2.CreateRectRgn(0, 0, rect.Width()-15, rect.Height());
  870. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  871. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  872. //Set the region
  873. SetWindowRgn(rgnFinalA, TRUE);
  874. }
  875. }
  876. void CWndEx::OnSize(UINT nType, int cx, int cy)
  877. {
  878. CWnd::OnSize(nType, cx, cy);
  879. SetRegion();
  880. }