在CView中画上bitmap图,在CView中画上dialog,更换左上角icon,在CView上面画线(橡皮筋)

代码
// ex_14View.cpp : implementation of the CEx_14View class
//

#include
"stdafx.h"
#include
"ex_14.h"

#include
"ex_14Doc.h"
#include
"ex_14View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEx_14View

IMPLEMENT_DYNCREATE(CEx_14View, CView)

BEGIN_MESSAGE_MAP(CEx_14View, CView)
//{{AFX_MSG_MAP(CEx_14View)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
//}}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()

/////////////////////////////////////////////////////////////////////////////
// CEx_14View construction/destruction

CEx_14View::CEx_14View()
{
// TODO: add construction code here

}

CEx_14View::
~CEx_14View()
{
}

BOOL CEx_14View::PreCreateWindow(CREATESTRUCT
& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEx_14View drawing

void CEx_14View::OnDraw(CDC* pDC)
{
CEx_14Doc
* pDoc = GetDocument();
ASSERT_VALID(pDoc);
////////////////////////////////////////////////////////////画bitmap图
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
//创建兼容的内存设备描述表
CBitmap *pOldBitmap=MemDC.SelectObject(&bitmap);
BITMAP bm;
bitmap.GetBitmap(
&bm);
pDC
->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBitmap);

////////////////////////////////////////////////////////////////
// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CEx_14View printing

BOOL CEx_14View::OnPreparePrinting(CPrintInfo
* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CEx_14View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CEx_14View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEx_14View diagnostics

#ifdef _DEBUG
void CEx_14View::AssertValid() const
{
CView::AssertValid();
}

void CEx_14View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CEx_14Doc
* CEx_14View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument
->IsKindOf(RUNTIME_CLASS(CEx_14Doc)));
return (CEx_14Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEx_14View message handlers

void CEx_14View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(nFlags&&MK_LBUTTON)
{
CClientDC dc(
this);
int nDrawMode=dc.GetROP2();//获取当前的绘图模式
dc.SetROP2(R2_NOTXORPEN);
dc.MoveTo(m_StartPoint);
dc.LineTo(m_LastEndPoint);
dc.MoveTo(m_StartPoint);
dc.LineTo(point);
m_LastEndPoint
=point;
dc.SetROP2(nDrawMode);

}


CView::OnMouseMove(nFlags, point);
}

void CEx_14View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_StartPoint=point;
m_LastEndPoint
= point;
SetCapture();
/*SetCapture():
函数功能:该函数在属于当前线程的指定窗口里设置鼠标捕获。一旦窗口捕获了鼠标,所有鼠标输入都针对该窗口,无论光标是否在窗口的边界内。同一时刻只能有一个窗口捕获鼠标。如果鼠标光标在另一个线程创建的窗口上,只有当鼠标键按下时系统才将鼠标输入指向指定的窗口。
*/
CView::OnLButtonDown(nFlags, point);
}

 

 

 

代码
// MainFrm.cpp : implementation of the CMainFrame class
//

#include
"stdafx.h"
#include
"ex_14.h"

#include
"MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
ID_SEPARATOR,
// status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
// TODO: add member initialization code here

}

CMainFrame::
~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
////////////////////////////////////////////////////////////////////////////////////////创建toolbar
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0(
"Failed to create toolbar\n");
return -1; // fail to create
}

////////////////////////////////////////////////////////////////////////////zghong//创建一个DialogBar
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0(
"Failed to create status bar\n");
return -1; // fail to create
}

// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(
&m_wndToolBar);

m_wndDialogBar.Create(
this,IDD_DIALOGBAR,CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC,IDD_DIALOGBAR);

//允许停靠
m_wndDialogBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(
&m_wndDialogBar);
//////////////////////////////////////////////////////////////////////////////zghong End

/////以下是修改Icon的例子
HICON hIcon=AfxGetApp()->LoadIcon(IDR_EX_14TYPE);//读取另外一个icon
ASSERT(hIcon);
AfxGetMainWnd()
->SendMessage(WM_SETICON,TRUE,(LPARAM)hIcon);//修改大图标
AfxGetMainWnd()->SendMessage(WM_SETICON,FALSE,(LPARAM)hIcon);//修改小图标
/////End
//////////////////////////////////////////////////////////////////////////加新的menu上去
m_pChinese.LoadMenu(IDR_MAINFRAME_CH);
m_pEnglish.LoadMenu(IDR_MAINFRAME_EN);
SetMenu(
&m_pEnglish);
//////////////////////////////////////////////////////////////////////////END
return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT
& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

 

 

执行结果:

 

posted on 2010-04-12 21:10  不知道  阅读(901)  评论(0编辑  收藏  举报

导航