www.gusucode.com > VC++动画窗口以及位图上下文菜单源代码源码程序 > VC++动画窗口以及位图上下文菜单源代码源码程序\code\jobView.cpp

    // jobView.cpp : implementation of the CJobView class
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "job.h"

#include "jobDoc.h"
#include "jobView.h"

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

IMPLEMENT_DYNCREATE(CJobView, CView)

BEGIN_MESSAGE_MAP(CJobView, CView)
	//{{AFX_MSG_MAP(CJobView)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(IDR_F5, OnF5)
	ON_COMMAND(IDR_EXIT, OnExit)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CJobView construction/destruction

CJobView::CJobView()
{
	// TODO: add construction code here
    m_crBackground=RGB(146,177,231);
    m_wndbkBrush.CreateSolidBrush(m_crBackground);
}

CJobView::~CJobView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CJobView drawing

void CJobView::OnDraw(CDC* pDC)
{
	CJobDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CJobView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CJobView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CJobView message handlers

void CJobView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	// Do not call CView::OnPaint() for painting messages
	BITMAP bm;                         //创建位图结构变量
	CBitmap m_bitmap;                  //创建位图对象
	CDC dcImage;                           //创建设备环境
	m_bitmap.LoadBitmap(IDB_BITMAP1);  //拷贝资源位图
    m_bitmap.GetBitmap(&bm);           //得到位图结构中的大小信息
	dcImage.CreateCompatibleDC(NULL);
	dcImage.SelectObject(&m_bitmap);
    dc.BitBlt(15,15,bm.bmWidth,bm.bmHeight,&dcImage,0,0,SRCCOPY);
	// Do not call CView::OnPaint() for painting messages
    dc.SetBkMode(TRANSPARENT);//设置背景颜色模式为透明色
	dc.SetTextColor(RGB(255,255,0));//设置文本前景色为黄色
	CString str("☆★Hello,World!★☆");
	dc.SetTextColor(RGB(rand()+30,rand()+50,rand()+20));
    dc.TextOut(100,0,str);
//	Sleep(500);
//	InvalidateRect(CRect(50,0,200,15), TRUE);
}

BOOL CJobView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	CView::OnEraseBkgnd(pDC);
	CRect rect;
	GetClientRect(&rect);
	pDC->FillRect(&rect,&m_wndbkBrush);//设置背景色
	return TRUE;	
//	return CView::OnEraseBkgnd(pDC);
}

void CJobView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnRButtonDown(nFlags, point);
	BCMenu popmenu;
  //添加右键快捷图标菜单(用于下拉式菜单)
  popmenu.LoadMenu(IDR_MENU);
  popmenu.ModifyODMenu(NULL,IDR_F5,IDB_F5);
  popmenu.ModifyODMenu(NULL,IDR_EXIT,IDB_EXIT);
  
  ClientToScreen(&point);
  BCMenu *psub = (BCMenu *)popmenu.GetSubMenu(0); 
  psub->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this);
  popmenu.DestroyMenu();
}

void CJobView::OnF5() 
{
	// TODO: Add your command handler code here
	InvalidateRect(CRect(100,0,250,16), TRUE);	
}

void CJobView::OnExit() 
{
	// TODO: Add your command handler code here
//	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER);
    PostQuitMessage(0);
}