gusucode.com > 基于VC编程界面编程高级应用技术源码程序 > VC界面编程高级应用技术/code/1/ViewOutlookdemo/ViewOutlook.cpp
// ViewOutlook.cpp : implementation file // #include "stdafx.h" #include "ViewOutlook.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CViewOutlook IMPLEMENT_DYNCREATE(CViewOutlook, CView) CViewOutlook::CViewOutlook() { } CViewOutlook::~CViewOutlook() { } BEGIN_MESSAGE_MAP(CViewOutlook, CView) //{{AFX_MSG_MAP(CViewOutlook) ON_WM_CREATE() ON_WM_SIZE() ON_WM_ERASEBKGND() ON_WM_CTLCOLOR_REFLECT() //}}AFX_MSG_MAP ON_MESSAGE( OBN_SELENDOK, OnSelEndOK ) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CViewOutlook drawing void CViewOutlook::OnDraw(CDC* pDC) { CDocument* pDoc = GetDocument(); // TODO: add draw code here } ///////////////////////////////////////////////////////////////////////////// // CViewOutlook diagnostics #ifdef _DEBUG void CViewOutlook::AssertValid() const { CView::AssertValid(); } void CViewOutlook::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CViewOutlook message handlers #include "resource.h" static UINT Icons[] = { IDI_ICON_OUTLOOK, IDI_ICON_INBOX, IDI_ICON_CALENDAR, IDI_ICON_CONTACTS, IDI_ICON_TASKS, IDI_ICON_JOURNAL, IDI_ICON_NOTES, IDI_ICON_DELETED, IDI_ICON_PUBLIC, IDI_ICON_DRAFTS, IDI_ICON_OUTBOX, IDI_ICON_SENT, }; static LPCTSTR Title[] = { _T("今日"), _T("收件箱"), _T("日历"), _T("联系人"), _T("任务"), _T("安排"), _T("便笺"), _T("已删除"), _T("公用"), _T("草稿"), _T("发件箱"), _T("发送"), }; CContentItems ContentInfo[] = { CContentItems ( 0, Title[ 0]), CContentItems ( 1, Title[ 1]), CContentItems ( 2, Title[ 2]), CContentItems ( 3, Title[ 3]), CContentItems ( 4, Title[ 4]), CContentItems ( 5, Title[ 5]), CContentItems ( 6, Title[ 6]), CContentItems ( 7, Title[ 7]), CContentItems ( 8, Title[ 8]), CContentItems ( 9, Title[ 9]), CContentItems (10, Title[10]), CContentItems (11, Title[11]), }; int CViewOutlook::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; //建立翻页箭头 if (!m_Pager.Create(WS_CHILD|WS_VISIBLE|PGS_VERT, CRect(0,0,0,0), this, IDC_STATIC )) { TRACE0("建立翻页箭头出错\n"); return -1; } //设置列表框控件布局风格 DWORD dwStyle = WS_CHILD | WS_VISIBLE | LBS_OWNERDRAWVARIABLE | LBS_NOINTEGRALHEIGHT | WS_TABSTOP; //建立列表框控件,设定其父窗口为建立翻页箭头 if (!m_OutlookBar.Create( dwStyle, CRect(0,0,0,0), &m_Pager, IDC_OUTBAR )) { TRACE0("建立列表框控件出错n"); return -1; } int nArraySize = sizeof(Icons)/sizeof(Icons[0]); //将列表框控件与视图关联 m_OutlookBar.SetOwner (this); // 设置建立翻页箭头的滚动区间 // 12*图标高 m_Pager.SetScrollArea( NULL, nArraySize*OB_CYBUTTON ); // 设置建立翻页箭头的滚动区间 m_Pager.SetChild(m_OutlookBar.GetSafeHwnd()); m_Pager.SetButtonSize(15); //建立图像列表并追加图标 m_ImageList.Create (32, 32, TRUE, 2, 1); for (int i =0; i < nArraySize; ++i) { m_ImageList.Add(AfxGetApp()->LoadIcon(Icons[i])); } //设置图像列表 m_OutlookBar.SetImageLists(&m_ImageList, &m_ImageList); //设置按钮项目 m_OutlookBar.SetItems(ContentInfo, nArraySize); return 0; } void CViewOutlook::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); if(m_Pager.GetSafeHwnd()) { //显示翻页箭头 m_Pager.MoveWindow(0,0,cx,cy-2); } } void CViewOutlook::OnSelEndOK(UINT lParam, LONG wParam) { UINT uIndex = lParam; //根据按钮的ID值进行消息响应 switch( wParam ) { case IDC_OUTBAR: AfxMessageBox(Title[uIndex]); break; } } BOOL CViewOutlook::OnEraseBkgnd(CDC* pDC) { //不进行默认的处理 return 1; } HBRUSH CViewOutlook::CtlColor(CDC* pDC, UINT nCtlColor) { CBrush m_brHollow; m_brHollow.CreateStockObject(NULL_BRUSH); //NULL_BRUSH:不进行默认的处理 return m_brHollow; }