CustomTabCtrl.cpp
上传用户:huashan618
上传日期:2013-03-26
资源大小:261k
文件大小:74k
- /**********************************************************************
- **
- ** CustomTabCtrl.cpp : implementation file of CCustomTabCtrl class
- **
- ** by Andrzej Markowski June 2004
- **
- ** teazlemoon add it's funcation,in oct 2005
- ** 在本代码段中,去除了修改TAB键上的编辑标志功能,增加了GDI+的相关内容
- ** 处理按钮的透明色绘制、视图窗口的建立和管理部分
- **********************************************************************/
- #include "stdafx.h"
- #include "CustomTabCtrl.h"
- #include "resource.h"
- #ifndef _GDIPLUS_USED
- #include <gdiplus.h>
- #include ".customtabctrl.h"
- #pragma comment(lib,"gdiplus.lib")
- using namespace Gdiplus;
- #endif
- // CCustomTabCtrlItem
- ULONG_PTR g_token;
- CCustomTabCtrlItem::CCustomTabCtrlItem(CString sText,/*LPARAM*/CWnd* lParam) :
- m_sText(sText),
- m_lParam(lParam),
- m_bShape(TAB_SHAPE1),
- m_fSelected(FALSE),
- m_fHighlighted(FALSE),
- m_fHighlightChanged(FALSE),
- m_OpenURL(FALSE)
- {
- GdiplusStartupInput start;
- GdiplusStartup(&g_token,&start,NULL);
- }
- void CCustomTabCtrlItem::operator=(const CCustomTabCtrlItem &other)
- {
- m_sText = other.m_sText;
- m_lParam = other.m_lParam;
- }
- void CCustomTabCtrlItem::ComputeRgn()
- {
- m_rgn.DeleteObject();
- CPoint pts[6];
- GetRegionPoints(m_rect,pts);
- m_rgn.CreatePolygonRgn(pts, 6, WINDING);
- }
- void CCustomTabCtrlItem::GetRegionPoints(const CRect& rc, CPoint* pts) const
- {
- switch(m_bShape)
- {
- case TAB_SHAPE2:
- {
- pts[0] = rc.TopLeft();
- pts[1] = CPoint(rc.left, rc.bottom);
- pts[2] = CPoint(rc.left + rc.Height()/2, rc.top);
- pts[3] = CPoint(rc.left + rc.Height()/2, rc.top);
- pts[4] = CPoint(rc.left + rc.Height()/2, rc.top);
- pts[5] = CPoint(rc.left + rc.Height()/2, rc.top);
- }
- break;
- case TAB_SHAPE3:
- {
- pts[0] = rc.TopLeft();
- pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
- pts[2] = CPoint(rc.left, rc.bottom);
- pts[3] = CPoint(rc.left, rc.bottom);
- pts[4] = CPoint(rc.left, rc.bottom);
- pts[5] = CPoint(rc.left, rc.bottom);
- }
- break;
- case TAB_SHAPE4:
- {
- pts[0] = rc.TopLeft();
- pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
- pts[2] = CPoint(rc.left + rc.Height()/2, rc.bottom);
- pts[3] = CPoint(rc.right - rc.Height()/2, rc.bottom);
- pts[4] = CPoint(rc.right - rc.Height()/4, rc.Height()/2);
- pts[5] = CPoint(rc.right, rc.top);
- }
- break;
- case TAB_SHAPE5:
- {
- pts[0] = rc.TopLeft();
- pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
- pts[2] = CPoint(rc.left + rc.Height()/2 , rc.bottom);
- pts[3] = CPoint(rc.right - rc.Height()/2, rc.bottom);
- pts[4] = CPoint(rc.right - rc.Height()/4, rc.Height()/2);
- pts[5] = CPoint(rc.right - rc.Height()/2, rc.top);
- }
- break;
- default:
- {
- pts[0] = CPoint(0,0);
- pts[1] = CPoint(0,0);
- pts[2] = CPoint(0,0);
- pts[3] = CPoint(0,0);
- pts[4] = CPoint(0,0);
- pts[5] = CPoint(0,0);
- }
- break;
- }
- }
- void CCustomTabCtrlItem::GetDrawPoints(const CRect& rc, CPoint* pts) const
- {
- switch(m_bShape)
- {
- case TAB_SHAPE2:
- case TAB_SHAPE3:
- {
- pts[0] = CPoint(rc.left, rc.bottom);
- pts[1] = CPoint(rc.left + rc.Height()/2, rc.top);
- }
- break;
- case TAB_SHAPE4:
- case TAB_SHAPE5:
- {
- pts[0] = rc.TopLeft();
- pts[1] = CPoint(rc.left + rc.Height()/2, rc.bottom);
- pts[2] = CPoint(rc.right - rc.Height()/2, rc.bottom);
- pts[3] = CPoint(rc.right, rc.top);
- }
- break;
- }
- }
- //绘制TAB项,在这里,使用GDI+的一些方面,实现颜色渐变和半透明
- void CCustomTabCtrlItem::Draw(CDC& dc, CFont& font)
- {
- //设置前景和背景色
- COLORREF bgColor = GetSysColor((m_fSelected||m_fHighlighted) ? COLOR_WINDOW : COLOR_3DFACE);
- COLORREF fgColor = GetSysColor((m_fSelected ||m_fHighlighted) ? COLOR_WINDOWTEXT : COLOR_BTNTEXT);
- //COLORREF bgColor=RGB(255,128,128);
- // COLORREF fgColor=RGB(0,0,0);
- dc.SetBkMode(TRANSPARENT);
- Graphics graph(dc.m_hDC);
- CRect rect;
- m_rgn.GetRgnBox(&rect);
- LinearGradientBrush linbrush(Point(rect.left,rect.top),Point(rect.left,rect.bottom),
- Color(255,192,214,192),Color(198,128,128,128));
- Region reg((HRGN)m_rgn);
- graph.FillRegion(&linbrush,®);
- //CBrush brush(RGB(128,168,128));//(bgColor);
- //设置TAB框线的颜色
- // CPen blackPen(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
- // CPen shadowPen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
- CPen blackPen(PS_SOLID, 2, RGB(64,0,0));
- CPen shadowPen(PS_SOLID, 2, RGB(0,0,128));
- CPoint pts[4];
- CRect rc = m_rect;
- GetDrawPoints(rc, pts);
-
- // Paint item background
- //dc.FillRgn(&m_rgn, &brush);
- CPen* pOldPen = dc.SelectObject(&blackPen);
- // draw item
- switch(m_bShape)
- {
- case TAB_SHAPE2:
- case TAB_SHAPE3:
- {
- dc.MoveTo(pts[0]);
- dc.LineTo(pts[1]);
-
- if(!m_fSelected)
- {
- dc.SelectObject(&shadowPen);
- dc.MoveTo(pts[0].x-1,pts[0].y);
- dc.LineTo(pts[1].x-1,pts[1].y);
- }
- }
- break;
- case TAB_SHAPE4:
- case TAB_SHAPE5:
- {
- dc.MoveTo(pts[0]);
- dc.LineTo(pts[1]);
-
- dc.SelectObject(&shadowPen);
- dc.LineTo(pts[2]);
-
- if(!m_fSelected)
- {
- dc.MoveTo(pts[2].x-1,pts[2].y);
- dc.LineTo(pts[3].x-1,pts[3].y);
- }
- dc.SelectObject(&blackPen);
- dc.MoveTo(pts[2]);
- dc.LineTo(pts[3]);
- // draw item text
- COLORREF bgOldColor = dc.SetBkColor(bgColor);
- COLORREF fgOldColor = dc.SetTextColor(fgColor);
- rc.DeflateRect(rc.Height()/2, 2,rc.Height()/2,2);
- CFont* pOldFont = dc.SelectObject(&font);
- dc.DrawText(m_sText, &rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
- dc.SelectObject(pOldFont);
- dc.SetTextColor(fgOldColor);
- dc.SetBkColor(bgOldColor);
- }
- break;
- }
- dc.SelectObject(pOldPen);
- }
- // CCustomTabCtrl
- LOGFONT CCustomTabCtrl::lf_default = {14, 0, 0, 0, FW_NORMAL, 0, 0, 0,
- DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Microsoft Sans Serif"};
- BYTE CCustomTabCtrl::m_bBitsGlyphs[] = {0xBD,0xFB,0xDF,0xBD,
- 0xB9,0xF3,0xCF,0x9D,
- 0xB1,0xE3,0xC7,0x8D,
- 0xA3,0xC7,0xE3,0xC5,
- 0xB1,0xE3,0xC7,0x8D,
- 0xB9,0xF3,0xCF,0x9D,
- 0xBD,0xFB,0xDF,0xBD};
- CCustomTabCtrl::CCustomTabCtrl() :
- m_nButtonIDDown(CTCID_NOBUTTON),
- m_nPrevState(BNST_INVISIBLE),
- m_nNextState(BNST_INVISIBLE),
- m_nFirstState(BNST_INVISIBLE),
- m_nLastState(BNST_INVISIBLE),
- m_nItemSelected(-1),
- m_nItemNdxOffset(0),
- m_dwLastRepeatTime(0),
- m_hBmpBkLeftSpin(NULL),
- m_hBmpBkRightSpin(NULL),
- m_hCursorMove(NULL),
- m_hCursorCopy(NULL),
- m_nItemDragDest(0)
- {
- RegisterWindowClass();
- SetControlFont(GetDefaultFont());
- m_bmpGlyphsMono.CreateBitmap(32,7,1,1,m_bBitsGlyphs);
- m_rClient.SetRect(0,0,0,0);
- m_hSwitch=DEF_SWITCH_HEIGHT;
- // m_orgial=FALSE;
- m_oldwnd=NULL;
- }
- // Register the window class if it has not already been registered.
- BOOL CCustomTabCtrl::RegisterWindowClass()
- {
- WNDCLASS wndcls;
- HINSTANCE hInst = AfxGetInstanceHandle();
- if (!(::GetClassInfo(hInst, CustomTabCtrl_CLASSNAME, &wndcls)))
- {
- wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
- wndcls.lpfnWndProc = ::DefWindowProc;
- wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
- wndcls.hInstance = hInst;
- wndcls.hIcon = NULL;
- wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
- wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
- wndcls.lpszMenuName = NULL;
- wndcls.lpszClassName = CustomTabCtrl_CLASSNAME;
- if (!AfxRegisterClass(&wndcls))
- {
- AfxThrowResourceException();
- return FALSE;
- }
- }
- return TRUE;
- }
- CCustomTabCtrl::~CCustomTabCtrl()
- {
- for(int i=0; i< m_aItems.GetSize(); i++)
- {
- CCustomTabCtrlItem* pItem =(CCustomTabCtrlItem*)m_aItems.GetAt(i);
- ((CIEView*)pItem->m_lParam)->SendMessage(WM_DESTROY);
- delete m_aItems[i];
- }
- m_aItems.RemoveAll();
- ::DeleteObject(m_hBmpBkLeftSpin);
- m_hBmpBkLeftSpin = NULL;
- ::DeleteObject(m_hBmpBkRightSpin);
- m_hBmpBkRightSpin = NULL;
- ::DestroyCursor(m_hCursorMove);
- m_hCursorMove = NULL;
- ::DestroyCursor(m_hCursorCopy);
- m_hCursorCopy = NULL;
- GdiplusShutdown(g_token);
- }
- BEGIN_MESSAGE_MAP(CCustomTabCtrl, CWnd)
- //{{AFX_MSG_MAP(CCustomTabCtrl)
- ON_WM_ERASEBKGND()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
- ON_MESSAGE(THM_WM_THEMECHANGED,OnThemeChanged)
- ON_WM_MOUSEMOVE()
- ON_WM_PAINT()
- ON_WM_SIZE()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- // ON_WM_NCRBUTTONDOWN()
- //ON_WM_RBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- END_MESSAGE_MAP()
- // CCustomTabCtrl message handlers
- BOOL CCustomTabCtrl::Create(UINT dwStyle, const CRect & rect, CWnd * pParentWnd, UINT nID)
- {
- m_rClient=rect;
- dwStyle|=WS_BORDER;
- if(m_rClient.Height()>m_hSwitch)
- {
- m_rClient.bottom=m_rClient.bottom-m_hSwitch-DEF_STOWND_LENGTH;
-
- }
- CRect switchrect;
- switchrect.SetRect(rect.left,rect.bottom-m_hSwitch,rect.right,rect.bottom);
- return CWnd::Create(CustomTabCtrl_CLASSNAME, _T(""), dwStyle, switchrect, pParentWnd, nID);
- }
- BOOL CCustomTabCtrl::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- }
- void CCustomTabCtrl::OnPaint()
- {
- CPaintDC dc(this);
- if(!m_hBmpBkLeftSpin)
- {
- m_rgbGlyph[0] =RGB(0,0,255);// GetSysColor(COLOR_BTNTEXT);切换按钮平常箭头色
- m_rgbGlyph[1] =RGB(255,0,0);// GetSysColor(COLOR_BTNTEXT);切换按钮在MOUSE位于其上箭头色
- m_rgbGlyph[2] =RGB(0,0,192);// GetSysColor(COLOR_BTNTEXT);
- m_rgbGlyph[3] =RGB(0,255,0);// GetSysColor(COLOR_BTNTEXT);
- }
- CRect rCl;
- GetClientRect(&rCl);
- // CPen blackPen(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
- //绘制按钮边框的颜色
- CPen blackPen(PS_SOLID, 2, RGB(0,0,128));
- CDC dcMem;
- CBitmap bmpMem;
- CBitmap* pOldBmp=NULL;
- if(dcMem.CreateCompatibleDC(&dc))
- {
- if(bmpMem.CreateCompatibleBitmap(&dc,rCl.Width(),rCl.Height()))
- pOldBmp = dcMem.SelectObject(&bmpMem);
- else
- return;
- }
- else
- return;
- int nBtns = 2;
- if(GetStyle()&CTCS_FOURBUTTONS)
- nBtns = 4;
- {
- // clear background
- // dcMem.FillSolidRect(&rCl,GetSysColor(COLOR_BTNFACE));
- dcMem.FillSolidRect(&rCl,RGB(192,192,255));
- }
- {
- // 以下部分绘制按钮
- if(m_nPrevState && m_nNextState)
- {
- int nA = rCl.Height()-3;
- CRect rAll(0,1,nBtns*nA+3,rCl.Height());
- CRect rFirst,rPrev,rNext,rLast;
- if(nBtns==2)
- {
- rPrev.SetRect(1,2,nA+1,rCl.Height()-1);
- rNext.SetRect(nA+2,2,2*nA+2,rCl.Height()-1);
- }
- else
- {
- rFirst.SetRect(1,2,nA+1,rCl.Height()-1);
- rPrev.SetRect(nA+1,2,2*nA+1,rCl.Height()-1);
- rNext.SetRect(2*nA+2,2,3*nA+2,rCl.Height()-1);
- rLast.SetRect(3*nA+2,2,4*nA+2,rCl.Height()-1);
- }
- CPen* pOldPen = dcMem.SelectObject(&blackPen);
- dcMem.Rectangle(rAll);
- dcMem.SelectObject(pOldPen);
- if(nBtns==4)
- {
- CPoint ptFirst(rFirst.left+(rFirst.Width()-8)/2,rFirst.top+(rFirst.Height()-7)/2);
- if(m_hBmpBkLeftSpin)
- DrawBkLeftSpin(dcMem,rFirst,m_nFirstState-1);
- else
- {
- if(m_nFirstState==BNST_PRESSED)//绘制指向TAB第一个项
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rFirst.left,rFirst.top),Point(rFirst.left,rFirst.bottom),
- Color(128,192,64,64),Color(255,128,64,64));
- graph.FillRectangle(&linbrush,rFirst.left,rFirst.top,rFirst.Width(),rFirst.Height());
- dcMem.DrawEdge(&rFirst,BDR_SUNKENOUTER,BF_RECT);
- // dcMem.DrawFrameControl(rFirst,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
- }
- else
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rFirst.left,rFirst.top),Point(rFirst.left,rFirst.bottom),
- Color(128,255,128,128),Color(255,192,64,64));
- graph.FillRectangle(&linbrush,rFirst.left,rFirst.top,rFirst.Width(),rFirst.Height());
- dcMem.DrawEdge(&rFirst,BDR_RAISEDOUTER,BF_RECT);
- //dcMem.DrawFrameControl(rFirst,DFC_BUTTON,DFCS_BUTTONPUSH);
- }
- }
- DrawGlyph(dcMem,ptFirst,0,m_nFirstState-1);
- CPoint ptLast(rLast.left+(rLast.Width()-8)/2,rLast.top+(rLast.Height()-7)/2);
- if(m_hBmpBkRightSpin)
- DrawBkRightSpin(dcMem,rLast,m_nLastState-1);
- else//绘制TAB最后一个项按钮
- {
- if(m_nLastState==BNST_PRESSED)
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rLast.left,rLast.top),Point(rLast.left,rLast.bottom),
- Color(128,192,64,64),Color(255,128,64,64));
- // rPrev.InflateRect(1,1,-1,-1);
- graph.FillRectangle(&linbrush,rLast.left+1,rLast.top+1,rLast.Width()-2,rLast.Height()-2);
- dcMem.DrawEdge(&rLast,BDR_SUNKENOUTER,BF_RECT);
- // dcMem.DrawFrameControl(rLast,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
- }
- else
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rLast.left,rLast.top),Point(rLast.left,rLast.bottom),
- Color(128,255,128,128),Color(255,192,64,64));
- graph.FillRectangle(&linbrush,rLast.left,rLast.top,rLast.Width(),rLast.Height());
- dcMem.DrawEdge(&rLast,BDR_RAISEDOUTER,BF_RECT);
- // dcMem.DrawFrameControl(rLast,DFC_BUTTON,DFCS_BUTTONPUSH);
- }
- }
- DrawGlyph(dcMem,ptLast,3,m_nLastState-1);
- }
- CPoint ptPrev(rPrev.left+(rPrev.Width()-8)/2,rPrev.top+(rPrev.Height()-7)/2);
- if(m_hBmpBkLeftSpin)
- DrawBkLeftSpin(dcMem,rPrev,m_nPrevState-1);
- else//以下绘制TAB向前的按钮
- {
- if(m_nPrevState==BNST_PRESSED)
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rPrev.left,rPrev.top),Point(rPrev.left,rPrev.bottom),
- Color(128,192,64,64),Color(255,128,64,64));
- // rPrev.InflateRect(1,1,-1,-1);
- graph.FillRectangle(&linbrush,rPrev.left,rPrev.top,rPrev.Width(),rPrev.Height());
- dcMem.DrawEdge(&rPrev,BDR_SUNKENOUTER,BF_RECT);
- //dcMem.DrawFrameControl(rPrev,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
- }
- else
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rPrev.left,rPrev.top),Point(rPrev.left,rPrev.bottom),
- Color(128,255,128,128),Color(255,192,64,64));
- graph.FillRectangle(&linbrush,rPrev.left,rPrev.top,rPrev.Width(),rPrev.Height());
- dcMem.DrawEdge(&rPrev,BDR_RAISEDOUTER,BF_RECT);
- // dcMem.DrawFrameControl(rPrev,DFC_BUTTON,DFCS_BUTTONPUSH);
- }
- }
- DrawGlyph(dcMem,ptPrev,1,m_nPrevState-1);
- CPoint ptNext(rNext.left+(rNext.Width()-8)/2,rNext.top+(rNext.Height()-7)/2);
- if(m_hBmpBkRightSpin)
- DrawBkRightSpin(dcMem,rNext,m_nNextState-1);
- else//以下绘制下一个TAB的按钮
- {
- rNext.left -= 1;
- if(m_nNextState==BNST_PRESSED)
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rNext.left,rNext.top),Point(rNext.left,rNext.bottom),
- Color(128,192,64,64),Color(255,128,64,64));
- graph.FillRectangle(&linbrush,rNext.left,rNext.top,rNext.Width(),rNext.Height());
- dcMem.DrawEdge(&rNext,BDR_SUNKENOUTER,BF_RECT);
- // dcMem.DrawFocusRect(&rNext);
- //dcMem.DrawFrameControl(rNext,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
- }
- else
- {
- Graphics graph(dcMem.m_hDC);
- LinearGradientBrush linbrush(Point(rNext.left,rNext.top),Point(rNext.left,rNext.bottom),
- Color(128,255,128,128),Color(255,192,64,64));
- graph.FillRectangle(&linbrush,rNext.left,rNext.top,rNext.Width(),rNext.Height());
- dcMem.DrawEdge(&rNext,BDR_RAISEDOUTER,BF_RECT);
- // dcMem.Draw3dRect(rNext.left,rNext.top,rNext.Width(),rNext.Height(),RGB(255,0,0),RGB(0,255,0));
- // dcMem.DrawFrameControl(rNext,DFC_BUTTON,DFCS_BUTTONPUSH);
- }
- }
- DrawGlyph(dcMem,ptNext,2,m_nNextState-1);
- }
- }
- {
- // draw tab items visible and not selected
- //绘制TAB项中可见但为非选的项
- for(int i= 0; i<m_aItems.GetSize(); i++)
- {
- if(m_aItems[i]->m_bShape && !m_aItems[i]->m_fSelected)
- {
- if(m_aItems[i]->m_fHighlighted)
- m_aItems[i]->Draw(dcMem,m_FontSelected);
- else
- m_aItems[i]->Draw(dcMem,m_Font);
- }
- }
- // draw selected tab item
- if(m_nItemSelected!=-1 && m_aItems[m_nItemSelected]->m_bShape)
- m_aItems[m_nItemSelected]->Draw(dcMem,m_FontSelected);
-
- }
- {
- // draw black lines
- int nOffsetX = 0;
- if(m_nPrevState && m_nNextState)
- nOffsetX = nBtns*(rCl.Height()-3)+3;
- CPoint pts[4];
- if(m_nItemSelected==-1)
- {
- pts[0] = CPoint(nOffsetX,1);
- pts[1] = CPoint(nOffsetX,1);
- pts[2] = CPoint(nOffsetX,1);
- pts[3] = CPoint(rCl.right,1);
- }
- else
- {
- if(m_aItems[m_nItemSelected]->m_bShape)
- {
- pts[0] = CPoint(nOffsetX,1);
- pts[1] = CPoint(m_aItems[m_nItemSelected]->m_rect.left,1);
- pts[2] = CPoint(m_aItems[m_nItemSelected]->m_rect.right,1);
- pts[3] = CPoint(rCl.right,1);
- }
- else
- {
- pts[0] = CPoint(nOffsetX,1);
- pts[1] = CPoint(nOffsetX,1);
- pts[2] = CPoint(nOffsetX,1);
- pts[3] = CPoint(rCl.right,1);
- }
- }
-
- CPen* pOldPen = dcMem.SelectObject(&blackPen);
- dcMem.MoveTo(pts[0]);
- dcMem.LineTo(pts[1]);
- dcMem.MoveTo(pts[2]);
- dcMem.LineTo(pts[3]);
- dcMem.SelectObject(pOldPen);
-
- }
- {
- if(m_nButtonIDDown>=0 &&
- (GetCursor()==m_hCursorMove || GetCursor()==m_hCursorCopy))
- {
- // Draw drag destination marker
- CPen* pOldPen = dcMem.SelectObject(&blackPen);
- int x;
- if(m_nItemDragDest==m_aItems.GetSize())
- x= m_aItems[m_nItemDragDest-1]->m_rectText.right + rCl.Height()/4-3;
- else
- x= m_aItems[m_nItemDragDest]->m_rectText.left - rCl.Height()/4-3;
- if(x>=rCl.right-7)
- x = rCl.right-7;
- dcMem.MoveTo(x,1);
- dcMem.LineTo(x+7,1);
- dcMem.MoveTo(x+1,2);
- dcMem.LineTo(x+6,2);
- dcMem.MoveTo(x+2,3);
- dcMem.LineTo(x+5,3);
- dcMem.MoveTo(x+3,4);
- dcMem.LineTo(x+4,4);
- }
- }
- dc.BitBlt(rCl.left,
- rCl.top,
- rCl.Width(),
- rCl.Height(),
- &dcMem,
- rCl.left,
- rCl.top,
- SRCCOPY);
- dcMem.SelectObject(pOldBmp);
- }
- void CCustomTabCtrl::OnSize(UINT nType, int cx, int cy)
- {
- CWnd::OnSize(nType, cx, cy);
- if(cx && cy)
- RecalcLayout(RECALC_RESIZED, m_nItemSelected);
- }
- void CCustomTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
- {
- int nHitTest = HitTest(point);
- NotifyParent(CTCN_CLICK,nHitTest,point);//发送消息到父窗口
- ProcessLButtonDown(nHitTest,nFlags,point);//处理按下左端按钮
- CWnd::OnLButtonDown(nFlags,point);
- }
- /*void CCustomTabCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- int nHTRet = ProcessLButtonDown(HitTest(point),nFlags,point);
- if(nHTRet>=0)
- {
- m_nButtonIDDown = CTCID_NOBUTTON;
- // if(nHTRet==HitTest(point))
- // EditLabel(nHTRet,TRUE);
- }
- CWnd::OnLButtonDblClk(nFlags, point);
- }*/
- //按下左键后,执行相应的操作首先处理前面切换视图的按钮,是移到第一视图、
- int CCustomTabCtrl::ProcessLButtonDown(int nHitTest, UINT nFlags, CPoint point)
- {
- SetCapture();
- switch(nHitTest)
- {
- case CTCHT_NOWHERE:
- m_nButtonIDDown = CTCID_NOBUTTON;
- break;
- case CTCHT_ONFIRSTBUTTON://移到第一个视图
- {
- m_nButtonIDDown = CTCID_FIRSTBUTTON;
- m_nFirstState = BNST_PRESSED;
- RecalcLayout(RECALC_FIRST_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- SetTimer(1,100,NULL);
- }
- break;
- case CTCHT_ONPREVBUTTON://切换到前一个视图
- {
- m_nButtonIDDown = CTCID_PREVBUTTON;
- m_nPrevState = BNST_PRESSED;
- RecalcLayout(RECALC_PREV_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- SetTimer(1,100,NULL);
- }
- break;
- case CTCHT_ONNEXTBUTTON://切换到下一个视图
- {
- m_nButtonIDDown = CTCID_NEXTBUTTON;
- m_nNextState = BNST_PRESSED;
- RecalcLayout(RECALC_NEXT_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- SetTimer(1,100,NULL);
- }
- break;
- case CTCHT_ONLASTBUTTON://切换到最后一个视图
- {
- m_nButtonIDDown = CTCID_LASTBUTTON;
- m_nLastState = BNST_PRESSED;
- RecalcLayout(RECALC_LAST_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- SetTimer(1,100,NULL);
- }
- break;
- default:
- {
- DWORD dwStyle = GetStyle();
- if(((dwStyle&CTCS_DRAGMOVE) && !(nFlags&MK_CONTROL) && m_hCursorMove) ||
- ((dwStyle&CTCS_DRAGCOPY) && (nFlags&MK_CONTROL) && m_hCursorCopy))
- {
- m_nButtonIDDown = nHitTest;
- m_nItemDragDest = nHitTest;
- SetTimer(2,300,NULL);
- }
- else
- m_nButtonIDDown = CTCID_NOBUTTON;
- if((GetStyle()&CTCS_MULTIHIGHLIGHT) && (nFlags&MK_CONTROL))
- HighlightItem(nHitTest,TRUE,nFlags&MK_CONTROL);
- else
- {
- BOOL bNotify = nHitTest!=m_nItemSelected;
- SetCurSel(nHitTest,TRUE,nFlags&MK_CONTROL);
- if(bNotify)
- NotifyParent(CTCN_SELCHANGE,m_nItemSelected,point);
- }
- for(int i=0; i<m_aItems.GetSize();i++)
- {
- if(m_aItems[i]->m_fHighlightChanged)
- NotifyParent(CTCN_HIGHLIGHTCHANGE,i,point);
- }
- }
- break;
- }
- return nHitTest;
- }
- //处理按钮消息,并将相应的按钮消息发送到父窗口,以便对TAB窗口的切换作出响应
- BOOL CCustomTabCtrl::NotifyParent(UINT code, int nItem, CPoint pt)
- {
- CTC_NMHDR nmh;
- memset(&nmh,0,sizeof(CTC_NMHDR));
- nmh.hdr.hwndFrom = GetSafeHwnd();
- nmh.hdr.idFrom = GetDlgCtrlID();
- nmh.hdr.code = code;
- nmh.nItem = nItem;
- nmh.ptHitTest = pt;
- if(nItem>=0)
- {
- _tcscpy(nmh.pszText,m_aItems[nItem]->m_sText);
- nmh.lParam = m_aItems[nItem]->m_lParam;
- nmh.rItem = m_aItems[nItem]->m_rectText;
- nmh.fSelected = m_aItems[nItem]->m_fSelected;
- nmh.fHighlighted = m_aItems[nItem]->m_fHighlighted;
- if(code==CTCN_SELCHANGE)
- {
-
- if(m_oldwnd)
- {
- SwitchWindows(DYNAMIC_DOWNCAST( CView, nmh.lParam));
- m_oldwnd=nmh.lParam;
- }
- }
- }
- //在这里选中的窗口发送消息,作出相应的处理
- //在这里,对应多个窗口,将选中的窗口设定为活动或禁止
- //CString inf;
- // inf.Format("显示当前窗口的索引号为:%d",nItem);
- // CDC* pDC=GetParent()->GetDC();
- // pDC->FillRect(&m_rClient,&CBrush(RGB(255,224,224)));
- // pDC->SetBkMode(TRANSPARENT);
- // pDC->DrawText(inf,&m_rClient,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
- // ReleaseDC(pDC);
- //////////////////////////////
- return (BOOL)GetParent()->SendMessage(WM_NOTIFY,GetDlgCtrlID(),(LPARAM)&nmh);
- }
- void CCustomTabCtrl::OnLButtonUp(UINT nFlags, CPoint point)
- {
- if(m_nPrevState || m_nNextState || m_nFirstState || m_nLastState)
- {
- m_nPrevState = BNST_NORMAL;
- m_nNextState = BNST_NORMAL;
- m_nFirstState = BNST_NORMAL;
- m_nLastState = BNST_NORMAL;
- Invalidate(FALSE);
- KillTimer(1);
- }
- if(m_nButtonIDDown>=0)
- {
- if((GetCursor()==m_hCursorCopy) && (GetKeyState(VK_CONTROL)&0x8000))
- CopyItem(m_nButtonIDDown,m_nItemDragDest, TRUE);
- else if((GetCursor()==m_hCursorMove) && !(GetKeyState(VK_CONTROL)&0x8000))
- MoveItem(m_nButtonIDDown,m_nItemDragDest, TRUE);
- }
- m_nButtonIDDown = CTCID_NOBUTTON;
- ReleaseCapture();
- }
- void CCustomTabCtrl::OnMouseMove(UINT nFlags, CPoint point)
- {
- TRACKMOUSEEVENT trackmouseevent;
- trackmouseevent.cbSize = sizeof(trackmouseevent);
- trackmouseevent.dwFlags = TME_LEAVE;
- trackmouseevent.hwndTrack = GetSafeHwnd();
- trackmouseevent.dwHoverTime = 0;
- _TrackMouseEvent(&trackmouseevent);
- CRect rCl;
- GetClientRect(&rCl);
- int nBtns = 2;
- if(GetStyle()&CTCS_FOURBUTTONS)
- nBtns = 4;
- int nA = rCl.Height()-3;
- CRect rFirst,rPrev,rNext,rLast;
- if(nBtns==2)
- {
- rPrev.SetRect(0,0,nA+1,rCl.Height());
- rNext.SetRect(nA+1,0,2*nA+3,rCl.Height());
- }
- else
- {
- rFirst.SetRect(0,0,nA+1,rCl.Height());
- rPrev.SetRect(nA+1,0,2*nA+1,rCl.Height());
- rNext.SetRect(2*nA+1,0,3*nA+2,rCl.Height());
- rLast.SetRect(3*nA+2,0,4*nA+3,rCl.Height());
- }
- if(nBtns==4 && m_nFirstState)
- {
- if(rFirst.PtInRect(point))
- {
- if(m_nButtonIDDown==CTCID_FIRSTBUTTON)
- m_nFirstState = BNST_PRESSED;
- else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
- m_nFirstState = BNST_HOT;
- else
- m_nFirstState = BNST_NORMAL;
- }
- else
- m_nFirstState = BNST_NORMAL;
- Invalidate(FALSE);
- }
- if(m_nPrevState)
- {
- if(rPrev.PtInRect(point))
- {
- if(m_nButtonIDDown==CTCID_PREVBUTTON)
- m_nPrevState = BNST_PRESSED;
- else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
- m_nPrevState = BNST_HOT;
- else
- m_nPrevState = BNST_NORMAL;
- }
- else
- m_nPrevState = BNST_NORMAL;
- Invalidate(FALSE);
- }
- if(m_nNextState)
- {
- if(rNext.PtInRect(point))
- {
- if(m_nButtonIDDown==CTCID_NEXTBUTTON)
- m_nNextState = BNST_PRESSED;
- else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
- m_nNextState = BNST_HOT;
- else
- m_nNextState = BNST_NORMAL;
- }
- else
- m_nNextState = BNST_NORMAL;
- Invalidate(FALSE);
- }
- if(nBtns==4 && m_nLastState)
- {
- if(rLast.PtInRect(point))
- {
- if(m_nButtonIDDown==CTCID_LASTBUTTON)
- m_nLastState = BNST_PRESSED;
- else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
- m_nLastState = BNST_HOT;
- else
- m_nLastState = BNST_NORMAL;
- }
- else
- m_nLastState = BNST_NORMAL;
- Invalidate(FALSE);
- }
- if(m_nButtonIDDown>=0)
- {
- if(m_nItemDragDest>=(int)m_aItems.GetSize())
- m_nItemDragDest = (int)m_aItems.GetSize()-1;
- int x1 = m_aItems[m_nItemDragDest]->m_rectText.left - rCl.Height()/4;
- int x2 = m_aItems[m_nItemDragDest]->m_rectText.right + rCl.Height()/4;
- if(point.x>=rCl.right)
- {
- m_nItemDragDest++;
- if(m_nItemDragDest>=m_aItems.GetSize())
- RecalcLayout(RECALC_NEXT_PRESSED,(int)m_aItems.GetSize()-1);
- else
- RecalcLayout(RECALC_NEXT_PRESSED,m_nItemDragDest);
- Invalidate(FALSE);
- }
- else if(point.x>=x2)
- {
- m_nItemDragDest++;
- if(m_nItemDragDest>=(int)m_aItems.GetSize())
- RecalcLayout(RECALC_ITEM_SELECTED,(int)m_aItems.GetSize()-1);
- else
- RecalcLayout(RECALC_ITEM_SELECTED,m_nItemDragDest);
- Invalidate(FALSE);
- }
- else if(point.x<x1)
- {
- if(m_nItemDragDest>0)
- m_nItemDragDest--;
-
- RecalcLayout(RECALC_ITEM_SELECTED,m_nItemDragDest);
- Invalidate(FALSE);
- }
- }
- }
- LONG CCustomTabCtrl::OnMouseLeave(WPARAM wParam, LPARAM lParam)
- {
- if(m_nPrevState || m_nNextState)
- {
- m_nPrevState = BNST_NORMAL;
- m_nNextState = BNST_NORMAL;
- m_nFirstState = BNST_NORMAL;
- m_nLastState = BNST_NORMAL;
- Invalidate(FALSE);
- KillTimer(1);
- }
- return 0;
- }
- /*void CCustomTabCtrl::OnUpdateEdit()
- {
- if(m_ctrlEdit.m_hWnd)
- {
- m_ctrlEdit.GetWindowText(m_aItems[m_nItemSelected]->m_sText);
- RecalcLayout(RECALC_EDIT_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- }
- }*/
- LONG CCustomTabCtrl::OnThemeChanged(WPARAM wParam, LPARAM lParam)
- {
- ::DeleteObject(m_hBmpBkLeftSpin);
- m_hBmpBkLeftSpin = NULL;
- ::DeleteObject(m_hBmpBkRightSpin);
- m_hBmpBkRightSpin = NULL;
- HBITMAP hBmpGlyph = NULL;
- CDC dcGlyph;
- dcGlyph.CreateCompatibleDC(NULL);
- CBitmap* pOldBmpGlyph = NULL;
- try
- {
- CThemeUtil tm;
- if(!tm.OpenThemeData(m_hWnd, L"SPIN"))
- AfxThrowUserException();
- {
- // left spin background
- int nBkType;
- if(!tm.GetThemeEnumValue(SPNP_DOWNHORZ,0,TMT_BGTYPE,&nBkType))
- AfxThrowUserException();
- if(nBkType!=BT_IMAGEFILE)
- AfxThrowUserException();
- int nImageCount;
- if(!tm.GetThemeInt(SPNP_DOWNHORZ,0,TMT_IMAGECOUNT,&nImageCount))
- AfxThrowUserException();
- if(nImageCount!=4)
- AfxThrowUserException();
- WCHAR szSpinBkLeftBitmapFilename[MAX_PATH];
- if(!tm.GetThemeFilename(SPNP_DOWNHORZ,0,TMT_IMAGEFILE,szSpinBkLeftBitmapFilename,MAX_PATH))
- AfxThrowUserException();
- if(!(m_hBmpBkLeftSpin = tm.LoadBitmap(szSpinBkLeftBitmapFilename)))
- AfxThrowUserException();
- int nLeftImageLayout;
- if(!tm.GetThemeEnumValue(SPNP_DOWNHORZ,0,TMT_IMAGELAYOUT,&nLeftImageLayout))
- AfxThrowUserException();
- if(nLeftImageLayout==IL_VERTICAL)
- m_fIsLeftImageHorLayout = FALSE;
- else
- m_fIsLeftImageHorLayout = TRUE;
-
- if(!tm.GetThemeMargins(SPNP_DOWNHORZ,0,TMT_SIZINGMARGINS,&m_mrgnLeft))
- AfxThrowUserException();
- }
- {
- // right spin background
- int nBkType;
- if(!tm.GetThemeEnumValue(SPNP_UPHORZ,0,TMT_BGTYPE,&nBkType))
- AfxThrowUserException();
- if(nBkType!=BT_IMAGEFILE)
- AfxThrowUserException();
- int nImageCount;
- if(!tm.GetThemeInt(SPNP_UPHORZ,0,TMT_IMAGECOUNT,&nImageCount))
- AfxThrowUserException();
- if(nImageCount!=4)
- AfxThrowUserException();
- WCHAR szSpinBkRightBitmapFilename[MAX_PATH];
- if(!tm.GetThemeFilename(SPNP_UPHORZ,0,TMT_IMAGEFILE,szSpinBkRightBitmapFilename,MAX_PATH))
- AfxThrowUserException();
- if(!(m_hBmpBkRightSpin = tm.LoadBitmap(szSpinBkRightBitmapFilename)))
- AfxThrowUserException();
-
- int nRightImageLayout;
- if(!tm.GetThemeEnumValue(SPNP_UPHORZ,0,TMT_IMAGELAYOUT,&nRightImageLayout))
- AfxThrowUserException();
- if(nRightImageLayout==IL_VERTICAL)
- m_fIsRightImageHorLayout = FALSE;
- else
- m_fIsRightImageHorLayout = TRUE;
- if(!tm.GetThemeMargins(SPNP_UPHORZ,0,TMT_SIZINGMARGINS,&m_mrgnRight))
- AfxThrowUserException();
- }
- {
- // glyph color
- int nGlyphType;
- if(!tm.GetThemeEnumValue(SPNP_DOWNHORZ,0,TMT_GLYPHTYPE,&nGlyphType))
- AfxThrowUserException();
-
- if(nGlyphType==GT_IMAGEGLYPH)
- {
- COLORREF rgbTransGlyph = RGB(255,0,255);
- if(!tm.GetThemeColor(SPNP_DOWNHORZ,0,TMT_GLYPHTRANSPARENTCOLOR,&rgbTransGlyph))
- AfxThrowUserException();
- WCHAR szSpinGlyphIconFilename[MAX_PATH];
- if(!tm.GetThemeFilename(SPNP_DOWNHORZ,0,TMT_GLYPHIMAGEFILE,szSpinGlyphIconFilename,MAX_PATH))
- AfxThrowUserException();
- if(!(hBmpGlyph = tm.LoadBitmap(szSpinGlyphIconFilename)))
- AfxThrowUserException();
- CBitmap* pBmp = CBitmap::FromHandle(hBmpGlyph);
- if(pBmp==NULL)
- AfxThrowUserException();
- pOldBmpGlyph = dcGlyph.SelectObject(pBmp);
- BITMAP bm;
- pBmp->GetBitmap(&bm);
- m_rgbGlyph[0] = rgbTransGlyph;
- m_rgbGlyph[1] = rgbTransGlyph;
- m_rgbGlyph[2] = rgbTransGlyph;
- m_rgbGlyph[3] = rgbTransGlyph;
- if(m_fIsLeftImageHorLayout)
- {
- for(int i=0;i<bm.bmWidth;i++)
- {
- if(i<bm.bmWidth/4 && m_rgbGlyph[0]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmHeight;j++)
- {
- if((m_rgbGlyph[0]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
- break;
- }
- if(i==bm.bmWidth/4-1 && m_rgbGlyph[0]==rgbTransGlyph)
- AfxThrowUserException();
- }
- else if(i>=bm.bmWidth/4 && i<bm.bmWidth/2 && m_rgbGlyph[1]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmHeight;j++)
- {
- if((m_rgbGlyph[1]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
- break;
- }
- if(i==bm.bmWidth/2-1 && m_rgbGlyph[1]==rgbTransGlyph)
- AfxThrowUserException();
- }
- else if(i>=bm.bmWidth/2 && i<3*bm.bmWidth/4 && m_rgbGlyph[2]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmHeight;j++)
- {
- if((m_rgbGlyph[2]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
- break;
- }
- if(i==3*bm.bmWidth/4-1 && m_rgbGlyph[2]==rgbTransGlyph)
- AfxThrowUserException();
- }
- else if(i>=3*bm.bmWidth/4 && i<bm.bmWidth && m_rgbGlyph[3]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmHeight;j++)
- {
- if((m_rgbGlyph[3]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
- break;
- }
- if(i==bm.bmWidth-1 && m_rgbGlyph[3]==rgbTransGlyph)
- AfxThrowUserException();
- }
- }
- }
- else
- {
- for(int i=0;i<bm.bmHeight;i++)
- {
- if(i<bm.bmHeight/4 && m_rgbGlyph[0]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmWidth;j++)
- {
- if((m_rgbGlyph[0] = dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
- break;
- }
- if(i==bm.bmHeight/4-1 && m_rgbGlyph[0]==rgbTransGlyph)
- AfxThrowUserException();
- }
- else if(i>=bm.bmHeight/4 && i<bm.bmHeight/2 && m_rgbGlyph[1]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmWidth;j++)
- {
- if((m_rgbGlyph[1]=dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
- break;
- }
- if(i==bm.bmHeight/2-1 && m_rgbGlyph[1]==rgbTransGlyph)
- AfxThrowUserException();
- }
- else if(i>=bm.bmHeight/2 && i<3*bm.bmHeight/4 && m_rgbGlyph[2]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmWidth;j++)
- {
- if((m_rgbGlyph[2] = dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
- break;
- }
- if(i==3*bm.bmHeight/4-1 && m_rgbGlyph[2]==rgbTransGlyph)
- AfxThrowUserException();
- }
- else if(i>=3*bm.bmHeight/4 && i<bm.bmHeight && m_rgbGlyph[3]==rgbTransGlyph)
- {
- for(int j=0;j<bm.bmWidth;j++)
- {
- if((m_rgbGlyph[3]=dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
- break;
- }
- if(i==bm.bmHeight-1 && m_rgbGlyph[3]==rgbTransGlyph)
- AfxThrowUserException();
- }
- }
- }
- dcGlyph.SelectObject(pOldBmpGlyph);
- pOldBmpGlyph = NULL;
- ::DeleteObject(hBmpGlyph);
- hBmpGlyph = NULL;
- }
- else if(nGlyphType==GT_FONTGLYPH)
- {
- if(!tm.GetThemeColor(SPNP_UPHORZ,UPHZS_NORMAL,TMT_GLYPHTEXTCOLOR,&m_rgbGlyph[0]))
- AfxThrowUserException();
- if(!tm.GetThemeColor(SPNP_UPHORZ,UPHZS_HOT,TMT_GLYPHTEXTCOLOR,&m_rgbGlyph[1]))
- AfxThrowUserException();
- if(!tm.GetThemeColor(SPNP_UPHORZ,UPHZS_PRESSED,TMT_GLYPHTEXTCOLOR,&m_rgbGlyph[2]))
- AfxThrowUserException();
- }
- else
- AfxThrowUserException();
- }
- }
- catch(CUserException* e)
- {
- e->Delete();
- ::DeleteObject(m_hBmpBkLeftSpin);
- m_hBmpBkLeftSpin = NULL;
- ::DeleteObject(m_hBmpBkRightSpin);
- m_hBmpBkRightSpin = NULL;
- if(pOldBmpGlyph)
- dcGlyph.SelectObject(pOldBmpGlyph);
- ::DeleteObject(hBmpGlyph);
- hBmpGlyph = NULL;
- }
- return 0;
- }
- void CCustomTabCtrl::OnTimer(UINT nIDEvent)
- {
- CWnd::OnTimer(nIDEvent);
- if(nIDEvent==1)
- {
- if(m_nFirstState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
- {
- m_nFirstState = BNST_PRESSED;
- RecalcLayout(RECALC_FIRST_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- return;
- }
- if(m_nPrevState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
- {
- m_nPrevState = BNST_PRESSED;
- RecalcLayout(RECALC_PREV_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- return;
- }
- if(m_nNextState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
- {
- m_nNextState = BNST_PRESSED;
- RecalcLayout(RECALC_NEXT_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- return;
- }
- if(m_nLastState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
- {
- m_nLastState = BNST_PRESSED;
- RecalcLayout(RECALC_LAST_PRESSED,m_nItemSelected);
- Invalidate(FALSE);
- m_dwLastRepeatTime = ::GetTickCount();
- return;
- }
- }
- else if(nIDEvent==2)
- {
- KillTimer(2);
- if(m_nButtonIDDown>=0)
- {
- SetTimer(2,10,NULL);
- DWORD dwStyle = GetStyle();
- if((dwStyle&CTCS_DRAGCOPY) && (GetKeyState(VK_CONTROL)&0x8000))
- SetCursor(m_hCursorCopy);
- else if((dwStyle&CTCS_DRAGMOVE) && !(GetKeyState(VK_CONTROL)&0x8000))
- SetCursor(m_hCursorMove);
- else
- {
- m_nButtonIDDown = CTCID_NOBUTTON;
- ReleaseCapture();
- }
- Invalidate(FALSE);
- }
- }
- }
- void CCustomTabCtrl::SetControlFont(const LOGFONT& lf, BOOL fRedraw)
- {
- if(m_Font.m_hObject)
- {
- DeleteObject(m_Font);
- m_Font.m_hObject = NULL;
- }
- if(m_FontSelected.m_hObject)
- {
- DeleteObject(m_FontSelected);
- m_FontSelected.m_hObject = NULL;
- }
- if(!m_Font.CreateFontIndirect(&lf))
- m_Font.CreateFontIndirect(&lf_default);
- LOGFONT lfSel;
- m_Font.GetLogFont(&lfSel);
- lfSel.lfWeight = FW_BOLD;
- m_FontSelected.CreateFontIndirect(&lfSel);
- if(fRedraw)
- {
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate();
- }
- }
- int CCustomTabCtrl::InsertItem(int nItem, CString sText,CWnd* childwnd)///*PARAM*/lParam)
- {
- if(nItem<0 || nItem>m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- if(sText.GetLength()>MAX_LABEL_TEXT-1)
- return CTCERR_TEXTTOOLONG;
- if(childwnd)
- childwnd->MoveWindow(0,0,0,0);
- CCustomTabCtrlItem* pItem = new CCustomTabCtrlItem(sText,childwnd);//lParam);
- if(pItem==NULL)
- return CTCERR_OUTOFMEMORY;
- try
- {
- m_aItems.InsertAt(nItem,pItem);
- }
- catch(CMemoryException* e)
- {
- e->Delete();
- delete pItem;
- return CTCERR_OUTOFMEMORY;
- }
- if(m_nItemSelected>=nItem)
- m_nItemSelected++;
- if(m_ctrlToolTip.m_hWnd)
- {
- for(INT_PTR i=m_aItems.GetSize()-1; i>nItem; i--)
- {
- CString s;
- m_ctrlToolTip.GetText(s,this,i);
- m_ctrlToolTip.DelTool(this,i);
- m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i+1);
- }
- m_ctrlToolTip.DelTool(this,nItem+1);
- }
-
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- return nItem;
- }
- CWnd* CCustomTabCtrl::InsertItem(int nItem,CString sText,CRuntimeClass* pViewClass)
- {
- if(nItem<0 || nItem>m_aItems.GetSize())
- return NULL;//CTCERR_INDEXOUTOFRANGE;
- if(sText.GetLength()>MAX_LABEL_TEXT-1)
- return NULL;//CTCERR_TEXTTOOLONG;
- if(!pViewClass) return NULL;
- CWnd* pWnd = NULL;
- TRY
- {
- // Create the object.
- pWnd = DYNAMIC_DOWNCAST(CWnd, pViewClass->CreateObject());
- if (!pWnd) AfxThrowMemoryException();
- }
- CATCH_ALL(e)
- {
- AfxMessageBox("建立视图时内存越界!" );
- // Note: DELETE_EXCEPTION(e) not required
- return NULL;//FALSE;
- }
- END_CATCH_ALL
- if(!pWnd) AfxMessageBox(_T("the window is null!"));
- ASSERT_KINDOF(CWnd, pWnd);
- ASSERT(pWnd->m_hWnd == NULL); // not yet created.
- if(m_nItemSelected>=nItem)
- m_nItemSelected++;
- // Create with the right size and position
- if (!pWnd->Create(NULL, NULL, WS_CHILD|WS_VISIBLE|WS_BORDER,
- CRect(0,0,0,0),GetParent(),nItem))//m_rClient
- {
- AfxMessageBox("fail!");
- // pWnd will be cleaned up by PostNcDestroy
- return NULL;
- }
- pWnd->ShowWindow(SW_SHOW);
- CCustomTabCtrlItem* pItem = new CCustomTabCtrlItem(sText,pWnd);//lParam);
- pItem->m_wType=WND_TYPE_HTMLVIEW;
- if(pItem==NULL)
- {
- AfxMessageBox("建立TAB控件项失败!");
- return NULL;//CTCERR_OUTOFMEMORY;
- }
- try
- {
- m_aItems.InsertAt(nItem,pItem);
- }
- catch(CMemoryException* e)
- {
- e->Delete();
- delete pItem;
- return NULL;//CTCERR_OUTOFMEMORY;
- }
- if(m_nItemSelected>=nItem)
- m_nItemSelected++;
- if(m_ctrlToolTip.m_hWnd)
- {
- for(INT_PTR i=m_aItems.GetSize()-1; i>nItem; i--)
- {
- CString s;
- m_ctrlToolTip.GetText(s,this,i);
- m_ctrlToolTip.DelTool(this,i);
- m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i+1);
- }
- m_ctrlToolTip.DelTool(this,nItem+1);
- }
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- ModifyStyle(0,CTCS_TOOLTIPS,0);
- CString infstr;
- infstr.Format("窗口序列:%d,按下右键删除!",nItem);
- SetItemTooltipText(nItem,infstr);
- return pWnd;
- }
- //移除一项
- int CCustomTabCtrl::MoveItem(int nItemSrc, int nItemDst)
- {
- return MoveItem(nItemSrc, nItemDst, FALSE);
- }
- int CCustomTabCtrl::MoveItem(int nItemSrc, int nItemDst, BOOL fMouseSel)
- {
- if(nItemSrc<0||nItemSrc>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- if(nItemDst<0||nItemDst>m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- if(nItemSrc==nItemDst || nItemSrc==nItemDst-1)
- return nItemSrc;
- CCustomTabCtrlItem *pItem = m_aItems[nItemSrc];
-
- // remove item from old place
- CString sOldTooltip;
- if(m_ctrlToolTip.m_hWnd)
- {
- m_ctrlToolTip.GetText(sOldTooltip,this,nItemSrc+1);
- for(int i=nItemSrc+1; i< m_aItems.GetSize(); i++)
- {
- CString s;
- m_ctrlToolTip.GetText(s,this,i+1);
- m_ctrlToolTip.DelTool(this,i);
- m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i);
- }
- }
- m_aItems.RemoveAt(nItemSrc);
- // insert item in new place
- if(nItemDst>nItemSrc)
- nItemDst--;
- try
- {
- m_aItems.InsertAt(nItemDst,pItem);
- }
- catch(CMemoryException* e)
- {
- e->Delete();
- delete pItem;
- if(fMouseSel)
- NotifyParent(CTCN_ITEMMOVE,nItemSrc,CPoint(0,0));
- return CTCERR_OUTOFMEMORY;
- }
- if(m_ctrlToolTip.m_hWnd)
- {
- for(int i=(int)m_aItems.GetSize()-1; i>nItemDst; i--)
- {
- CString s;
- m_ctrlToolTip.GetText(s,this,i);
- m_ctrlToolTip.DelTool(this,i+1);
- m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i+1);
- }
- m_ctrlToolTip.DelTool(this,nItemDst+1);
- m_ctrlToolTip.AddTool(this,sOldTooltip,CRect(0,0,0,0),nItemDst+1);
- }
- m_nItemSelected = nItemDst;
- RecalcLayout(RECALC_ITEM_SELECTED,m_nItemSelected);
- Invalidate(FALSE);
- if(fMouseSel)
- NotifyParent(CTCN_ITEMMOVE,m_nItemSelected,CPoint(0,0));
- return nItemDst;
- }
- int CCustomTabCtrl::CopyItem(int nItemSrc, int nItemDst)
- {
- return CopyItem(nItemSrc, nItemDst, FALSE);
- }
- int CCustomTabCtrl::CopyItem(int nItemSrc, int nItemDst, BOOL fMouseSel)
- {
- if(nItemSrc<0||nItemSrc>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- if(nItemDst<0||nItemDst>m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- CString sDst;
- try
- {
- BOOL bAppendFlag=TRUE;
- int n = m_aItems[nItemSrc]->m_sText.GetLength();
- if(n>=4)
- {
- if(m_aItems[nItemSrc]->m_sText[n-1]==_T(')') &&
- m_aItems[nItemSrc]->m_sText[n-2]>_T('1') &&
- m_aItems[nItemSrc]->m_sText[n-2]<=_T('9') &&
- m_aItems[nItemSrc]->m_sText[n-3]==_T('('))
- {
- n = m_aItems[nItemSrc]->m_sText.GetLength()-3;
- bAppendFlag = FALSE;
- }
- else if(m_aItems[nItemSrc]->m_sText[n-1]==_T(')') &&
- m_aItems[nItemSrc]->m_sText[n-2]>=_T('0') &&
- m_aItems[nItemSrc]->m_sText[n-2]<=_T('9') &&
- m_aItems[nItemSrc]->m_sText[n-3]>=_T('1') &&
- m_aItems[nItemSrc]->m_sText[n-3]<=_T('9') &&
- m_aItems[nItemSrc]->m_sText[n-4]==_T('('))
- {
- n = m_aItems[nItemSrc]->m_sText.GetLength()-4;
- bAppendFlag = FALSE;
- }
- }
- int ndx = 1;
- while(1)
- {
- ndx++;
- if(bAppendFlag)
- sDst.Format(_T("%s (%d)"),(LPCTSTR)m_aItems[nItemSrc]->m_sText,ndx);
- else
- sDst.Format(_T("%s(%d)"),(LPCTSTR)m_aItems[nItemSrc]->m_sText.Left(n),ndx);
- for(int i=0;i<m_aItems.GetSize();i++)
- {
- if(m_aItems[i]->m_sText==sDst)
- break;
- }
- if(i==m_aItems.GetSize())
- break;
- }
- }
- catch(CMemoryException* e)
- {
- e->Delete();
- if(fMouseSel)
- NotifyParent(CTCN_OUTOFMEMORY,nItemSrc,CPoint(0,0));
- return CTCERR_OUTOFMEMORY;
- }
- int nRetItem = InsertItem(nItemDst,sDst,m_aItems[nItemSrc]->m_lParam);
- if(nRetItem>=0)
- {
- SetCurSel(nRetItem);
- if(fMouseSel)
- NotifyParent(CTCN_ITEMCOPY,nRetItem,CPoint(0,0));
- }
- else if(fMouseSel && nRetItem==CTCERR_OUTOFMEMORY)
- NotifyParent(CTCN_OUTOFMEMORY,nRetItem,CPoint(0,0));
- return nRetItem;
- }
- int CCustomTabCtrl::DeleteItem(int nItem)
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- try
- {
- if(m_ctrlToolTip.m_hWnd)
- {
- for(int i=nItem+1; i< m_aItems.GetSize(); i++)
- {
- CString s;
- m_ctrlToolTip.GetText(s,this,i+1);
- m_ctrlToolTip.DelTool(this,i);
- m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i);
- }
- }
- }
- catch(CMemoryException* e)
- {
- e->Delete();
- return CTCERR_OUTOFMEMORY;
- }
- if(m_aItems.GetSize()==1)
- m_nItemSelected = -1;
- else if(m_nItemSelected==nItem)
- {
- if(m_nItemSelected==m_aItems.GetSize()-1) // last item
- {
- m_nItemSelected--;
- m_aItems[m_nItemSelected]->m_fSelected = TRUE;
- }
- else
- m_aItems[m_nItemSelected+1]->m_fSelected = TRUE;
- }
- else if(m_nItemSelected>nItem)
- m_nItemSelected--;
- //if(m_nItemSelected>=0)
- // SetCurSel(m_nItemSelected);
- //else
- CCustomTabCtrlItem* pItem =(CCustomTabCtrlItem*)m_aItems.GetAt(nItem);
- pItem->m_lParam->SendMessage(WM_QUIT);
- delete pItem->m_lParam;
- delete m_aItems[nItem];
- m_aItems.RemoveAt(nItem);
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- m_oldwnd=NULL;
- if(m_nItemSelected>=0)
- {
- SwitchWindows(DYNAMIC_DOWNCAST( CView, m_aItems[m_nItemSelected]->m_lParam));
- m_oldwnd=m_aItems[m_nItemSelected]->m_lParam;
- }
- //if(m_aItems.GetSize()==1)
- // SetCurSel(0);
- return CTCERR_NOERROR;
- }
- void CCustomTabCtrl::DeleteAllItems()
- {
- if(m_ctrlToolTip.m_hWnd)
- {
- for(int i=0; i< m_aItems.GetSize(); i++)
- {
- CCustomTabCtrlItem* pItem =(CCustomTabCtrlItem*)m_aItems.GetAt(i);
- delete pItem->m_lParam;
- delete m_aItems[i];
- m_ctrlToolTip.DelTool(this,i+1);
- }
- }
- else
- {
- for(int i=0; i< m_aItems.GetSize(); i++)
- {
- CCustomTabCtrlItem* pItem =(CCustomTabCtrlItem*)m_aItems.GetAt(i);
- delete pItem->m_lParam;
- delete m_aItems[i];
- }
- }
- m_aItems.RemoveAll();
- m_nItemSelected = -1;
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- }
- int CCustomTabCtrl::SetCurSel(int nItem)
- {
- return SetCurSel(nItem,FALSE,FALSE);
- }
- int CCustomTabCtrl::HighlightItem(int nItem, BOOL fHighlight)
- {
- if(!(GetStyle()&CTCS_MULTIHIGHLIGHT))
- return CTCERR_NOMULTIHIGHLIGHTSTYLE;
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- if(m_nItemSelected==-1 && !fHighlight)
- return CTCERR_NOERROR;
- if(m_nItemSelected==-1)
- {
- SetCurSel(nItem);
- return CTCERR_NOERROR;
- }
- if(fHighlight==m_aItems[nItem]->m_fHighlighted || nItem==m_nItemSelected)
- return CTCERR_NOERROR;
-
- m_aItems[nItem]->m_fHighlighted = fHighlight;
- return CTCERR_NOERROR;
- }
- int CCustomTabCtrl::GetItemText(int nItem, CString& sText)
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- sText = m_aItems[nItem]->m_sText;
- return CTCERR_NOERROR;
- }
- int CCustomTabCtrl::SetItemText(int nItem, CString sText)
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- m_aItems[nItem]->m_sText = sText;
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- return CTCERR_NOERROR;
- }
- int CCustomTabCtrl::SetItemTooltipText(int nItem, CString sText)
- {
- if(!(GetStyle()&CTCS_TOOLTIPS))
- return CTCERR_NOTOOLTIPSSTYLE;
- if(nItem>=CTCID_LASTBUTTON && nItem<m_aItems.GetSize())
- {
- if(m_ctrlToolTip.m_hWnd==NULL)
- {
- if(!m_ctrlToolTip.Create(this))
- return CTCERR_CREATETOOLTIPFAILED;
- m_ctrlToolTip.Activate(TRUE);
- }
- if(nItem>=0)
- nItem++;
- m_ctrlToolTip.DelTool(this,nItem);
- m_ctrlToolTip.AddTool(this,sText,CRect(0,0,0,0),nItem);
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- return CTCERR_NOERROR;
- }
- return CTCERR_INDEXOUTOFRANGE;
- }
- /*int CCustomTabCtrl::GetItemData(int nItem, DWORD& dwData)
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- dwData = m_aItems[nItem]->m_lParam;
- return CTCERR_NOERROR;
- }*/
- int CCustomTabCtrl::GetItemRect(int nItem, CRect& rect) const
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- rect = m_aItems[nItem]->m_rectText;
- return CTCERR_NOERROR;
- }
- /*int CCustomTabCtrl::SetItemData(int nItem, DWORD dwData)
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- m_aItems[nItem]->m_lParam = dwData;
- return CTCERR_NOERROR;
- }*/
- int CCustomTabCtrl::IsItemHighlighted(int nItem)
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- return (m_aItems[nItem]->m_fHighlighted)?1:0;
- }
- //测试用户按下了哪一个键
- int CCustomTabCtrl::HitTest(CPoint pt)
- {
- CRect rCl;
- GetClientRect(&rCl);
- int nBtns = 2;
- if(GetStyle()&CTCS_FOURBUTTONS)
- nBtns = 4;
- int nA = rCl.Height()-3;
- CRect rFirst,rPrev,rNext,rLast;
- if(nBtns==2)
- {
- rPrev.SetRect(0,0,nA+1,rCl.Height());
- rNext.SetRect(nA+1,0,2*nA+3,rCl.Height());
- }
- else
- {
- rFirst.SetRect(0,0,nA+1,rCl.Height());
- rPrev.SetRect(nA+1,0,2*nA+1,rCl.Height());
- rNext.SetRect(2*nA+1,0,3*nA+2,rCl.Height());
- rLast.SetRect(3*nA+2,0,4*nA+3,rCl.Height());
- }
- if(nBtns==4 && m_nFirstState && rFirst.PtInRect(pt))
- return CTCHT_ONFIRSTBUTTON;
- if(m_nPrevState && rPrev.PtInRect(pt))
- return CTCHT_ONPREVBUTTON;
-
- if(m_nNextState && rNext.PtInRect(pt))
- return CTCHT_ONNEXTBUTTON;
-
- if(nBtns==4 && m_nLastState && rLast.PtInRect(pt))
- return CTCHT_ONLASTBUTTON;
- for(int i=0; i<m_aItems.GetSize(); i++)
- {
- if(m_aItems[i]->HitTest(pt))
- return i;
- }
- return CTCHT_NOWHERE;
- }
- int CCustomTabCtrl::HighlightItem(int nItem, BOOL fMouseSel, BOOL fCtrlPressed)
- {
- if(!(GetStyle()&CTCS_MULTIHIGHLIGHT))
- return CTCERR_NOMULTIHIGHLIGHTSTYLE;
- for(int i=0; i<m_aItems.GetSize();i++)
- m_aItems[i]->m_fHighlightChanged = FALSE;
- if(fCtrlPressed)
- {
- if(nItem!=m_nItemSelected)
- {
- m_aItems[nItem]->m_fHighlighted = !m_aItems[nItem]->m_fHighlighted;
- if(fMouseSel)
- m_aItems[nItem]->m_fHighlightChanged = TRUE;
- }
- }
- else if(!m_aItems[nItem]->m_fHighlighted)
- {
- m_aItems[nItem]->m_fHighlighted = TRUE;
- m_aItems[nItem]->m_fHighlightChanged = TRUE;
- for(int i=0;i<m_aItems.GetSize();i++)
- {
- if(i!=m_nItemSelected)
- {
- if(m_aItems[i]->m_fHighlighted)
- {
- m_aItems[i]->m_fHighlighted = FALSE;
- if(fMouseSel)
- m_aItems[i]->m_fHighlightChanged = TRUE;
- }
- }
- }
- }
- if(fMouseSel)
- RecalcLayout(RECALC_ITEM_SELECTED,nItem);
- Invalidate(FALSE);
- return CTCERR_NOERROR;
- }
- int CCustomTabCtrl::SetCurSel(int nItem, BOOL fMouseSel, BOOL fCtrlPressed)
- {
- if(nItem<0 || nItem>=m_aItems.GetSize())
- return CTCERR_INDEXOUTOFRANGE;
- if(m_nItemSelected!=-1)
- m_aItems[m_nItemSelected]->m_fSelected = FALSE;
- m_nItemSelected = nItem;
-
- if(m_nItemSelected!=-1)
- m_aItems[m_nItemSelected]->m_fSelected = TRUE;
- if(fMouseSel)
- RecalcLayout(RECALC_ITEM_SELECTED,m_nItemSelected);
- else
- {
- m_nItemNdxOffset = nItem;
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- }
- Invalidate(FALSE);
- HighlightItem(nItem, fMouseSel, fCtrlPressed);
- if(m_aItems[nItem]->m_lParam!=m_oldwnd || m_oldwnd!=NULL)
- {
- SwitchWindows(DYNAMIC_DOWNCAST( CView, m_aItems[nItem]->m_lParam));
- m_oldwnd=m_aItems[nItem]->m_lParam;
- if(m_aItems[nItem]->m_wType==WND_TYPE_HTMLVIEW && !m_aItems[nItem]->m_OpenURL )
- {
- ((CIEView*)m_oldwnd)->Navigate(m_aItems[nItem]->m_sText);
- m_aItems[nItem]->m_OpenURL=TRUE;
- }
- }
- return CTCERR_NOERROR;
- }
- //重新调整窗口状态
- void CCustomTabCtrl::RecalcLayout(int nRecalcType, int nItem)
- {
- CRect rCl;
- GetClientRect(&rCl);
- {
- int nBtns = 2;
- if(GetStyle()&CTCS_FOURBUTTONS)
- nBtns = 4;
- int nWidth = RecalcRectangles();
-
- if((GetStyle()&CTCS_AUTOHIDEBUTTONS) && (m_aItems.GetSize()<2 || nWidth <= rCl.Width()))
- {
- m_nFirstState = BNST_INVISIBLE;
- m_nPrevState = BNST_INVISIBLE;
- m_nNextState = BNST_INVISIBLE;
- m_nLastState = BNST_INVISIBLE;
- m_nItemNdxOffset = 0;
- RecalcOffset(0);
- //if(nRecalcType==RECALC_EDIT_RESIZED)
- // RecalcEditResized(0,nItem);
- if(m_ctrlToolTip.m_hWnd)
- {
- m_ctrlToolTip.SetToolRect(this,CTCID_FIRSTBUTTON,CRect(0,0,0,0));
- m_ctrlToolTip.SetToolRect(this,CTCID_PREVBUTTON,CRect(0,0,0,0));
- m_ctrlToolTip.SetToolRect(this,CTCID_NEXTBUTTON,CRect(0,0,0,0));
- m_ctrlToolTip.SetToolRect(this,CTCID_LASTBUTTON,CRect(0,0,0,0));
- }
- return;
- }
-
- if(m_ctrlToolTip.m_hWnd)
- {
- int nA = rCl.Height()-3;
- if(nBtns == 2)
- {
- m_ctrlToolTip.SetToolRect(this,CTCID_FIRSTBUTTON,CRect(0,0,0,0));
- m_ctrlToolTip.SetToolRect(this,CTCID_PREVBUTTON,CRect(0,0,nA+1,rCl.Height()));
- m_ctrlToolTip.SetToolRect(this,CTCID_NEXTBUTTON,CRect(nA+1,0,2*nA+3,rCl.Height()));
- m_ctrlToolTip.SetToolRect(this,CTCID_LASTBUTTON,CRect(0,0,0,0));
- }
- else
- {
- m_ctrlToolTip.SetToolRect(this,CTCID_FIRSTBUTTON,CRect(0,0,nA+1,rCl.Height()));
- m_ctrlToolTip.SetToolRect(this,CTCID_PREVBUTTON,CRect(nA+1,0,2*nA+3,rCl.Height()));
- m_ctrlToolTip.SetToolRect(this,CTCID_NEXTBUTTON,CRect(2*nA+1,0,3*nA+2,rCl.Height()));
- m_ctrlToolTip.SetToolRect(this,CTCID_LASTBUTTON,CRect(3*nA+2,0,4*nA+3,rCl.Height()));
- }
- }
- int nBnWidth = nBtns*(rCl.Height()-3)+3;
- if(m_nFirstState==BNST_INVISIBLE)
- m_nFirstState = BNST_NORMAL;
- if(m_nPrevState==BNST_INVISIBLE)
- m_nPrevState = BNST_NORMAL;
- if(m_nNextState == BNST_INVISIBLE)
- m_nNextState = BNST_NORMAL;
- if(m_nLastState == BNST_INVISIBLE)
- m_nLastState = BNST_NORMAL;
-
- if(m_aItems.GetSize()==0)
- return;
- switch(nRecalcType)
- {
- case RECALC_FIRST_PRESSED:
- {
- m_nItemNdxOffset=0;
- RecalcRectangles();
- RecalcOffset(nBnWidth);
- }
- break;
- case RECALC_PREV_PRESSED:
- {
- RecalcOffset(nBnWidth);
- if(m_nItemNdxOffset>0)
- {
- m_nItemNdxOffset--;
- RecalcRectangles();
- RecalcOffset(nBnWidth);
- }
- }
- break;
- case RECALC_NEXT_PRESSED:
- {
- RecalcOffset(nBnWidth);
- if(m_aItems[m_aItems.GetSize()-1]->m_rect.right>rCl.Width() && m_nItemNdxOffset!=m_aItems.GetSize()-1)
- {
- m_nItemNdxOffset++;
- RecalcRectangles();
- RecalcOffset(nBnWidth);
- }
- }
- break;
- case RECALC_ITEM_SELECTED:
- {
- RecalcOffset(nBnWidth);
- if(m_aItems[nItem]->m_bShape==TAB_SHAPE2 || m_aItems[nItem]->m_bShape==TAB_SHAPE3)
- {
- m_nItemNdxOffset--;
- RecalcRectangles();
- RecalcOffset(nBnWidth);
- }
- else
- {
- while(m_nItemNdxOffset<nItem &&
- m_aItems[nItem]->m_bShape==TAB_SHAPE4 &&
- m_aItems[nItem]->m_rect.right>rCl.Width() &&
- m_aItems[nItem]->m_rect.left>nBnWidth)
- {
- m_nItemNdxOffset++;
- RecalcRectangles();
- RecalcOffset(nBnWidth);
- }
- }
- }
- break;
- // case RECALC_EDIT_RESIZED:
- // {
- // RecalcOffset(nBnWidth);
- // RecalcEditResized(nBnWidth,nItem);
- // }
- // break;
- case RECALC_LAST_PRESSED:
- {
- m_nItemNdxOffset=(int)m_aItems.GetSize()-1;
- }
- default: // window resized
- {
- BOOL bNdxOffsetChanged = FALSE;
- RecalcOffset(nBnWidth);
- while(m_nItemNdxOffset>=0 && m_aItems[m_aItems.GetSize()-1]->m_rect.right<rCl.Width())
- {
- m_nItemNdxOffset--;
- if(m_nItemNdxOffset>=0)
- {
- RecalcRectangles();
- RecalcOffset(nBnWidth);
- }
- bNdxOffsetChanged = TRUE;
- }
- if(bNdxOffsetChanged)
- {
- m_nItemNdxOffset++;
- RecalcRectangles();
- RecalcOffset(nBnWidth);
- }
- }
- break;
- }
- }
- }
- /*void CCustomTabCtrl::RecalcEditResized(int nOffset, int nItem)
- {
- CRect rCl;
- GetClientRect(rCl);
- do
- {
- CRect r;
- CDC* pDC = GetDC();
- CFont* pOldFont = pDC->SelectObject(&m_FontSelected);
- int h = pDC->DrawText(m_aItems[nItem]->m_sText+"X", r, DT_CALCRECT);
- pDC->SelectObject(pOldFont);
- ReleaseDC(pDC);
- r = m_aItems[nItem]->m_rectText;
- if(r.Height()>h)
- {
- r.top += (r.Height()-h)/2;
- r.bottom -= (r.Height()-h)/2;
- }
- r.left += 2;
- if(r.right>rCl.right && m_nItemSelected>m_nItemNdxOffset)
- {
- m_nItemNdxOffset++;
- RecalcRectangles();
- RecalcOffset(nOffset);
- }
- else
- {
- if(r.right>rCl.right)
- r.right = rCl.right;
- m_ctrlEdit.MoveWindow(r);
- int n = m_aItems[nItem]->m_sText.GetLength();
- int nStart, nEnd;
- m_ctrlEdit.GetSel(nStart,nEnd);
- if(nStart==nEnd && nStart==n)
- {
- m_ctrlEdit.SetSel(0,0);
- m_ctrlEdit.SetSel(n,n);
- }
- return;
- }
- }
- while(1);
- }*/
- void CCustomTabCtrl::RecalcOffset(int nOffset)
- {
- CRect rCl;
- GetClientRect(&rCl);
- int nBtns = 2;
- if(GetStyle()&CTCS_FOURBUTTONS)
- nBtns = 4;
- int nBnWidth = nBtns*(rCl.Height()-3)+3;
- for(int i = 0; i<m_aItems.GetSize(); i++)
- {
- if(i<m_nItemNdxOffset-1)
- {
- m_aItems[i]->m_bShape = TAB_SHAPE1;
- nOffset -= m_aItems[i]->m_rect.Width()-rCl.Height()/2;
- m_aItems[i]->m_rectText.SetRectEmpty();
- }
- else if(i==m_nItemNdxOffset-1)
- {
- if(i==m_nItemSelected)
- m_aItems[i]->m_bShape = TAB_SHAPE2;
- else
- m_aItems[i]->m_bShape = TAB_SHAPE3;
- nOffset -= m_aItems[i]->m_rect.Width()-rCl.Height()/2;
- m_aItems[i]->m_rect.SetRect(0,1,rCl.Height()/2,rCl.Height()-1);
- m_aItems[i]->m_rect.OffsetRect(nBnWidth,0);
- m_aItems[i]->m_rectText.SetRectEmpty();
- }
- else
- {
- if(i==m_nItemSelected)
- m_aItems[i]->m_bShape = TAB_SHAPE4;
- else if(i==m_aItems.GetSize()-1) // last item
- m_aItems[i]->m_bShape = TAB_SHAPE4;
- else
- m_aItems[i]->m_bShape = TAB_SHAPE5;
- m_aItems[i]->m_rect.OffsetRect(nOffset,0);
- m_aItems[i]->m_rectText.OffsetRect(nOffset,0);
- }
- m_aItems[i]->ComputeRgn();
- if(m_ctrlToolTip.m_hWnd)
- m_ctrlToolTip.SetToolRect(this,i+1,m_aItems[i]->m_rectText);
- }
- }
- int CCustomTabCtrl::RecalcRectangles()
- {
- CRect rCl;
- GetClientRect(&rCl);
- int nWidth = 0;
-
- {
- // calculate width
- int nOffset = 0;
- CRect rcText;
- CDC* pDC = GetDC();
- CFont* pOldFont = pDC->SelectObject(&m_FontSelected);
- if(GetStyle()&CTCS_FIXEDWIDTH)
- {
- int nMaxWidth=0;
- for(int i=0; i<m_aItems.GetSize(); i++)
- {
- int w=0;
- int h = pDC->DrawText(m_aItems[i]->m_sText, rcText, DT_CALCRECT);
- if(h>0)
- w = rcText.Width();
- if(w>nMaxWidth)
- nMaxWidth = w;
- }
- for(i=0; i<m_aItems.GetSize(); i++)
- {
- m_aItems[i]->m_rect = CRect(0,1,nMaxWidth+rCl.Height()+4,rCl.Height()-1);
- m_aItems[i]->m_rect += CPoint(nOffset,0);
- m_aItems[i]->m_rectText = CRect(rCl.Height()/2,1,nMaxWidth+rCl.Height()/2+4,rCl.Height()-1);
- m_aItems[i]->m_rectText += CPoint(nOffset,0);
- nOffset += m_aItems[i]->m_rect.Width()-rCl.Height()/2;
- nWidth = m_aItems[i]->m_rect.right;
- }
- }
- else
- {
- for(int i= 0; i<m_aItems.GetSize(); i++)
- {
- int w=0;
- int h = pDC->DrawText(m_aItems[i]->m_sText, rcText, DT_CALCRECT);
- if(h>0)
- w = rcText.Width();
- m_aItems[i]->m_rect = CRect(0,1,w+rCl.Height()+4,rCl.Height()-1);
- m_aItems[i]->m_rect += CPoint(nOffset,0);
- m_aItems[i]->m_rectText = CRect(rCl.Height()/2,1,w+rCl.Height()/2+4,rCl.Height()-1);
- m_aItems[i]->m_rectText += CPoint(nOffset,0);
- nOffset += m_aItems[i]->m_rect.Width()-rCl.Height()/2;
- nWidth = m_aItems[i]->m_rect.right;
- }
- }
- pDC->SelectObject(pOldFont);
- ReleaseDC(pDC);
- }
- return nWidth;
- }
- BOOL CCustomTabCtrl::PreTranslateMessage(MSG* pMsg)
- {
- if(GetStyle()&CTCS_TOOLTIPS && m_ctrlToolTip.m_hWnd &&
- (pMsg->message==WM_LBUTTONDOWN || pMsg->message==WM_LBUTTONUP || pMsg->message==WM_MOUSEMOVE))
- m_ctrlToolTip.RelayEvent(pMsg);
- return CWnd::PreTranslateMessage(pMsg);
- }
- void CCustomTabCtrl::DrawBkLeftSpin(CDC& dc, CRect& r, int nImageNdx)
- {
- CDC dcMem;
- dcMem.CreateCompatibleDC(&dc);
- CBitmap* pBmp = CBitmap::FromHandle(m_hBmpBkLeftSpin);
- BITMAP bm;
- pBmp->GetBitmap(&bm);
- CBitmap* pOldBmp = dcMem.SelectObject(pBmp);
- if(m_fIsLeftImageHorLayout)
- {
- // left-top
- dc.BitBlt(r.left,
- r.top,
- m_mrgnLeft.cxLeftWidth,
- m_mrgnLeft.cyTopHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4,
- 0,
- SRCCOPY);
-
- // right-top
- dc.BitBlt(r.right-m_mrgnLeft.cxRightWidth,
- r.top,
- m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyTopHeight,
- &dcMem,
- (nImageNdx+1)*bm.bmWidth/4-m_mrgnLeft.cxRightWidth,
- 0,
- SRCCOPY);
- // left-bottom
- dc.BitBlt(r.left,
- r.bottom-m_mrgnLeft.cyBottomHeight,
- m_mrgnLeft.cxLeftWidth,
- m_mrgnLeft.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4,
- bm.bmHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // right-bottom
- dc.BitBlt(r.right-m_mrgnLeft.cxRightWidth,
- r.bottom-m_mrgnLeft.cyBottomHeight,
- m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyBottomHeight,
- &dcMem,
- (nImageNdx+1)*bm.bmWidth/4-m_mrgnLeft.cxRightWidth,
- bm.bmHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle-top
- dc.StretchBlt(r.left+m_mrgnLeft.cxLeftWidth,
- r.top,
- r.Width()-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyTopHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4+m_mrgnLeft.cxLeftWidth,
- 0,
- bm.bmWidth/4-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyTopHeight,
- SRCCOPY);
- // middle-bottom
- dc.StretchBlt(r.left+m_mrgnLeft.cxLeftWidth,
- r.bottom-m_mrgnLeft.cyBottomHeight,
- r.Width()-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4+m_mrgnLeft.cxLeftWidth,
- bm.bmHeight-m_mrgnLeft.cyBottomHeight,
- bm.bmWidth/4-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle-left
- dc.StretchBlt(r.left,
- r.top+m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxLeftWidth,
- r.Height()-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4,
- m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxLeftWidth,
- bm.bmHeight-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle-right
- dc.StretchBlt(r.right-m_mrgnLeft.cxRightWidth,
- r.top+m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxRightWidth,
- r.Height()-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- &dcMem,
- (nImageNdx+1)*bm.bmWidth/4-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxRightWidth,
- bm.bmHeight-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle
- dc.StretchBlt(
- r.left+m_mrgnLeft.cxLeftWidth,
- r.top+m_mrgnLeft.cyTopHeight,
- r.Width()-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- r.Height()-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4 + m_mrgnLeft.cxLeftWidth,
- m_mrgnLeft.cyTopHeight,
- bm.bmWidth/4-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- bm.bmHeight-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- }
- else
- {
- // left-top
- dc.BitBlt(r.left,
- r.top,
- m_mrgnLeft.cxLeftWidth,
- m_mrgnLeft.cyTopHeight,
- &dcMem,
- 0,
- nImageNdx*bm.bmHeight/4,
- SRCCOPY);
-
- // right-top
- dc.BitBlt(r.right-m_mrgnLeft.cxRightWidth,
- r.top,
- m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyTopHeight,
- &dcMem,
- bm.bmWidth-m_mrgnLeft.cxRightWidth,
- nImageNdx*bm.bmHeight/4,
- SRCCOPY);
-
- // left-bottom
- dc.BitBlt(r.left,
- r.bottom-m_mrgnLeft.cyBottomHeight,
- m_mrgnLeft.cxLeftWidth,
- m_mrgnLeft.cyBottomHeight,
- &dcMem,
- 0,
- (nImageNdx+1)*bm.bmHeight/4-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // right-bottom
- dc.BitBlt(r.right-m_mrgnLeft.cxRightWidth,
- r.bottom-m_mrgnLeft.cyBottomHeight,
- m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyBottomHeight,
- &dcMem,
- bm.bmWidth-m_mrgnLeft.cxRightWidth,
- (nImageNdx+1)*bm.bmHeight/4-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle-top
- dc.StretchBlt(r.left+m_mrgnLeft.cxLeftWidth,
- r.top,
- r.Width()-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyTopHeight,
- &dcMem,
- m_mrgnLeft.cxLeftWidth,
- nImageNdx*bm.bmHeight/4,
- bm.bmWidth-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyTopHeight,
- SRCCOPY);
- // middle-bottom
- dc.StretchBlt(r.left+m_mrgnLeft.cxLeftWidth,
- r.bottom-m_mrgnLeft.cyBottomHeight,
- r.Width()-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyBottomHeight,
- &dcMem,
- m_mrgnLeft.cxLeftWidth,
- (nImageNdx+1)*bm.bmHeight/4-m_mrgnLeft.cyBottomHeight,
- bm.bmWidth-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle-left
- dc.StretchBlt(r.left,
- r.top+m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxLeftWidth,
- r.Height()-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- &dcMem,
- 0,
- nImageNdx*bm.bmHeight/4+m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxLeftWidth,
- bm.bmHeight/4-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle-right
- dc.StretchBlt(r.right-m_mrgnLeft.cxRightWidth,
- r.top+m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxRightWidth,
- r.Height()-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- &dcMem,
- bm.bmWidth-m_mrgnLeft.cxRightWidth,
- nImageNdx*bm.bmHeight/4+m_mrgnLeft.cyTopHeight,
- m_mrgnLeft.cxRightWidth,
- bm.bmHeight/4-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- // middle
- dc.StretchBlt(
- r.left+m_mrgnLeft.cxLeftWidth,
- r.top+m_mrgnLeft.cyTopHeight,
- r.Width()-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- r.Height()-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- &dcMem,
- m_mrgnLeft.cxLeftWidth,
- nImageNdx*bm.bmHeight/4+m_mrgnLeft.cyTopHeight,
- bm.bmWidth-m_mrgnLeft.cxLeftWidth-m_mrgnLeft.cxRightWidth,
- bm.bmHeight/4-m_mrgnLeft.cyTopHeight-m_mrgnLeft.cyBottomHeight,
- SRCCOPY);
- }
- dcMem.SelectObject(pOldBmp);
- }
- void CCustomTabCtrl::DrawBkRightSpin(CDC& dc, CRect& r, int nImageNdx)
- {
- CDC dcMem;
- dcMem.CreateCompatibleDC(&dc);
- CBitmap* pBmp = CBitmap::FromHandle(m_hBmpBkRightSpin);
- BITMAP bm;
- pBmp->GetBitmap(&bm);
- CBitmap* pOldBmp = dcMem.SelectObject(pBmp);
- if(m_fIsRightImageHorLayout)
- {
- // left-top
- dc.BitBlt(r.left,
- r.top,
- m_mrgnRight.cxLeftWidth,
- m_mrgnRight.cyTopHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4,
- 0,
- SRCCOPY);
-
- // right-top
- dc.BitBlt(r.right-m_mrgnRight.cxRightWidth,
- r.top,
- m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyTopHeight,
- &dcMem,
- (nImageNdx+1)*bm.bmWidth/4-m_mrgnRight.cxRightWidth,
- 0,
- SRCCOPY);
- // left-bottom
- dc.BitBlt(r.left,
- r.bottom-m_mrgnRight.cyBottomHeight,
- m_mrgnRight.cxLeftWidth,
- m_mrgnRight.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4,
- bm.bmHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // right-bottom
- dc.BitBlt(r.right-m_mrgnRight.cxRightWidth,
- r.bottom-m_mrgnRight.cyBottomHeight,
- m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyBottomHeight,
- &dcMem,
- (nImageNdx+1)*bm.bmWidth/4-m_mrgnRight.cxRightWidth,
- bm.bmHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle-top
- dc.StretchBlt(r.left+m_mrgnRight.cxLeftWidth,
- r.top,
- r.Width()-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyTopHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4+m_mrgnRight.cxLeftWidth,
- 0,
- bm.bmWidth/4-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyTopHeight,
- SRCCOPY);
- // middle-bottom
- dc.StretchBlt(r.left+m_mrgnRight.cxLeftWidth,
- r.bottom-m_mrgnRight.cyBottomHeight,
- r.Width()-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4+m_mrgnRight.cxLeftWidth,
- bm.bmHeight-m_mrgnRight.cyBottomHeight,
- bm.bmWidth/4-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle-left
- dc.StretchBlt(r.left,
- r.top+m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxLeftWidth,
- r.Height()-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4,
- m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxLeftWidth,
- bm.bmHeight-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle-right
- dc.StretchBlt(r.right-m_mrgnRight.cxRightWidth,
- r.top+m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxRightWidth,
- r.Height()-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- &dcMem,
- (nImageNdx+1)*bm.bmWidth/4-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxRightWidth,
- bm.bmHeight-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle
- dc.StretchBlt(
- r.left+m_mrgnRight.cxLeftWidth,
- r.top+m_mrgnRight.cyTopHeight,
- r.Width()-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- r.Height()-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- &dcMem,
- nImageNdx*bm.bmWidth/4 + m_mrgnRight.cxLeftWidth,
- m_mrgnRight.cyTopHeight,
- bm.bmWidth/4-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- bm.bmHeight-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- }
- else
- {
- // left-top
- dc.BitBlt(r.left,
- r.top,
- m_mrgnRight.cxLeftWidth,
- m_mrgnRight.cyTopHeight,
- &dcMem,
- 0,
- nImageNdx*bm.bmHeight/4,
- SRCCOPY);
-
- // right-top
- dc.BitBlt(r.right-m_mrgnRight.cxRightWidth,
- r.top,
- m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyTopHeight,
- &dcMem,
- bm.bmWidth-m_mrgnRight.cxRightWidth,
- nImageNdx*bm.bmHeight/4,
- SRCCOPY);
-
- // left-bottom
- dc.BitBlt(r.left,
- r.bottom-m_mrgnRight.cyBottomHeight,
- m_mrgnRight.cxLeftWidth,
- m_mrgnRight.cyBottomHeight,
- &dcMem,
- 0,
- (nImageNdx+1)*bm.bmHeight/4-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // right-bottom
- dc.BitBlt(r.right-m_mrgnRight.cxRightWidth,
- r.bottom-m_mrgnRight.cyBottomHeight,
- m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyBottomHeight,
- &dcMem,
- bm.bmWidth-m_mrgnRight.cxRightWidth,
- (nImageNdx+1)*bm.bmHeight/4-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle-top
- dc.StretchBlt(r.left+m_mrgnRight.cxLeftWidth,
- r.top,
- r.Width()-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyTopHeight,
- &dcMem,
- m_mrgnRight.cxLeftWidth,
- nImageNdx*bm.bmHeight/4,
- bm.bmWidth-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyTopHeight,
- SRCCOPY);
- // middle-bottom
- dc.StretchBlt(r.left+m_mrgnRight.cxLeftWidth,
- r.bottom-m_mrgnRight.cyBottomHeight,
- r.Width()-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyBottomHeight,
- &dcMem,
- m_mrgnRight.cxLeftWidth,
- (nImageNdx+1)*bm.bmHeight/4-m_mrgnRight.cyBottomHeight,
- bm.bmWidth-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle-left
- dc.StretchBlt(r.left,
- r.top+m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxLeftWidth,
- r.Height()-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- &dcMem,
- 0,
- nImageNdx*bm.bmHeight/4+m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxLeftWidth,
- bm.bmHeight/4-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle-right
- dc.StretchBlt(r.right-m_mrgnRight.cxRightWidth,
- r.top+m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxRightWidth,
- r.Height()-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- &dcMem,
- bm.bmWidth-m_mrgnRight.cxRightWidth,
- nImageNdx*bm.bmHeight/4+m_mrgnRight.cyTopHeight,
- m_mrgnRight.cxRightWidth,
- bm.bmHeight/4-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- // middle
- dc.StretchBlt(
- r.left+m_mrgnRight.cxLeftWidth,
- r.top+m_mrgnRight.cyTopHeight,
- r.Width()-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- r.Height()-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- &dcMem,
- m_mrgnRight.cxLeftWidth,
- nImageNdx*bm.bmHeight/4+m_mrgnRight.cyTopHeight,
- bm.bmWidth-m_mrgnRight.cxLeftWidth-m_mrgnRight.cxRightWidth,
- bm.bmHeight/4-m_mrgnRight.cyTopHeight-m_mrgnRight.cyBottomHeight,
- SRCCOPY);
- }
- dcMem.SelectObject(pOldBmp);
- }
- //绘制左端按钮上的箭头标志符号
- void CCustomTabCtrl::DrawGlyph(CDC& dc, CPoint& pt, int nImageNdx, int nColorNdx)
- {
- CDC dcMem, dcMemMono;
- dcMem.CreateCompatibleDC(&dc);
- dcMemMono.CreateCompatibleDC(&dc);
- CBitmap* pOldBmpGlyphMono = dcMemMono.SelectObject(&m_bmpGlyphsMono);
- CBitmap bmpGlyphColor;
- bmpGlyphColor.CreateCompatibleBitmap(&dc,8,7);
-
- CBitmap* pOldBmpGlyphColor = dcMem.SelectObject(&bmpGlyphColor);
- COLORREF rgbOldTextGlyph = dcMem.SetTextColor(m_rgbGlyph[nColorNdx]);
- dcMem.BitBlt(0, 0, 8, 7, &dcMemMono, nImageNdx*8, 0, SRCCOPY);
- dcMem.SetTextColor(rgbOldTextGlyph);
- COLORREF rgbOldBk = dc.SetBkColor(RGB(255,255,255));
- COLORREF rgbOldText = dc.SetTextColor(RGB(0,0,0));
- dc.BitBlt(pt.x, pt.y, 8, 7, &dcMem, 0, 0, SRCINVERT);
- dc.BitBlt(pt.x, pt.y, 8, 7, &dcMemMono, nImageNdx*8, 0, SRCAND);
- dc.BitBlt(pt.x, pt.y, 8, 7, &dcMem, 0, 0, SRCINVERT);
- dcMem.SelectObject(pOldBmpGlyphColor);
- dcMemMono.SelectObject(pOldBmpGlyphMono);
- dc.SetBkColor(rgbOldBk);
- dc.SetTextColor(rgbOldText);
- }
- BOOL CCustomTabCtrl::ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
- {
- if(dwRemove&CTCS_TOOLTIPS)
- m_ctrlToolTip.DestroyWindow();
- if(dwRemove&CTCS_MULTIHIGHLIGHT)
- {
- for(int i=0;i<m_aItems.GetSize();i++)
- m_aItems[i]->m_fHighlighted = FALSE;
- }
- if(dwAdd&CTCS_MULTIHIGHLIGHT)
- {
- for(int i=0;i<m_aItems.GetSize();i++)
- {
- if(i==m_nItemSelected)
- m_aItems[i]->m_fHighlighted = TRUE;
- }
- }
- CWnd::ModifyStyle(dwRemove,dwAdd,nFlags);
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- Invalidate(FALSE);
- return TRUE;
- }
- void CCustomTabCtrl::PreSubclassWindow()
- {
- OnThemeChanged(0,0);
- CWnd::ModifyStyle(0,WS_CLIPCHILDREN);
- RecalcLayout(RECALC_RESIZED,m_nItemSelected);
- CWnd::PreSubclassWindow();
- }
- void CCustomTabCtrl::SetDragCursors(HCURSOR hCursorMove, HCURSOR hCursorCopy)
- {
- ::DestroyCursor(m_hCursorMove);
- m_hCursorMove = NULL;
- ::DestroyCursor(m_hCursorCopy);
- m_hCursorCopy = NULL;
- m_hCursorMove = CopyCursor(hCursorMove);
- m_hCursorCopy = CopyCursor(hCursorCopy);
- }
- // 切换显示的窗口
- //在这里选中的窗口发送消息,作出相应的处理
- //在这里,对应多个窗口,将选中的窗口设定为活动或禁止
- void CCustomTabCtrl::SwitchWindows(CWnd* curwnd)
- {
- if(curwnd==NULL) return;
- if(m_oldwnd!=NULL)
- {
- m_oldwnd->MoveWindow(0,0,0,0);
- m_oldwnd->EnableWindow(FALSE);
- m_oldwnd->ShowWindow(SW_HIDE);
-
- }
- if(curwnd!=NULL)
- {
- curwnd->MoveWindow(&m_rClient);
- curwnd->EnableWindow();
- curwnd->ShowWindow(SW_SHOW);
- }
- /*else
- {
- CString inf;
- CDC* pDC=GetParent()->GetDC();
- pDC->FillRect(&m_rClient,&CBrush(RGB(255,224,224)));
- pDC->SetBkMode(TRANSPARENT);
- pDC->DrawText(_T("当前显示的窗口尚未建立"),&m_rClient,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
- ReleaseDC(pDC);
- }*/
- }
- //当父窗口大小发生变化时,若为了使它的大小也发生相应的变化
- //则调用本窗函数,以改变目前窗口的大小
- void CCustomTabCtrl::ResetWindowSize(CRect& rect)
- {
- if(m_rClient==rect) return;
- m_rClient=rect;
- if(m_rClient.Height()>m_hSwitch)
- {
- m_rClient.bottom=m_rClient.bottom-m_hSwitch-DEF_STOWND_LENGTH;
-
- }
- CRect switchrect;
- switchrect.SetRect(rect.left,rect.bottom-m_hSwitch,rect.right,rect.bottom);
- MoveWindow(&switchrect);
- if(m_oldwnd!=NULL)
- m_oldwnd->MoveWindow(&m_rClient);
- }
- //在有时,不必要使切换窗口的大小和显示窗口部分的宽度一致,用此函数实现
- //重新定义切换窗口的大小
- void CCustomTabCtrl::ResetSwitchWidth(int width)
- {
- CRect switchrect;
- switchrect.SetRect(m_rClient.left,m_rClient.bottom+DEF_STOWND_LENGTH,
- m_rClient.left+width,m_rClient.bottom+DEF_STOWND_LENGTH+m_hSwitch);
- MoveWindow(&switchrect);
- //m_oldwnd->MoveWindow(&m_rClient);
- }
- //当按下右键时,则删除当年的页面
- void CCustomTabCtrl::OnRButtonDown(UINT nFlags, CPoint point)
- {
- int nHitTest = HitTest(point);
- DeleteItem(nHitTest);
- CWnd::OnRButtonDown(nFlags, point);
- }