August 13th, 1999, 07:45 AM
Hi,
I am using CSliderCtrl in one of my applications. I am creating the control with tics say 12 one for each month. Now beside the slider control, say on right side in front of each of the tic mark I would like to put a text describing each of the month from Jan thru' Dec.
How do I do it? How to add text right next to the tic mark on slider control???
jlhavens
August 22nd, 1999, 05:03 PM
Were you ever able to do this?
I have a method but, it requires constructing a static control next to the slider and filling in the tic labels. You can do this dynamically or using the dialog editor.
I wasn't able to get labels to stick inside the slider control. Every time I moved the slider they disappeared.
The code below is for a vertical box and writing numbers next to the tics. I had 16 tic marks to label.
I was using it in a PropertyPage and it was necessary to rerun this when the screen was repainted (WM_PAINT message received). I didn't try it on a regular dialog box.
void slidedlg::Print()
{ CFont axisFont;
CRect rect;
CString str;
CWnd * pWnd=GetDlgItem( IDC_STATIC_TEXT );
CDC *pDC = pWnd->GetDC();
axisFont.CreateFont (14, 0, 0, 0, 300,
FALSE, FALSE, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_SWISS, "Arial") ;
pDC->SelectObject(&axisFont) ;
pWnd->GetWindowRect(&rect);
pDC->SetBkMode(TRANSPARENT );//OPAQUE
pDC->SetTextAlign (TA_RIGHT|TA_BOTTOM);
float j=(float(rect.bottom-rect.top-26))/15;
for(int i=0;i<16;i++){
str.Format("%d",120-(10*i));
pDC->TextOut(15,20+(i*j),str);
// pDC->DrawState( CPoint(1,20+(i*j)), CSize(0,0), str, DST_PREFIXTEXT, TRUE, 0, (CBrush*)NULL );
}
}