COOL3DWNDMANAGER.CPP
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:12k
- // Cool3DWndManager.cpp: implementation of the CCool3DWndManager class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Oam.h"
- #include "Cool3DWndManager.h"
- #include "memDC.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- SIZE _sizeMiniSys;
- CDibList imgBoader;
- CDibList imgCaption;
- AFX_STATIC void AFXAPI
- DrawFrameEx(CDC* dc, LPCRECT lpRect, int nWidth, int nHeight, CDibList & img)
- {
- CRect rect;
- // left stile
- rect = *lpRect;
- int nCount = rect.Height()/nHeight;
- for(int i = 0; i<nCount ;i++)
- {
- img.Draw(dc,0,CPoint(rect.left,rect.top+i*nHeight),ILD_NORMAL & ~ILD_TRANSPARENT);
- }
- // for(i = 0; i< rect.Width()/nWidth;i++)
- // {
- // img.Draw(dc,8,CPoint(rect.left+i*nWidth,rect.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- // }
- nCount = rect.Height()/nHeight;
- for(i = 0; i< nCount;i++)
- {
- img.Draw(dc,4,CPoint(rect.right-nWidth,rect.top+i*nHeight),ILD_NORMAL & ~ILD_TRANSPARENT);
- }
- nCount = rect.Width()/nWidth;
- for(i = 0; i< nCount;i++)
- {
- img.Draw(dc,3,CPoint(rect.left+i*nWidth,rect.bottom-nHeight),ILD_NORMAL & ~ILD_TRANSPARENT);
- }
- // img.Draw(dc,7,rect.TopLeft(),ILD_NORMAL & ~ILD_TRANSPARENT);
- // img.Draw(dc,9,CPoint(rect.right-5,rect.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- img.Draw(dc,6,CPoint(rect.right-10,rect.bottom-10),ILD_NORMAL & ~ILD_TRANSPARENT);
- img.Draw(dc,2,CPoint(rect.left,rect.bottom-10),ILD_NORMAL & ~ILD_TRANSPARENT);
- }
- void DrawLlxNcRect(CDC &dc,CRect rcAll, CString strTitle,LONG dwStyle,BOOL bActive)
- {
- CRect rect = rcAll,rectCaption;
- rect.OffsetRect(-rect.left, -rect.top);
- // CMemDCEx dc(&theDC,rect,CRect(10,_sizeMiniSys.cy,10,10));
- CSize sizeBorder(GetSystemMetrics(SM_CXBORDER),
- GetSystemMetrics(SM_CYBORDER));
- CSize sizeFrame(GetSystemMetrics(SM_CXFRAME),
- GetSystemMetrics(SM_CYFRAME));
- CBrush brCaption;
- brCaption.CreateSolidBrush(::GetSysColor(bActive ?
- COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
- // Draw the caption. Remove it from rect.
- if (dwStyle & WS_CAPTION)
- {
- rectCaption = rect;
- rectCaption.bottom = rectCaption.top + _sizeMiniSys.cy + sizeBorder.cy;
- CLLXMemDC * pDCEx = new CLLXMemDC(&dc,rectCaption);
- int nBase = bActive ? 0 : 8;
- pDCEx->FillRect(rectCaption,&brCaption);
- imgCaption.Draw(pDCEx,nBase+0,rectCaption.TopLeft(),ILD_NORMAL & ~ILD_TRANSPARENT);
- imgCaption.Draw(pDCEx,nBase+1,CPoint(rectCaption.left+30,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- imgCaption.Draw(pDCEx,nBase+2,CPoint(rectCaption.left+60,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- for(int i = 0; i<rectCaption.Width()/30-6; i++)
- {
- imgCaption.Draw(pDCEx,nBase+3,CPoint(rectCaption.left+90+i*30,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- }
- imgCaption.Draw(pDCEx,nBase+4,CPoint(rectCaption.right - 120,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- i++;
- imgCaption.Draw(pDCEx,nBase+5,CPoint(rectCaption.right - 90,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- i++;
- imgCaption.Draw(pDCEx,nBase+6,CPoint(rectCaption.right - 60,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- i++;
- imgCaption.Draw(pDCEx,nBase+7,CPoint(rectCaption.right - 30,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- if(dwStyle & WS_MAXIMIZEBOX)
- {
- if(dwStyle & WS_MAXIMIZE)
- imgCaption.Draw(pDCEx,16,CPoint(rectCaption.right - 47,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- else
- imgCaption.Draw(pDCEx,17,CPoint(rectCaption.right - 47,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- }
- if(dwStyle & WS_MINIMIZEBOX)
- imgCaption.Draw(pDCEx,18,CPoint(rectCaption.right - 62,rectCaption.top),ILD_NORMAL & ~ILD_TRANSPARENT);
- {
- HFONT hFontOld = (HFONT)pDCEx->SelectObject(m_fontSys);//_afx_hfontMiniSys);
- int xLeft = rectCaption.left +
- (dwStyle & WS_SYSMENU ? _sizeMiniSys.cx : 0);
- CSize sizeText = pDCEx->GetTextExtent(strTitle, strTitle.GetLength());
- if (sizeText.cx <= rectCaption.Width())
- {
- pDCEx->SetTextAlign(TA_CENTER);
- xLeft += (rectCaption.right - xLeft) / 2;
- }
- TEXTMETRIC tm;
- VERIFY(pDCEx->GetTextMetrics(&tm));
- int yHeight = tm.tmAscent + tm.tmDescent + tm.tmInternalLeading;
- rectCaption.InflateRect(0, 1);
- int yHeightDiff = (rectCaption.Height() - yHeight + 1) / 2;
- pDCEx->SetTextColor(::GetSysColor(bActive ?
- COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
- pDCEx->SetBkMode(TRANSPARENT);
- pDCEx->ExtTextOut(xLeft, rectCaption.top + yHeightDiff, ETO_CLIPPED,
- rectCaption, strTitle, strTitle.GetLength(), NULL);
- pDCEx->SelectObject(hFontOld);
- }
- rect.top = rectCaption.bottom;
- delete pDCEx;
- }
- rect = rcAll;
- rect.OffsetRect(-rect.left, -rect.top);
- rect.top += _sizeMiniSys.cy;
- DrawFrameEx(&dc, rect, 10,
- 10, imgBoader);
- }
- CCool3DWndManager::CCool3DWndManager()
- {
- m_pWnd = NULL;
- m_bActive = FALSE;
- m_bInSys = 0;
- m_bLimitMin = TRUE;
- if(imgBoader.m_hImageList == NULL)
- imgBoader.Load("borders.bmp",7,RGB(255,0,255));
- if(imgCaption.m_hImageList == NULL)
- {
- imgCaption.Load("captionbar.bmp",19,RGB(255,0,255));
- _sizeMiniSys.cx = imgCaption.GetEverySize().cx;//bmStruct.bmWidth;
- _sizeMiniSys.cy = imgCaption.GetEverySize().cy;//bmStruct.bmHeight;
- }
- }
- CCool3DWndManager::~CCool3DWndManager()
- {
- HookWindow((HWND)NULL); // (unhook)
- }
- LRESULT CCool3DWndManager::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
- {
- if(imgBoader.m_hImageList == NULL || imgCaption.m_hImageList == NULL)
- {
- return CSubclassWnd::WindowProc(msg, wp, lp);
- }
- switch(msg) {
- case WM_NCACTIVATE:
- return OnNcActivate(wp);
- break;
- case WM_NCCALCSIZE:
- {
- OnNcCalcSize(wp,(LPNCCALCSIZE_PARAMS) lp);
- return TRUE; // handled
- break;
- }
- case WM_NCPAINT:
- OnNcPaint();
- return TRUE; // handled
- break;
- case WM_NCLBUTTONDOWN:
- OnNcLButtonDown((INT) wp,CPoint(MAKEPOINTS(lp).x,MAKEPOINTS(lp).y));
- return TRUE; // handled
- break;
- case WM_GETMINMAXINFO:
- OnGetMinMaxInfo((LPMINMAXINFO) lp);
- return TRUE; // handled
- break;
- case WM_NCLBUTTONUP:
- OnNcLButtonUp((INT) wp,CPoint(MAKEPOINTS(lp).x,MAKEPOINTS(lp).y));
- return TRUE; // handled
- break;
- case WM_ACTIVATE:
- OnActivate(LOWORD(wp),CWnd::FromHandle((HWND) lp),(BOOL) HIWORD(wp));
- return TRUE; // handled
- break;
- case WM_SIZE:
- break;
- case WM_INITDIALOG :
- return OnInitDialog();
- break;
- }
- return CSubclassWnd::WindowProc(msg, wp, lp);
- }
- void CCool3DWndManager::Install(CWnd *pWnd)
- {
- if(m_pWnd)
- HookWindow((HWND)NULL);
- ASSERT_VALID(pWnd);
- m_pWnd = pWnd;
- HookWindow(pWnd); // install message hook
- }
- void CCool3DWndManager::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
- {
- //
- LONG dwStyle = m_pWnd->GetStyle();
- if (dwStyle & (MFS_4THICKFRAME | WS_THICKFRAME | MFS_THICKFRAME))
- {
- ::InflateRect(lpClientRect,
- GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME));
- }
- else
- {
- ::InflateRect(lpClientRect,
- GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
- }
- if (dwStyle & WS_CAPTION)
- lpClientRect->top -= _sizeMiniSys.cy;
- }
- void CCool3DWndManager::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
- {
- Default();
-
- // TODO: Add your message handler code here
- if (WA_INACTIVE != nState && !m_bActive)// && pWndOther && (!IsChild(pWndOther) && !(pWndOther == this)))
- {
- m_bActive = TRUE;
- m_pWnd->SendMessage(WM_NCPAINT);
- }
- else if(WA_INACTIVE == nState && m_bActive)//&& pWndOther && (IsChild(pWndOther) || pWndOther == this))
- {
- m_bActive = FALSE;
- m_pWnd->SendMessage(WM_NCPAINT);
- }
- }
- BOOL CCool3DWndManager::OnNcActivate(BOOL bActive)
- {
- return TRUE;
- }
- void CCool3DWndManager::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS *lpncsp)
- {
- LONG dwStyle = m_pWnd->GetStyle();
- if (
- m_pWnd->IsKindOf(RUNTIME_CLASS(CDialog))
- ||
- (dwStyle & (MFS_4THICKFRAME | MFS_THICKFRAME | WS_THICKFRAME))
- )
- {
- ::InflateRect(lpncsp->rgrc,
- -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME));
- }
- else if(!m_pWnd->IsKindOf(RUNTIME_CLASS(CDialog)))
- {
- ::InflateRect(lpncsp->rgrc,
- -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
- }
- if (dwStyle & WS_CAPTION)
- lpncsp->rgrc[0].top += _sizeMiniSys.cy;
- if(bCalcValidRects)
- {
- lpncsp->rgrc[0].top = lpncsp->lppos->y + _sizeMiniSys.cy;
- lpncsp->rgrc[0].left += 6;
- lpncsp->rgrc[0].bottom -= 6;
- lpncsp->rgrc[0].right -= 6;
- }
- }
- void CCool3DWndManager::OnNcLButtonDown(UINT nHitTest, CPoint point)
- {
- if (nHitTest != HTZOOM && nHitTest !=HTMAXBUTTON
- && nHitTest !=HTGROWBOX && nHitTest != HTCLOSE
- && nHitTest !=HTMINBUTTON)
- {
- Default();
- return;
- }
- m_bInSys = nHitTest;
- m_bSysTracking = TRUE;
- }
- void CCool3DWndManager::OnNcLButtonUp(UINT nHitTest, CPoint point)
- {
- if (!m_bSysTracking)
- {
- Default();
- return;
- }
- m_bSysTracking = FALSE;
- m_pWnd->ClientToScreen(&point);
- UINT aa = m_pWnd->SendMessage(WM_NCHITTEST ,point.x,point.y);
- if (nHitTest == m_bInSys)
- {
- switch (nHitTest)
- {
- case HTZOOM:
- if(m_pWnd->GetStyle() & WS_MAXIMIZE)
- m_pWnd->SendMessage(WM_SYSCOMMAND,SC_RESTORE ,0);
- else
- m_pWnd->SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE ,0);
- break;
- case HTSIZE:
- m_pWnd->SendMessage(WM_SYSCOMMAND,SC_MINIMIZE ,0);
- break;
- case HTCLOSE:
- m_pWnd->SendMessage(WM_SYSCOMMAND,SC_CLOSE ,0);
- break;
- case HTMINBUTTON:
- m_pWnd->SendMessage(WM_SYSCOMMAND,SC_MINIMIZE ,0);
- break;
- }
-
- }
- }
- void CCool3DWndManager::OnNcPaint()
- {
- CWindowDC dc(m_pWnd);
- LONG dwStyle = m_pWnd->GetStyle();
- CRect rect;
- m_pWnd->GetWindowRect(&rect);
- CString strTitle;
- m_pWnd->GetWindowText(strTitle);
- DrawLlxNcRect(dc,rect,strTitle,dwStyle,m_bActive);
- }
- void CCool3DWndManager::OnSize(UINT nType, int cx, int cy)
- {
- }
- void CCool3DWndManager::OnGetMinMaxInfo(MINMAXINFO *lpMMI)
- {
- Default(); // don't allow sizing smaller than the non-client area
- CRect rectWindow, rectClient;
- m_pWnd->GetWindowRect(rectWindow);
- m_pWnd->GetClientRect(rectClient);
- lpMMI->ptMinTrackSize.x = rectWindow.Width() - rectClient.right;
- lpMMI->ptMinTrackSize.y = rectWindow.Height() - rectClient.bottom;
- int nOffsetX = 10 - GetSystemMetrics(SM_CXBORDER) - GetSystemMetrics(SM_CXFRAME);
- int nOffsetY = 10 - GetSystemMetrics(SM_CYBORDER) - GetSystemMetrics(SM_CYFRAME);
- lpMMI->ptMaxPosition.x = 0;//+= (nOffsetX-1);
- lpMMI->ptMaxPosition.y = 0;//+= (nOffsetX-1);
- lpMMI->ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);//-= nOffsetX;
- lpMMI->ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);//-= nOffsetY;
- lpMMI->ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);//-= nOffsetX;
- lpMMI->ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);//-= nOffsetY;
- if(!m_bLimitMin)
- {
- lpMMI->ptMinTrackSize.x = 300;
- lpMMI->ptMinTrackSize.y = 50;
- }
- else if(m_pWnd->IsKindOf(RUNTIME_CLASS(CDialog)))
- {
- lpMMI->ptMinTrackSize.x = 300;
- lpMMI->ptMinTrackSize.y = 200;
- }
- else
- {
- lpMMI->ptMinTrackSize.x = 640;
- lpMMI->ptMinTrackSize.y = 480;
- }
- }
- BOOL CCool3DWndManager::OnInitDialog()
- {
- Default();
- CRect rect;
- m_pWnd->GetWindowRect(&rect);
- rect.InflateRect(6,6);
- m_pWnd->MoveWindow(rect,TRUE);
- m_pWnd->CenterWindow();
- return TRUE;
- }
- void CCool3DWndManager::UnInstall()
- {
- HookWindow((HWND)NULL); // (unhook)
- }
- BOOL CCool3DWndManager::LimitMin(BOOL bLimit)
- {
- BOOL ret = m_bLimitMin;
- m_bLimitMin = bLimit;
- return ret;
- }