Thanks for the post. There is a bug in the demo program in recalculating layouts of the controls. To fix it comment out the code in CCustomTabCtrlDemoDlg::Size(int cx, int cy) or apply the code shown below:
void CCustomTabCtrlDemoDlg::Size(int cx, int cy)
{
if(m_ctrlTab.m_hWnd && cx && cy)
{
int m = 10;
int w = 100;
CRect r;
m_ctrlTab.GetWindowRect(r);
CRect rBn;
m_ctrlFixed.GetWindowRect(rBn);
if(m_ctrlTab.GetStyle()&CTCS_TOP)
{
m_ctrlColor.MoveWindow(m,r.Height()+m,cx-3*m-rBn.Width(),cy-r.Height()-2*m);
m_ctrlTab.MoveWindow(m,m,cx-3*m-rBn.Width(),r.Height());
}
else
{
m_ctrlColor.MoveWindow(m,m,cx-3*m-rBn.Width(),cy-r.Height()-2*m);
m_ctrlTab.MoveWindow(m,cy-r.Height()-m,cx-3*m-rBn.Width(),r.Height());
}
m_ctrlFixed.MoveWindow(r.Width()+2*m,m,rBn.Width(),rBn.Height());
m_ctrl4Buttons.MoveWindow(r.Width()+2*m,3*m,rBn.Width(),rBn.Height());
m_ctrlAutoHide.MoveWindow(r.Width()+2*m,5*m,rBn.Width(),rBn.Height());
m_ctrlClose.MoveWindow(r.Width()+2*m,7*m,rBn.Width(),rBn.Height());
m_ctrlTop.MoveWindow(r.Width()+2*m,9*m,rBn.Width(),rBn.Height());
m_ctrlTooltips.MoveWindow(r.Width()+2*m,11*m,rBn.Width(),rBn.Height());
m_ctrlMultihighlight.MoveWindow(r.Width()+2*m,13*m,rBn.Width(),rBn.Height());
m_ctrlEditlabels.MoveWindow(r.Width()+2*m,15*m,rBn.Width(),rBn.Height());
m_ctrlDragmove.MoveWindow(r.Width()+2*m,17*m,rBn.Width(),rBn.Height());
m_ctrlDragcopy.MoveWindow(r.Width()+2*m,19*m,rBn.Width(),rBn.Height());
GetDlgItem(IDC_RADIO1)->MoveWindow(r.Width()+2*m,21*m,rBn.Width(),rBn.Height());
GetDlgItem(IDC_RADIO2)->MoveWindow(r.Width()+2*m,23*m,rBn.Width(),rBn.Height());
}
}
Also you can set WS_EX_LAYOUTRTL (0x400000) style to the tab control. You have to change CCustomTabCtrl::OnPaint() function to fix the problem with drawing tab control buttons and add DT_RTLREADING format style to DrawText function for right to left reading order for labels.
void CCustomTabCtrl::OnPaint()
{
CPaintDC dc(this);
if(!m_hBmpBkLeftSpin)
{
m_rgbGlyph[0] = GetSysColor(COLOR_BTNTEXT);
m_rgbGlyph[1] = GetSysColor(COLOR_BTNTEXT);
m_rgbGlyph[2] = GetSysColor(COLOR_BTNTEXT);
m_rgbGlyph[3] = GetSysColor(COLOR_BTNTEXT);
}
CRect rCl;
GetClientRect(&rCl);
CPen blackPen(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
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 = 0;
if(m_nCloseState)
nBtns++;
if(m_nPrevState)
nBtns += 2;
if(m_nFirstState)
nBtns += 2;
dcMem.FillSolidRect(&rCl,GetSysColor(COLOR_BTNFACE));
int nA = rCl.Height()-3;
CRect rAll(0,1,nBtns*nA+3,rCl.Height());
if(nBtns==0)
rAll.SetRectEmpty();
int nCloseOffset = 0;
if(m_nCloseState || m_nPrevState)
{
CPen* pOldPen = dcMem.SelectObject(&blackPen);
dcMem.Rectangle(rAll);
dcMem.SelectObject(pOldPen);
}
BOOL fRTL = (BOOL)(GetExStyle()&0x400000);
if(m_nCloseState)
{
nCloseOffset = nA;
CRect rClose(1,2,nA+1,rCl.Height()-1);
CPoint ptClose(rClose.left+(rClose.Width()-8)/2+rClose.Width()%2,rClose.top+(rClose.Height()-7)/2);
if(fRTL && m_hBmpBkRightSpin)
DrawBk(dcMem,rClose,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nCloseState-1);
else if(m_hBmpBkLeftSpin)
DrawBk(dcMem,rClose,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nCloseState-1);
else
{
if(m_nCloseState==BNST_PRESSED)
dcMem.DrawFrameControl(rClose,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rClose,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptClose,1,m_nCloseState-1);
else
DrawGlyph(dcMem,ptClose,4,m_nCloseState-1);
}
if(m_nPrevState)
{
CRect rFirst,rPrev,rNext,rLast;
if(nBtns<4)
{
rPrev.SetRect(nCloseOffset+1,2,nCloseOffset+nA+1,rCl.Height()-1);
rNext.SetRect(nCloseOffset+nA+2,2,nCloseOffset+2*nA+2,rCl.Height()-1);
}
else
{
rFirst.SetRect(nCloseOffset+1,2,nCloseOffset+nA+1,rCl.Height()-1);
rPrev.SetRect(nCloseOffset+nA+1,2,nCloseOffset+2*nA+1,rCl.Height()-1);
rNext.SetRect(nCloseOffset+2*nA+2,2,nCloseOffset+3*nA+2,rCl.Height()-1);
rLast.SetRect(nCloseOffset+3*nA+2,2,nCloseOffset+4*nA+2,rCl.Height()-1);
}
if(nBtns>=4)
{
CPoint ptFirst(rFirst.left+(rFirst.Width()-8)/2,rFirst.top+(rFirst.Height()-7)/2);
if(fRTL && m_hBmpBkRightSpin)
DrawBk(dcMem,rFirst,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nFirstState-1);
else if(m_hBmpBkLeftSpin)
DrawBk(dcMem,rFirst,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nFirstState-1);
else
{
if(m_nFirstState==BNST_PRESSED)
dcMem.DrawFrameControl(rFirst,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rFirst,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptFirst,2,m_nFirstState-1);
else
DrawGlyph(dcMem,ptFirst,0,m_nFirstState-1);
CPoint ptLast(rLast.left+(rLast.Width()-8)/2,rLast.top+(rLast.Height()-7)/2);
if(fRTL && m_hBmpBkLeftSpin)
DrawBk(dcMem,rLast,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nLastState-1);
else if(m_hBmpBkRightSpin)
DrawBk(dcMem,rLast,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nLastState-1);
else
{
if(m_nLastState==BNST_PRESSED)
dcMem.DrawFrameControl(rLast,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rLast,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptLast,5,m_nLastState-1);
else
DrawGlyph(dcMem,ptLast,3,m_nLastState-1);
}
CPoint ptPrev(rPrev.left+(rPrev.Width()-8)/2,rPrev.top+(rPrev.Height()-7)/2);
if(fRTL && m_hBmpBkRightSpin)
DrawBk(dcMem,rPrev,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nPrevState-1);
else if(m_hBmpBkLeftSpin)
DrawBk(dcMem,rPrev,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nPrevState-1);
else
{
if(m_nPrevState==BNST_PRESSED)
dcMem.DrawFrameControl(rPrev,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rPrev,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptPrev,3,m_nPrevState-1);
else
DrawGlyph(dcMem,ptPrev,1,m_nPrevState-1);
CPoint ptNext(rNext.left+(rNext.Width()-8)/2,rNext.top+(rNext.Height()-7)/2);
if(fRTL && m_hBmpBkLeftSpin)
DrawBk(dcMem,rNext,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nNextState-1);
else if(m_hBmpBkRightSpin)
DrawBk(dcMem,rNext,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nNextState-1);
else
{
rNext.left -= 1;
if(m_nNextState==BNST_PRESSED)
dcMem.DrawFrameControl(rNext,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rNext,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptNext,4,m_nNextState-1);
else
DrawGlyph(dcMem,ptNext,2,m_nNextState-1);
}
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,GetStyle()&CTCS_TOP,fRTL);
else
m_aItems[i]->Draw(dcMem,m_Font,GetStyle()&CTCS_TOP,fRTL);
}
}
if(m_nItemSelected!=-1 && m_aItems[m_nItemSelected]->m_bShape)
m_aItems[m_nItemSelected]->Draw(dcMem,m_FontSelected,GetStyle()&CTCS_TOP,fRTL);
int nOffsetX = rAll.right;
CPoint pts[4];
if(GetStyle()&CTCS_TOP)
{
if(m_nItemSelected==-1)
{
pts[0] = CPoint(nOffsetX,rCl.bottom-1);
pts[1] = CPoint(nOffsetX,rCl.bottom-1);
pts[2] = CPoint(nOffsetX,rCl.bottom-1);
pts[3] = CPoint(rCl.right,rCl.bottom-1);
}
else
{
if(m_aItems[m_nItemSelected]->m_bShape)
{
pts[0] = CPoint(nOffsetX,rCl.bottom-1);
pts[1] = CPoint(m_aItems[m_nItemSelected]->m_rect.left,rCl.bottom-1);
pts[2] = CPoint(m_aItems[m_nItemSelected]->m_rect.right,rCl.bottom-1);
pts[3] = CPoint(rCl.right,rCl.bottom-1);
}
else
{
pts[0] = CPoint(nOffsetX,rCl.bottom-1);
pts[1] = CPoint(nOffsetX,rCl.bottom-1);
pts[2] = CPoint(nOffsetX,rCl.bottom-1);
pts[3] = CPoint(rCl.right,rCl.bottom-1);
}
}
}
else
{
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))
{
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);
dcMem.SelectObject(pOldPen);
}
dc.BitBlt(rCl.left,rCl.top,rCl.Width(),rCl.Height(),&dcMem,rCl.left,rCl.top,SRCCOPY);
dcMem.SelectObject(pOldBmp);
}
Regards,
Andrzej Markowski
|