www.pudn.com > TabBar.rar > MainView.cpp
// mainview.cpp : implementation of the CMainView class.
#include "stdafx.h"
#include "mainview.h"
#include "tabbarctrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainView Construction\Destruction
IMPLEMENT_DYNCREATE(CMainView, CView)
CMainView::CMainView()
{
}
CMainView::~CMainView()
{
}
BEGIN_MESSAGE_MAP(CMainView, CView)
//{{AFX_MSG_MAP(CMainView)
ON_WM_SIZE()
ON_MESSAGE(WM_TABBARCTRL_NOTIFY, OnTabBarCtrlNotify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainView Operations
void CMainView::ShowMessage(CDC *pDC)
{
CRect rcClient;
GetClientRect(&rcClient);
int nHeight = 20; // font height
if(rcClient.Height() >= nHeight)
{
int nOldMode = pDC->SetBkMode(TRANSPARENT);
rcClient.top = (rcClient.Height() - nHeight) / 2;
rcClient.bottom = rcClient.top + nHeight;
pDC->DrawText(m_Message, &rcClient, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_PATH_ELLIPSIS);
pDC->SetBkMode(nOldMode);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMainView Overrides
void CMainView::OnDraw(CDC *pDC)
{
// get client rectangle
CRect rcClient;
GetClientRect(&rcClient);
// create a bitmap
CBitmap bmpMemory;
bmpMemory.CreateCompatibleBitmap(pDC, rcClient.Width(), rcClient.Height());
// create a memory device context
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
// select the bitmap into the memory device context
CBitmap* pbmpMemory = dcMemory.SelectObject(&bmpMemory);
// fill the memory device context with the background color
dcMemory.FillSolidRect(rcClient, GetSysColor(COLOR_WINDOW));
// show message
ShowMessage(&dcMemory);
// copy the memory device context to the screen
pDC->BitBlt(0, 0, rcClient.Width(), rcClient.Height(), &dcMemory, 0, 0, SRCCOPY);
// release the gdi resource
dcMemory.SelectObject(pbmpMemory);
bmpMemory.DeleteObject();
dcMemory.DeleteDC();
}
BOOL CMainView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = AfxRegisterWndClass(0);
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainView Message handlers
void CMainView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
Invalidate(FALSE);
}
long CMainView::OnTabBarCtrlNotify(WPARAM wParam, LPARAM lParam)
{
switch(wParam)
{
case NM_TB_FOLDERCHANGE:
{
CPoint point(lParam);
m_Message.Format("the folder %d is no active and the folder %d is active", point.y, point.x);
}
break;
case NM_TB_ITEMCHANGE:
{
CPoint point(lParam);
m_Message.Format("the item %d in the folder %d is selected", point.x, point.y);
}
break;
case NM_TB_ADDFOLDER:
m_Message.Format("the folder %d is add", lParam);
break;
case NM_TB_INSERTITEM:
{
CPoint point(lParam);
m_Message.Format("the item %d in the folder %d is add", point.x, point.y);
}
break;
case NM_TB_ONFOLDER:
if(lParam == DWORD(-1L))
m_Message.Format("no folder is hilighted");
else
m_Message.Format("the folder %d is hilighted", lParam);
break;
case NM_TB_ONITEM:
if(lParam == DWORD(-1L))
m_Message.Format("no item is hilighted");
else
{
CPoint point(lParam);
m_Message.Format("the item %d in the folder %d is hilighted", point.x, point.y);
}
break;
case NM_TB_REMOVEFOLDER:
m_Message.Format("the folder %d is removed", lParam);
break;
case NM_TB_REMOVEITEM:
{
CPoint point(lParam);
m_Message.Format("the item %d in the folder %d is removed", point.x, point.y);
}
break;
case NM_TB_RESETALLITEMS:
m_Message.Format("all items are unselected");
break;
case NM_TB_DRAGITEMBEGIN:
{
CPoint point(lParam);
m_Message.Format("the item %d in the folder %d is dragging", point.x, point.y);
}
break;
case NM_TB_DRAGITEMEND:
m_Message.Format("finish the dragging");
break;
case NM_TB_ITEMMOVE:
{
CPoint point(lParam);
m_Message.Format("the item %d move to the folder %d", point.x, point.y);
}
break;
case NM_TB_DBLCLKITEM:
{
CPoint point(lParam);
m_Message.Format("the item %d in the folder %d is double clicked", point.x, point.y);
}
break;
case NM_TB_FOLDERENDEDIT:
m_Message.Format("the folder %d label is edited", lParam);
}
if(wParam >= NM_TB_FOLDERCHANGE && wParam <= NM_TB_FOLDERENDEDIT && !m_Message.IsEmpty())
Invalidate(FALSE);
return 0;
}