sampleView.cpp
上传用户:hicheon
上传日期:2007-02-06
资源大小:34k
文件大小:5k
- // sampleView.cpp : implementation of the CSampleView class
- //
- #include "stdafx.h"
- #include "sample.h"
- #include "sampleDoc.h"
- #include "sampleView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSampleView
- IMPLEMENT_DYNCREATE(CSampleView, CView)
- BEGIN_MESSAGE_MAP(CSampleView, CView)
- //{{AFX_MSG_MAP(CSampleView)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_COMMAND(IDC_ONLY_SELECTED_ITEMS, OnOnlySelectedItems)
- ON_UPDATE_COMMAND_UI(IDC_ONLY_SELECTED_ITEMS, OnUpdateOnlySelectedItems)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSampleView construction/destruction
- CSampleView::CSampleView()
- {
- // TODO: add construction code here
- m_bOnlySelectedItems = FALSE;
- }
- CSampleView::~CSampleView()
- {
- }
- BOOL CSampleView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSampleView drawing
- void CSampleView::OnDraw(CDC* pDC)
- {
- CSampleDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSampleView printing
- BOOL CSampleView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CSampleView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
- {
- // TODO: add extra initialization before printing
- m_lstPPListBox.OnBeginPrinting(pDC, pInfo);
- }
- void CSampleView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
- {
- // TODO: add cleanup after printing
- m_lstPPListBox.OnEndPrinting(pDC, pInfo);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSampleView diagnostics
- #ifdef _DEBUG
- void CSampleView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CSampleView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CSampleDoc* CSampleView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSampleDoc)));
- return (CSampleDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CSampleView message handlers
- int CSampleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // TODO: Add your specialized creation code here
- CSampleApp* pApp = (CSampleApp*) AfxGetApp();
- CRect rect;
- rect.SetRectEmpty();
- if( pApp->m_bSingleSelection )
- {
- if( m_lstPPListBox.Create( WS_CHILD | WS_BORDER | WS_VSCROLL, rect, this, 100 ) == -1 )
- return -1;
- }
- else
- {
- if( m_lstPPListBox.Create( WS_CHILD | LBS_HASSTRINGS | LBS_MULTIPLESEL
- | LBS_EXTENDEDSEL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_USETABSTOPS | WS_VSCROLL,
- rect, this, 100 ) == -1 )
- return -1;
- }
- m_lstPPListBox.SetPrintTitle();
- m_lstPPListBox.ShowWindow (SW_SHOW);
-
- return 0;
- }
- void CSampleView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
-
- // TODO: Add your message handler code here
- // resize listbox, too
- if( cx > 0 && cy > 0 )
- m_lstPPListBox.MoveWindow( 0, 0, cx, cy );
- }
- void CSampleView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
-
- // TODO: Add your specialized code here and/or call the base class
- m_lstPPListBox.AddString( "da...da...da...da...");
- m_lstPPListBox.AddString( "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890xyzp");
- for( int i = 0; i <= 100; i++ )
- {
- CString sItem;
- sItem.Format( "%d", i );
- sItem = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + sItem;
- m_lstPPListBox.AddString( sItem );
- }
- m_lstPPListBox.SetFocus();
- m_lstPPListBox.SetCurSel( 0 );
- }
- void CSampleView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
- {
- // TODO: Add your specialized code here and/or call the base class
- m_lstPPListBox.OnPrint(pDC, pInfo);
-
- // CView::OnPrint(pDC, pInfo);
- }
- void CSampleView::OnOnlySelectedItems()
- {
- // TODO: Add your command handler code here
- if( m_lstPPListBox.GetOnlySelectedItems() )
- {
- m_lstPPListBox.SetOnlySelectedItems( false );
- m_bOnlySelectedItems = FALSE;
- }
- else
- {
- m_lstPPListBox.SetOnlySelectedItems( true );
- m_bOnlySelectedItems = TRUE;
- }
- }
- void CSampleView::OnUpdateOnlySelectedItems(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck( m_bOnlySelectedItems );
- }