【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了DIP_SystemView.cpp提供大家参考,希望对大家有所帮助!
// DIP_SystemView.cpp : implementation of the CDIP_SystemView class
//
#include "stdafx.h"
#include "DIP_System.h"
#include "DIP_SystemDoc.h"
#include "DIP_SystemView.h"
#include "MainFrm.h"
#include "Coding.h"
#include "Noise.h"
#include "WaterMarking.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDIP_SystemView
IMPLEMENT_DYNCREATE(CDIP_SystemView, CScrollView)
BEGIN_MESSAGE_MAP(CDIP_SystemView, CScrollView)
//{{AFX_MSG_MAP(CDIP_SystemView)
ON_WM_ERASEBKGND()
ON_COMMAND(ID_PCX_ENCODING, OnPCXEncoding)
ON_COMMAND(ID_PCX_DECODING, OnPCXDecoding)
ON_COMMAND(ID_SET_WATERMARKING, OnSetWatermarking)
ON_COMMAND(ID_GET_WATERMARKING, OnGetWatermarking)
ON_COMMAND(ID_CHAOS, OnChaos)
ON_COMMAND(ID_KNIGHT_DECODE, OnKnightDecode)
ON_COMMAND(ID_KNIGHT_ENCODE, OnKnightEncode)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDIP_SystemView construction/destruction
CDIP_SystemView::CDIP_SystemView()
{
}
CDIP_SystemView::~CDIP_SystemView()
{
}
BOOL CDIP_SystemView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////[辅助函数]/////////////////////////////////////////////////
///////////////////////////////////////////
// 重画视图 //
///////////////////////////////////////////
void CDIP_SystemView::OnDraw(CDC* pDC)
{
// 显示等待光标
BeginWaitCursor();
// 获取文档
CDIP_SystemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// 获取DIB
HDIB hDIB = pDoc->GetHDIB();
// 判断DIB是否为空
if (hDIB != NULL)
{
LPBYTE lpDIB = (LPBYTE) ::GlobalLock((HGLOBAL) hDIB);
// 获取DIB宽度
int cxDIB = (int) pDoc->m_clsDIB.DIBWidth(lpDIB);
// 获取DIB高度
int cyDIB = (int) pDoc->m_clsDIB.DIBHeight(lpDIB);
::GlobalUnlock((HGLOBAL) hDIB);
CRect rcDIB;
rcDIB.top = rcDIB.left = 0;
rcDIB.right = cxDIB;
rcDIB.bottom = cyDIB;
CRect rcDest;
// 判断是否是打印
if (pDC->IsPrinting())
{
// 是打印,计算输出图像的位置和大小,以便符合页面
// 获取打印页面的水平宽度(象素)
int cxPage = pDC->GetDeviceCaps(HORZRES);
// 获取打印页面的垂直高度(象素)
int cyPage = pDC->GetDeviceCaps(VERTRES);
// 获取打印机每英寸象素数
int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
// 计算打印图像大小(缩放,根据页面宽度调整图像大小)
rcDest.top = rcDest.left = 0;
rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch) / ((double)cxDIB * cxInch));
rcDest.right = cxPage;
// 计算打印图像位置(垂直居中)
int temp = cyPage - (rcDest.bottom - rcDest.top);
rcDest.bottom += temp/2;
rcDest.top += temp/2;
}
else // 非打印
{
// 不必缩放图像
rcDest = rcDIB;
}
// 输出DIB
pDoc->m_clsDIB.PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
&rcDIB, pDoc->GetDocPalette());
}
// 恢复正常光标
EndWaitCursor();
}
void CDIP_SystemView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
}
/////////////////////////////////////////////////////////////////////////////
// 图像打印 //
/////////////////////////////////////////////////////////////////////////////
BOOL CDIP_SystemView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 设置总页数为一。
pInfo->SetMaxPage(1);
return DoPreparePrinting(pInfo);
}
void CDIP_SystemView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDIP_SystemView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDIP_SystemView diagnostics
#ifdef _DEBUG
void CDIP_SystemView::AssertValid() const
{
CScrollView::AssertValid();
}
void CDIP_SystemView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CDIP_SystemDoc* CDIP_SystemView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDIP_SystemDoc)));
return (CDIP_SystemDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDIP_SystemView message handlers
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// //
// 基本位图操作 //
// //
/////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////
// 设置子窗体默认背景色为m_refColorBKG //
///////////////////////////////////////////
BOOL CDIP_SystemView::OnEraseBkgnd(CDC* pDC)
{
// 获取文档
CDIP_SystemDoc* pDoc = GetDocument();
// 创建一个Brush
CBrush brush(pDoc->m_refColorBKG);
// 保存以前的Brush
CBrush* pOldBrush = pDC->SelectObject(&brush);
// 获取重绘区域
CRect rectClip;
pDC->GetClipBox(&rectClip);
// 重绘
pDC->PatBlt(rectClip.left, rectClip.top, rectClip.Width(), rectClip.Height(), PATCOPY);
// 恢复以前的Brush
pDC->SelectObject(pOldBrush);
// 返回
return TRUE;
}
///////////////////////////////////////////
// 实现新的调色板 //
///////////////////////////////////////////
void CDIP_SystemView::OnDoRealize(WPARAM wParam, LPARAM lParam)
{
ASSERT(wParam != NULL);
// 获取文档
CDIP_SystemDoc* pDoc = GetDocument();
// 判断DIB是否为空
if (pDoc->GetHDIB() == NULL)
{
// 直接返回
return;
}
// 获取Palette
CPalette* pPal = pDoc->GetDocPalette();
if (pPal != NULL)
{
// 获取MainFrame
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
CClientDC appDC(pAppFrame);
// All views but one should be a background palette.
// wParam contains a handle to the active view, so the SelectPalette
// bForceBackground flag is FALSE only if wParam == m_hWnd (this view)
CPalette* oldPalette = appDC.SelectPalette(pPal, ((HWND)wParam) != m_hWnd);
if (oldPalette != NULL)
{
UINT nColorsChanged = appDC.RealizePalette();
if (nColorsChanged > 0)
pDoc->UpdateAllViews(NULL);
appDC.Select
上一篇:
frmAudioRecorder.frm
下一篇:
大学生汉语写作水平与英语水平相关性研究