#pragma
once
#include
"TestView.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class
CMainDoc;
class
CMainView : public CView
{
protected
:
CMainView();
DECLARE_DYNCREATE( CMainView )
// Attributes
public
:
CMainDoc* GetDocument();
virtual ~CMainView();
// Operations
public
:
virtual BOOL PreCreateWindow( CREATESTRUCT& cs );
#ifdef
_DEBUG
virtual void AssertValid() const;
virtual void Dump( CDumpContext& dc ) const;
#endif
virtual void CalcWindowRect( LPRECT lpClientRect, UINT nAdjustType = adjustBorder );
protected
:
// called first time after construct
virtual void OnInitialUpdate();
virtual BOOL OnPreparePrinting( CPrintInfo *pInfo );
afx_msg void OnDestroy();
afx_msg BOOL OnEraseBkgnd( CDC *pDC );
DECLARE_MESSAGE_MAP()
void OnEmptyCommand( UINT );
virtual void OnDraw( CDC* /*pDC*/ );
afx_msg void OnPaint();
afx_msg void OnNcPaint();
public
:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
protected
:
virtual void OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/);
HBITMAP hBitmap;
public
:
afx_msg void OnSize(UINT nType, int cx, int cy);
};
My CPP
#include
"stdafx.h"
#include
"CMainApp.h"
#include
"CMainDoc.h"
#include
"CMainView.h"
#include
"CMainFrame.h"
#include
"CWorkspaceView.h"
#include
"CDoubleBuffer.h"
#ifdef
_DEBUG
#define
new DEBUG_NEW
#undef
THIS_FILE
static
char THIS_FILE[] = __FILE__;
#endif
/*************************************************************************************************************************************************************\
*
* Message maps
*
* DESCRIPTION:
* Message maps
*
\*************************************************************************************************************************************************************/
IMPLEMENT_DYNCREATE
( CMainView, CView )
BEGIN_MESSAGE_MAP
( CMainView, CView )
ON_WM_DESTROY()
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_NCPAINT()
ON_WM_SIZE()
END_MESSAGE_MAP
()
/*************************************************************************************************************************************************************\
*
* CAlphabetNamesView()
*
* DESCRIPTION:
* Constructor
*
\*************************************************************************************************************************************************************/
CMainView
::CMainView()
{
hBitmap = (HBITMAP)::LoadImage( NULL, "C:\\test.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
}
/*************************************************************************************************************************************************************\
*
* ~CAlphabetNamesView()
*
* DESCRIPTION:
* Destructor
*
\*************************************************************************************************************************************************************/
CMainView
::~CMainView()
{
}
/*************************************************************************************************************************************************************\
*
* BOOL PreCreateWindow( CREATESTRUCT& cs )
*
* DESCRIPTION:
* Precreate window style
*
\*************************************************************************************************************************************************************/
BOOL
CMainView::PreCreateWindow( CREATESTRUCT& cs )
{
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
return CView::PreCreateWindow( cs );
}
/*************************************************************************************************************************************************************\
*
* void OnInitialUpdate()
*
* DESCRIPTION:
* Initial update on view. Called only once
*
\*************************************************************************************************************************************************************/
void
CMainView::OnInitialUpdate()
{
CView::OnInitialUpdate();
ModifyStyleEx( WS_EX_CLIENTEDGE , 0 );
ModifyStyle( 0, WS_BORDER );
ULONG ulStyle = ::GetClassLong( GetSafeHwnd(), GCL_STYLE );
if( !( ulStyle & CS_DROPSHADOW ) )
::SetClassLong( GetSafeHwnd(), GCL_STYLE, CS_DROPSHADOW );
}
/*************************************************************************************************************************************************************\
*
* void OnPreparePrinting( CPrintInfo *pInfo )
*
* DESCRIPTION:
* Prepare printing
*
\*************************************************************************************************************************************************************/
BOOL
CMainView::OnPreparePrinting( CPrintInfo *pInfo )
{
// default preparation
return DoPreparePrinting( pInfo );
}
/*************************************************************************************************************************************************************\
*
* void OnDestroy( )
*
* DESCRIPTION:
* Destroy view
*
\*************************************************************************************************************************************************************/
void
CMainView::OnDestroy()
{
CView::OnDestroy();
}
#ifdef
_DEBUG
/*************************************************************************************************************************************************************\
*
* void AssertValid( ) const
*
* DESCRIPTION:
* Assert
*
\*************************************************************************************************************************************************************/
void
CMainView::AssertValid() const
{
CView::AssertValid();
}
/*************************************************************************************************************************************************************\
*
* void Dump( CDumpContext& dc ) const
*
* DESCRIPTION:
* Dump
*
\*************************************************************************************************************************************************************/
void
CMainView::Dump( CDumpContext& dc ) const
{
CView::Dump( dc );
}
/*************************************************************************************************************************************************************\
*
* CAlphabetNamesDoc* CAlphabetNamesView::GetDocument()
*
* DESCRIPTION:
* Return document object pointer
*
\*************************************************************************************************************************************************************/
CMainDoc
* CMainView::GetDocument()
{
ASSERT( m_pDocument->IsKindOf( RUNTIME_CLASS( CMainDoc ) ) ) ;
return (CMainDoc *)m_pDocument;
}
#endif
//_DEBUG
/*************************************************************************************************************************************************************\
*
* void OnDraw ( CDC *pDC )
*
* DESCRIPTION:
* View drawing function
*
\*************************************************************************************************************************************************************/
void
CMainView::OnDraw( CDC *pDC )
{
return;
}
/*************************************************************************************************************************************************************\
*
* void CalcWindowRect( LPRECT lpClientRect, UINT nAdjustType )
*
* DESCRIPTION:
* Calculates window rect
*
\*************************************************************************************************************************************************************/
void
CMainView::CalcWindowRect( LPRECT lpClientRect, UINT nAdjustType )
{
CView::CalcWindowRect( lpClientRect, nAdjustType );
int nWidth = 200;
int nHeight = 200;;
int nClientWidth = lpClientRect->right - lpClientRect->left;
int nBorders = max(8, nClientWidth - nWidth);
int nTopMargin = max(4, 40);
lpClientRect->top += nTopMargin;
lpClientRect->left += 300;
lpClientRect->right -= 300;
lpClientRect->bottom -= 30;
}
/*************************************************************************************************************************************************************\
*
* void OnMouseMove( UINT nFlags, CPoint point )
*
* DESCRIPTION:
* WM_MOUSEMOVE message handler
*
\*************************************************************************************************************************************************************/
void
CMainView::OnMouseMove( UINT nFlags, CPoint point )
{
CString cs;
cs.Format( "X=%.3d : Y=%.3d", point.x, point.y );
CMainFrame* pFrame = (CMainFrame *)AfxGetMainWnd();
if ( pFrame )
{
pFrame->m_wndStatusBar.SetPaneText( pFrame->m_wndStatusBar.CommandToIndex( ID_INDICATOR_POSITION ), cs, TRUE );
}
CView::OnMouseMove(nFlags, point);
}
/*************************************************************************************************************************************************************\
*
* void OnUpdate( CView *pSender, LPARAM lHint, CObject *pHint )
*
* DESCRIPTION:
* OnUpdate view function called by document object
*
\*************************************************************************************************************************************************************/
void
CMainView::OnUpdate( CView *pSender, LPARAM lHint, CObject *pHint )
{
int nParam = (int)lHint;
//if ( nParam == 1 )
// m_strFileName = *(CString *)pHint;
}
/*************************************************************************************************************************************************************\
*
* void OnPaint()
*
* DESCRIPTION:
* OnPaint message handler
*
\*************************************************************************************************************************************************************/
void
CMainView::OnPaint()
{
CPaintDC dc( this );
CXTPWindowRect rc( this );
//GetClientRect( &rcClient );
ScreenToClient( &rc );
CXTMemDC memDC( &dc, &rc );
rc.DeflateRect( 20, 20, 20, 20 );
memDC.FillSolidRect( &rc, RGB( 255, 0, 0 ) );
}
/*************************************************************************************************************************************************************\
*
* void OnEraseBkgnd( CDC *pDC )
*
* DESCRIPTION:
* WM_ERASEBKGND message handler
*
\*************************************************************************************************************************************************************/
BOOL
CMainView::OnEraseBkgnd( CDC *pDC )
{
return TRUE;
}
/*************************************************************************************************************************************************************\
*
* void OnNcPaint()
*
* DESCRIPTION:
* OnNcPaint message handler
*
\*************************************************************************************************************************************************************/
void
CMainView::OnNcPaint()
{
CView::OnNcPaint();
}
/*************************************************************************************************************************************************************\
*
* void OnSize( UINT nType, int cx, int cy )
*
* DESCRIPTION:
* WM_SIZE method
*
\*************************************************************************************************************************************************************/
void
CMainView::OnSize( UINT nType, int cx, int cy )
{
CView::OnSize( nType, cx, cy );
}