|
// CeTitleBar.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "CeTitleBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//---------------------------------------------------------------------------
//
// CCeTitleBar
//
//---------------------------------------------------------------------------
CCeTitleBar::CCeTitleBar()
: m_nHeight (17)
{
LOGFONT lf;
long nHeight;
//
// Create the option font
//
// Points 8 : -11
// 9 : -12
// 10 : -13
nHeight = -11;//(LONG)(-8 * pDC.GetDeviceCaps(LOGPIXELSY) / 72);
lf.lfHeight = nHeight;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_BOLD;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = 0;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
lstrcpy(lf.lfFaceName, TEXT("Tahoma"));
m_fntDefault.CreateFontIndirect(&lf);
}
CCeTitleBar::~CCeTitleBar()
{
}
BEGIN_MESSAGE_MAP(CCeTitleBar, CControlBar)
//{{AFX_MSG_MAP(CCeTitleBar)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
//
// CCeTitleBar interface to CControlBar
//
//---------------------------------------------------------------------------
// CCeTitleBar::OnUpdateCmdUI
//
// Pure virtual from CControlBar.
// Dummy implementation: not needed
//
void CCeTitleBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
}
// CCeTitleBar::CalcFixedLayout
//
// Make sure the bar height is 17 pixels.
//
CSize CCeTitleBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
CSize size(0,0);
CFrameWnd* pWnd = GetDockingFrame();
if(pWnd)
{
CRect rc;
pWnd->GetClientRect(&rc);
if(bHorz)
{
size.cx = rc.Width();
size.cy = m_nHeight;
}
}
return size;
}
// CCeTitleBar::CalcDynamicLayout
//
// Make sure the bar height is 17 pixels.
//
CSize CCeTitleBar::CalcDynamicLayout(int nLength, DWORD nMode)
{
CSize size(0,0);
CFrameWnd* pWnd = GetDockingFrame();
if(pWnd)
{
CRect rc;
pWnd->GetClientRect(&rc);
size.cx = rc.Width();
size.cy = m_nHeight;
}
return size;
}
//---------------------------------------------------------------------------
//
// CCeTitleBar operations
//
//---------------------------------------------------------------------------
// CCeTitleBar::Create
//
// Creates the letter bar
//
BOOL CCeTitleBar::Create(CWnd *pParentWnd, UINT nID)
{
CRect rc;
m_dwStyle = CBRS_BORDER_BOTTOM | CBRS_ALIGN_TOP;
pParentWnd->GetClientRect(&rc);
return CControlBar::Create(NULL, _T(""), WS_CHILD | WS_VISIBLE,
rc, pParentWnd, nID);
}
void CCeTitleBar::SetTitle(LPCTSTR pszTitle, BOOL bRepaint)
{
m_strTitle = pszTitle;
if(bRepaint)
InvalidateRect(NULL);
}
void CCeTitleBar::SetTitle(UINT nStrID, BOOL bRepaint)
{
m_strTitle.LoadString(nStrID);
if(bRepaint)
InvalidateRect(NULL);
}
//---------------------------------------------------------------------------
//
// CCeTitleBar message handlers
//
//---------------------------------------------------------------------------
// CCeTitleBar::OnPaint
//
// Paints the title
//
void CCeTitleBar::OnPaint()
{
CPaintDC dc(this);
CRect rc;
CFont* pFont;
CBrush brshBack(RGB(255, 255, 255)),
* pBrsh;
CPen penNull(PS_NULL, 0, 0),
* pPen;
int nBkMode;
COLORREF crText(RGB(0, 0, 156)),
crOld;
GetClientRect(&rc);
pBrsh = dc.SelectObject(&brshBack);
pPen = dc.SelectObject(&penNull);
dc.Rectangle(&rc);
dc.SelectObject(pBrsh);
dc.SelectObject(pPen);
dc.MoveTo(rc.left, rc.bottom - 1);
dc.LineTo(rc.right, rc.bottom - 1);
rc.left += 4;
rc.top += 1;
pFont = dc.SelectObject(&m_fntDefault);
nBkMode = dc.SetBkMode(TRANSPARENT);
crOld = dc.SetTextColor(crText);
dc.DrawText(m_strTitle, -1, &rc, DT_LEFT | DT_SINGLELINE);
dc.SetTextColor(crOld);
dc.SetBkMode(nBkMode);
dc.SelectObject(pFont);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.