OAMTABCTRL.CPP
资源名称:SNMP范例源代码.zip [点击查看]
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:6k
源码类别:
SNMP编程
开发平台:
MultiPlatform
- // OAMTabCtrl.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OAM.h"
- #include "OAMTabCtrl.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // COAMTabCtrl
- extern HBITMAP hBkBitmap;
- extern COLORREF _clrText;
- COAMTabCtrl::COAMTabCtrl()
- {
- m_crSelColour = RGB(0,0,255);
- m_crUnselColour = _clrText;
- }
- COAMTabCtrl::~COAMTabCtrl()
- {
- if(m_SelFont.GetSafeHandle())
- m_SelFont.DeleteObject();
- if(m_UnselFont.GetSafeHandle())
- m_UnselFont.DeleteObject();
- }
- BEGIN_MESSAGE_MAP(COAMTabCtrl, CTabCtrl)
- //{{AFX_MSG_MAP(COAMTabCtrl)
- ON_WM_ERASEBKGND()
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // COAMTabCtrl message handlers
- BOOL COAMTabCtrl::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- CRect rcChild;
- GetClientRect(&rcChild);
- rcChild.DeflateRect(3,3);
- rcChild.bottom -= 21;
- pDC->ExcludeClipRect(rcChild);
- int result;// = CControlBar::OnEraseBkgnd(pDC);
- if(hBkBitmap)
- {
- CRect rectClient;
- GetClientRect(rectClient);
- rectClient.top = rectClient.bottom - 21;
- CBitmap * bp = CBitmap::FromHandle(hBkBitmap);
- pDC->FillRect(rectClient,&CBrush(bp));
- result = TRUE;
- }
- else
- {
- result = CTabCtrl::OnEraseBkgnd(pDC);
- }
- return result;//CTabCtrl::OnEraseBkgnd(pDC);
- }
- void COAMTabCtrl::PreSubclassWindow()
- {
- // TODO: Add your specialized code here and/or call the base class
- CTabCtrl::PreSubclassWindow();
- // ModifyStyle(0, TCS_OWNERDRAWFIXED);
- }
- BOOL COAMTabCtrl::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Add your specialized code here and/or call the base class
- // cs.style |= TCS_OWNERDRAWFIXED;
- return CTabCtrl::PreCreateWindow(cs);
- }
- void COAMTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- CRect rect = lpDrawItemStruct->rcItem;
- int nTabIndex = lpDrawItemStruct->itemID;
- if (nTabIndex < 0) return;
- BOOL bSelected = (nTabIndex == GetCurSel());
- char label[64];
- TC_ITEM tci;
- tci.mask = TCIF_TEXT|TCIF_IMAGE;
- tci.pszText = label;
- tci.cchTextMax = 63;
- if (!GetItem(nTabIndex, &tci )) return;
- CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
- if (!pDC) return;
- int nSavedDC = pDC->SaveDC();
- // For some bizarre reason the rcItem you get extends above the actual
- // drawing area. We have to workaround this "feature".
- int nTopOffset;
- if(GetStyle() & TCS_BOTTOM)
- nTopOffset = ::GetSystemMetrics(SM_CYEDGE);
- else
- nTopOffset = -::GetSystemMetrics(SM_CYEDGE);
- rect.top -= nTopOffset;
- pDC->SetBkMode(TRANSPARENT);
- if(hBkBitmap)
- {
- CBitmap * bp = CBitmap::FromHandle(hBkBitmap);
- pDC->FillRect(rect,&CBrush(bp));
- }
- else
- pDC->FillSolidRect(rect, ::GetSysColor(COLOR_BTNFACE));
- // Draw image
- CImageList* pImageList = GetImageList();
- if (pImageList && tci.iImage >= 0) {
- rect.left += pDC->GetTextExtent(_T(" ")).cx; // Margin
- // Get height of image so we
- IMAGEINFO info;
- pImageList->GetImageInfo(tci.iImage, &info);
- CRect ImageRect(info.rcImage);
- int nYpos = rect.top+nTopOffset;
- pImageList->Draw(pDC, tci.iImage, CPoint(rect.left, nYpos), ILD_TRANSPARENT);
- rect.left += ImageRect.Width();
- }
- if (bSelected) {
- pDC->SetTextColor(m_crSelColour);
- pDC->SelectObject(&m_SelFont);
- rect.top += nTopOffset;
- pDC->DrawText(label, rect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
- } else {
- pDC->SetTextColor(m_crUnselColour);
- pDC->SelectObject(&m_UnselFont);
- pDC->DrawText(label, rect, DT_SINGLELINE|DT_BOTTOM|DT_CENTER);
- }
- pDC->RestoreDC(nSavedDC);
- }
- void COAMTabCtrl::SetColours(COLORREF bSelColour, COLORREF bUnselColour)
- {
- m_crSelColour = bSelColour;
- m_crUnselColour = bUnselColour;
- Invalidate();
- }
- void COAMTabCtrl::SetFonts(CFont* pSelFont, CFont* pUnselFont)
- {
- // ASSERT(pSelFont && pUnselFont);
- LOGFONT lFont;
- int nSelHeight, nUnselHeight;
- if(m_SelFont.GetSafeHandle())
- m_SelFont.DeleteObject();
- if(m_UnselFont.GetSafeHandle())
- m_UnselFont.DeleteObject();
- pSelFont->GetLogFont(&lFont);
- m_SelFont.CreateFontIndirect(&lFont);
- nSelHeight = lFont.lfHeight;
- pUnselFont->GetLogFont(&lFont);
- m_UnselFont.CreateFontIndirect(&lFont);
- nUnselHeight = lFont.lfHeight;
- SetFont( (nSelHeight > nUnselHeight)? &m_SelFont : &m_UnselFont);
- }
- void COAMTabCtrl::SetFonts(int nSelWeight, BOOL bSelItalic, BOOL bSelUnderline,
- int nUnselWeight, BOOL bUnselItalic, BOOL bUnselUnderline)
- {
- // Free any memory currently used by the fonts.
- if(m_SelFont.GetSafeHandle())
- m_SelFont.DeleteObject();
- if(m_UnselFont.GetSafeHandle())
- m_UnselFont.DeleteObject();
- // Get the current font
- LOGFONT lFont;
- CFont *pFont = GetFont();
- if (pFont)
- pFont->GetLogFont(&lFont);
- else {
- NONCLIENTMETRICS ncm;
- ncm.cbSize = sizeof(NONCLIENTMETRICS);
- VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0));
- lFont = ncm.lfMessageFont;
- }
- // Create the "Selected" font
- lFont.lfWeight = nSelWeight;
- lFont.lfItalic = bSelItalic;
- lFont.lfUnderline = bSelUnderline;
- m_SelFont.CreateFontIndirect(&lFont);
- // Create the "Unselected" font
- lFont.lfWeight = nUnselWeight;
- lFont.lfItalic = bUnselItalic;
- lFont.lfUnderline = bUnselUnderline;
- m_UnselFont.CreateFontIndirect(&lFont);
- SetFont( (nSelWeight > nUnselWeight)? &m_SelFont : &m_UnselFont);
- }
- void COAMTabCtrl::OnSize(UINT nType, int cx, int cy)
- {
- CTabCtrl::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- // ResizeTabs();
- }
- void COAMTabCtrl::ResizeTabs()
- {
- CRect rc;
- GetClientRect(rc);
- int iNumWin = GetItemCount();
- int x = 140; // def item width
- if ((x+4) * iNumWin > rc.Width()) x = (rc.Width()) / iNumWin - 4;
- CRect rcEx;
- GetItemRect(0, rcEx);
- SetItemSize(CSize(x,rcEx.Height()));
- }