WndEx.cpp 23 KB

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