Thursday, May 14, 2009

MFC - Vertical button with text

Ever wanted to place a vertical button on your application? use this code





1. You will have to Subclass CButton
2. change the fon't lfEscapement ,lfOrientation to 2700
GetFont(&tLogFont);
tLogFont.lfEscapement = tLogFont.lfOrientation = 2700;
m_bRotation = bRotation;
SetFont(&tLogFont);

3. overide the ::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
function

4. Draw the caption

int nAlign = _pDC->SetTextAlign (TA_BASELINE);
CRect rc;
GetClientRect(rc);
CPoint pt;
CSize sSizeExt = _pDC->GetTextExtent(sCaption);
GetViewportOrgEx (_pDC->m_hDC,&pt) ;
SetViewportOrgEx (_pDC->m_hDC,rc.Width() / 2,
rc.Height() / 2, NULL) ;
int nPosOfStart =(rc.Height()/2)+(rc.Height()-sSizeExt.cx)/2;
if(sSizeExt.cx>rc.Height()) nPosOfStart = rc.Height()/2;
int nPosX = min(0,(sSizeExt.cy-rc.Width())/2);
_pDC->TextOut (nPosX, ((nState-1) *rc.Height()) +
nPosOfStart, sCaption) ;
SetViewportOrgEx (_pDC->m_hDC,pt.x / 2, pt.y / 2, NULL) ;
_pDC->SetTextAlign (nAlign);


0 תגובות:

Post a Comment

 
Home | About | Link | Link
Simple Proff Blogger Template Created By Herro | Inspiring By Busy Bee Woo Themes