COOL3DWNDMANAGER.CPP
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:12k
源码类别:

SNMP编程

开发平台:

C/C++

  1. // Cool3DWndManager.cpp: implementation of the CCool3DWndManager class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Oam.h"
  6. #include "Cool3DWndManager.h"
  7. #include "memDC.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. SIZE _sizeMiniSys;
  17. CDibList imgBoader;
  18. CDibList imgCaption;
  19. AFX_STATIC void AFXAPI
  20. DrawFrameEx(CDC* dc, LPCRECT lpRect, int nWidth, int nHeight, CDibList & img)
  21. {
  22. CRect rect;
  23. // left stile
  24. rect = *lpRect;
  25. int nCount = rect.Height()/nHeight;
  26. for(int i = 0; i<nCount ;i++)
  27. {
  28. img.Draw(dc,0,CPoint(rect.left,rect.top+i*nHeight),ILD_NORMAL & ~ILD_TRANSPARENT);
  29. }
  30. // for(i = 0; i< rect.Width()/nWidth;i++)
  31. // {
  32. // img.Draw(dc,8,CPoint(rect.left+i*nWidth,rect.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  33. // }
  34. nCount = rect.Height()/nHeight;
  35. for(i = 0; i< nCount;i++)
  36. {
  37. img.Draw(dc,4,CPoint(rect.right-nWidth,rect.top+i*nHeight),ILD_NORMAL & ~ILD_TRANSPARENT);
  38. }
  39. nCount = rect.Width()/nWidth;
  40. for(i = 0; i< nCount;i++)
  41. {
  42. img.Draw(dc,3,CPoint(rect.left+i*nWidth,rect.bottom-nHeight),ILD_NORMAL & ~ILD_TRANSPARENT);
  43. }
  44. // img.Draw(dc,7,rect.TopLeft(),ILD_NORMAL & ~ILD_TRANSPARENT);
  45. // img.Draw(dc,9,CPoint(rect.right-5,rect.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  46. img.Draw(dc,6,CPoint(rect.right-10,rect.bottom-10),ILD_NORMAL & ~ILD_TRANSPARENT);
  47. img.Draw(dc,2,CPoint(rect.left,rect.bottom-10),ILD_NORMAL & ~ILD_TRANSPARENT);
  48. }
  49. void DrawLlxNcRect(CDC &dc,CRect rcAll, CString strTitle,LONG dwStyle,BOOL bActive)
  50. {
  51. CRect rect = rcAll,rectCaption;
  52. rect.OffsetRect(-rect.left, -rect.top);
  53. // CMemDCEx dc(&theDC,rect,CRect(10,_sizeMiniSys.cy,10,10));
  54. CSize sizeBorder(GetSystemMetrics(SM_CXBORDER),
  55. GetSystemMetrics(SM_CYBORDER));
  56. CSize sizeFrame(GetSystemMetrics(SM_CXFRAME),
  57. GetSystemMetrics(SM_CYFRAME));
  58. CBrush brCaption;
  59. brCaption.CreateSolidBrush(::GetSysColor(bActive ?
  60. COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
  61. // Draw the caption.  Remove it from rect.
  62. if (dwStyle & WS_CAPTION)
  63. {
  64. rectCaption = rect;
  65. rectCaption.bottom = rectCaption.top + _sizeMiniSys.cy + sizeBorder.cy;
  66. CLLXMemDC * pDCEx = new CLLXMemDC(&dc,rectCaption);
  67. int nBase = bActive ? 0 : 8;
  68. pDCEx->FillRect(rectCaption,&brCaption);
  69. imgCaption.Draw(pDCEx,nBase+0,rectCaption.TopLeft(),ILD_NORMAL & ~ILD_TRANSPARENT);
  70. imgCaption.Draw(pDCEx,nBase+1,CPoint(rectCaption.left+30,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  71. imgCaption.Draw(pDCEx,nBase+2,CPoint(rectCaption.left+60,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  72. for(int i = 0; i<rectCaption.Width()/30-6; i++)
  73. {
  74. imgCaption.Draw(pDCEx,nBase+3,CPoint(rectCaption.left+90+i*30,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  75. }
  76. imgCaption.Draw(pDCEx,nBase+4,CPoint(rectCaption.right - 120,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  77. i++;
  78. imgCaption.Draw(pDCEx,nBase+5,CPoint(rectCaption.right - 90,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  79. i++;
  80. imgCaption.Draw(pDCEx,nBase+6,CPoint(rectCaption.right - 60,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  81. i++;
  82. imgCaption.Draw(pDCEx,nBase+7,CPoint(rectCaption.right - 30,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  83. if(dwStyle & WS_MAXIMIZEBOX)
  84. {
  85. if(dwStyle & WS_MAXIMIZE)
  86. imgCaption.Draw(pDCEx,16,CPoint(rectCaption.right - 47,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  87. else
  88. imgCaption.Draw(pDCEx,17,CPoint(rectCaption.right - 47,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  89. }
  90. if(dwStyle & WS_MINIMIZEBOX)
  91. imgCaption.Draw(pDCEx,18,CPoint(rectCaption.right - 62,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
  92. {
  93. HFONT hFontOld = (HFONT)pDCEx->SelectObject(m_fontSys);//_afx_hfontMiniSys);
  94. int xLeft = rectCaption.left +
  95. (dwStyle & WS_SYSMENU ? _sizeMiniSys.cx : 0);
  96. CSize sizeText = pDCEx->GetTextExtent(strTitle, strTitle.GetLength());
  97. if (sizeText.cx <= rectCaption.Width())
  98. {
  99. pDCEx->SetTextAlign(TA_CENTER);
  100. xLeft += (rectCaption.right - xLeft) / 2;
  101. }
  102. TEXTMETRIC tm;
  103. VERIFY(pDCEx->GetTextMetrics(&tm));
  104. int yHeight = tm.tmAscent + tm.tmDescent + tm.tmInternalLeading;
  105. rectCaption.InflateRect(0, 1);
  106. int yHeightDiff = (rectCaption.Height() - yHeight + 1) / 2;
  107. pDCEx->SetTextColor(::GetSysColor(bActive ?
  108. COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
  109. pDCEx->SetBkMode(TRANSPARENT);
  110. pDCEx->ExtTextOut(xLeft, rectCaption.top + yHeightDiff, ETO_CLIPPED,
  111. rectCaption, strTitle, strTitle.GetLength(), NULL);
  112. pDCEx->SelectObject(hFontOld);
  113. }
  114. rect.top = rectCaption.bottom;
  115. delete pDCEx;
  116. }
  117. rect = rcAll;
  118. rect.OffsetRect(-rect.left, -rect.top);
  119. rect.top += _sizeMiniSys.cy;
  120. DrawFrameEx(&dc, rect, 10,
  121. 10, imgBoader);
  122. }
  123. CCool3DWndManager::CCool3DWndManager()
  124. {
  125. m_pWnd = NULL;
  126. m_bActive = FALSE;
  127. m_bInSys = 0;
  128. m_bLimitMin = TRUE;
  129. if(imgBoader.m_hImageList == NULL)
  130. imgBoader.Load("borders.bmp",7,RGB(255,0,255));
  131. if(imgCaption.m_hImageList == NULL)
  132. {
  133. imgCaption.Load("captionbar.bmp",19,RGB(255,0,255));
  134. _sizeMiniSys.cx = imgCaption.GetEverySize().cx;//bmStruct.bmWidth;
  135. _sizeMiniSys.cy = imgCaption.GetEverySize().cy;//bmStruct.bmHeight;
  136. }
  137. }
  138. CCool3DWndManager::~CCool3DWndManager()
  139. {
  140. HookWindow((HWND)NULL); // (unhook)
  141. }
  142. LRESULT CCool3DWndManager::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
  143. {
  144. if(imgBoader.m_hImageList == NULL || imgCaption.m_hImageList == NULL)
  145. {
  146. return CSubclassWnd::WindowProc(msg, wp, lp);
  147. }
  148. switch(msg) {
  149. case WM_NCACTIVATE:
  150. return OnNcActivate(wp);
  151. break;
  152. case WM_NCCALCSIZE:
  153. {
  154. OnNcCalcSize(wp,(LPNCCALCSIZE_PARAMS) lp);
  155. return TRUE; // handled
  156. break;
  157. }
  158. case WM_NCPAINT:
  159. OnNcPaint();
  160. return TRUE; // handled
  161. break;
  162. case WM_NCLBUTTONDOWN:
  163. OnNcLButtonDown((INT) wp,CPoint(MAKEPOINTS(lp).x,MAKEPOINTS(lp).y));
  164. return TRUE; // handled
  165. break;
  166. case WM_GETMINMAXINFO:
  167. OnGetMinMaxInfo((LPMINMAXINFO) lp);
  168. return TRUE; // handled
  169. break;
  170. case WM_NCLBUTTONUP:
  171. OnNcLButtonUp((INT) wp,CPoint(MAKEPOINTS(lp).x,MAKEPOINTS(lp).y));
  172. return TRUE; // handled
  173. break;
  174. case WM_ACTIVATE:
  175. OnActivate(LOWORD(wp),CWnd::FromHandle((HWND) lp),(BOOL) HIWORD(wp)); 
  176. return TRUE; // handled
  177. break;
  178. case WM_SIZE:
  179. break;
  180. case WM_INITDIALOG :
  181. return OnInitDialog();
  182. break;
  183. }
  184. return CSubclassWnd::WindowProc(msg, wp, lp);
  185. }
  186. void CCool3DWndManager::Install(CWnd *pWnd)
  187. {
  188. if(m_pWnd)
  189. HookWindow((HWND)NULL);
  190. ASSERT_VALID(pWnd);
  191. m_pWnd = pWnd;
  192. HookWindow(pWnd);   // install message hook
  193. }
  194. void CCool3DWndManager::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
  195. {
  196. //
  197. LONG dwStyle = m_pWnd->GetStyle();
  198. if (dwStyle & (MFS_4THICKFRAME | WS_THICKFRAME | MFS_THICKFRAME))
  199. {
  200. ::InflateRect(lpClientRect,
  201. GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME));
  202. }
  203. else
  204. {
  205. ::InflateRect(lpClientRect,
  206. GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
  207. }
  208. if (dwStyle & WS_CAPTION)
  209. lpClientRect->top -= _sizeMiniSys.cy;
  210. }
  211. void CCool3DWndManager::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  212. {
  213. Default();
  214. // TODO: Add your message handler code here
  215. if (WA_INACTIVE != nState && !m_bActive)// && pWndOther && (!IsChild(pWndOther) && !(pWndOther ==  this)))
  216. {
  217. m_bActive = TRUE;
  218. m_pWnd->SendMessage(WM_NCPAINT);
  219. }
  220. else if(WA_INACTIVE == nState && m_bActive)//&& pWndOther && (IsChild(pWndOther) || pWndOther ==  this))
  221. {
  222. m_bActive = FALSE;
  223. m_pWnd->SendMessage(WM_NCPAINT);
  224. }
  225. }
  226. BOOL CCool3DWndManager::OnNcActivate(BOOL bActive)
  227. {
  228. return TRUE;
  229. }
  230. void CCool3DWndManager::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS *lpncsp)
  231. {
  232. LONG dwStyle = m_pWnd->GetStyle();
  233. if (
  234. m_pWnd->IsKindOf(RUNTIME_CLASS(CDialog))
  235. ||
  236. (dwStyle & (MFS_4THICKFRAME | MFS_THICKFRAME | WS_THICKFRAME))
  237. )
  238. {
  239. ::InflateRect(lpncsp->rgrc,
  240. -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME));
  241. }
  242. else if(!m_pWnd->IsKindOf(RUNTIME_CLASS(CDialog)))
  243. {
  244. ::InflateRect(lpncsp->rgrc,
  245. -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
  246. }
  247. if (dwStyle & WS_CAPTION)
  248. lpncsp->rgrc[0].top += _sizeMiniSys.cy;
  249. if(bCalcValidRects)
  250. {
  251. lpncsp->rgrc[0].top = lpncsp->lppos->y + _sizeMiniSys.cy;
  252. lpncsp->rgrc[0].left += 6;
  253. lpncsp->rgrc[0].bottom -= 6;
  254. lpncsp->rgrc[0].right -= 6;
  255. }
  256. }
  257. void CCool3DWndManager::OnNcLButtonDown(UINT nHitTest, CPoint point)
  258. {
  259. if (nHitTest != HTZOOM && nHitTest !=HTMAXBUTTON  
  260. && nHitTest !=HTGROWBOX && nHitTest != HTCLOSE
  261. && nHitTest !=HTMINBUTTON)
  262. {
  263. Default();
  264. return;
  265. }
  266. m_bInSys = nHitTest;
  267. m_bSysTracking = TRUE;
  268. }
  269. void CCool3DWndManager::OnNcLButtonUp(UINT nHitTest, CPoint point)
  270. {
  271. if (!m_bSysTracking)
  272. {
  273. Default();
  274. return;
  275. }
  276. m_bSysTracking = FALSE;
  277. m_pWnd->ClientToScreen(&point);
  278. UINT aa = m_pWnd->SendMessage(WM_NCHITTEST ,point.x,point.y);
  279. if (nHitTest == m_bInSys)
  280. {
  281. switch (nHitTest)
  282. {
  283. case HTZOOM:
  284. if(m_pWnd->GetStyle() & WS_MAXIMIZE)
  285. m_pWnd->SendMessage(WM_SYSCOMMAND,SC_RESTORE  ,0);
  286. else
  287. m_pWnd->SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE ,0);
  288. break;
  289. case HTSIZE:
  290. m_pWnd->SendMessage(WM_SYSCOMMAND,SC_MINIMIZE ,0);
  291. break;
  292. case HTCLOSE:
  293. m_pWnd->SendMessage(WM_SYSCOMMAND,SC_CLOSE ,0);
  294. break;
  295. case HTMINBUTTON:
  296. m_pWnd->SendMessage(WM_SYSCOMMAND,SC_MINIMIZE ,0);
  297. break;
  298. }
  299. }
  300. }
  301. void CCool3DWndManager::OnNcPaint()
  302. {
  303. CWindowDC dc(m_pWnd);
  304. LONG dwStyle = m_pWnd->GetStyle();
  305. CRect rect;
  306. m_pWnd->GetWindowRect(&rect);
  307. CString strTitle;
  308. m_pWnd->GetWindowText(strTitle);
  309. DrawLlxNcRect(dc,rect,strTitle,dwStyle,m_bActive);
  310. }
  311. void CCool3DWndManager::OnSize(UINT nType, int cx, int cy)
  312. {
  313. }
  314. void CCool3DWndManager::OnGetMinMaxInfo(MINMAXINFO *lpMMI)
  315. {
  316. Default(); // don't allow sizing smaller than the non-client area
  317. CRect rectWindow, rectClient;
  318. m_pWnd->GetWindowRect(rectWindow);
  319. m_pWnd->GetClientRect(rectClient);
  320. lpMMI->ptMinTrackSize.x = rectWindow.Width() - rectClient.right;
  321. lpMMI->ptMinTrackSize.y = rectWindow.Height() - rectClient.bottom;
  322. int nOffsetX = 10 - GetSystemMetrics(SM_CXBORDER) - GetSystemMetrics(SM_CXFRAME);
  323. int nOffsetY = 10 - GetSystemMetrics(SM_CYBORDER) - GetSystemMetrics(SM_CYFRAME);
  324. lpMMI->ptMaxPosition.x = 0;//+= (nOffsetX-1);
  325. lpMMI->ptMaxPosition.y = 0;//+= (nOffsetX-1);
  326. lpMMI->ptMaxSize.x  = GetSystemMetrics(SM_CXSCREEN);//-= nOffsetX;
  327. lpMMI->ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);//-= nOffsetY;
  328. lpMMI->ptMaxTrackSize.x  = GetSystemMetrics(SM_CXSCREEN);//-= nOffsetX;
  329. lpMMI->ptMaxTrackSize.y  = GetSystemMetrics(SM_CYSCREEN);//-= nOffsetY;
  330. if(!m_bLimitMin)
  331. {
  332. lpMMI->ptMinTrackSize.x = 300;
  333. lpMMI->ptMinTrackSize.y = 50;
  334. }
  335. else if(m_pWnd->IsKindOf(RUNTIME_CLASS(CDialog)))
  336. {
  337. lpMMI->ptMinTrackSize.x = 300;
  338. lpMMI->ptMinTrackSize.y = 200;
  339. }
  340. else
  341. {
  342. lpMMI->ptMinTrackSize.x = 640;
  343. lpMMI->ptMinTrackSize.y = 480;
  344. }
  345. }
  346. BOOL CCool3DWndManager::OnInitDialog()
  347. {
  348. Default();
  349. CRect rect;
  350. m_pWnd->GetWindowRect(&rect);
  351. rect.InflateRect(6,6);
  352. m_pWnd->MoveWindow(rect,TRUE);
  353. m_pWnd->CenterWindow();
  354. return TRUE;
  355. }
  356. void CCool3DWndManager::UnInstall()
  357. {
  358. HookWindow((HWND)NULL); // (unhook)
  359. }
  360. BOOL CCool3DWndManager::LimitMin(BOOL bLimit)
  361. {
  362. BOOL ret = m_bLimitMin;
  363. m_bLimitMin = bLimit;
  364. return ret;
  365. }