WndEx.cpp 22 KB

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