请帮我看一下下面这段程序 在每句后面加解释 万分感激
#include "stdafx.h"#include "diblook.h"
#include "dibdoc.h"
#include "dibview.h"
#include "dibapi.h"
#include "mainfrm.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CDibView, CScrollView)
BEGIN_MESSAGE_MAP(CDibView, CScrollView)
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
CDibView::CDibView()
{
}
CDibView::~CDibView()
{
}
void CDibView::OnDraw(CDC* pDC)
{
CDibDoc* pDoc = GetDocument();
HDIB hDIB = pDoc->GetHDIB();
if (hDIB != NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
int cxDIB = (int) ::DIBWidth(lpDIB);
int cyDIB = (int) ::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;
}
else
{
rcDest = rcDIB;
}
::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
&rcDIB, pDoc->GetDocPalette());
}
}
BOOL CDibView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
LRESULT CDibView::OnDoRealize(WPARAM wParam, LPARAM)
{
ASSERT(wParam != NULL);
CDibDoc* pDoc = GetDocument();
if (pDoc->GetHDIB() == NULL)
return 0L;
CPalette* pPal = pDoc->GetDocPalette();
if (pPal != NULL)
{
CMainFrame*pAppFrame= (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
CClientDC appDC(pAppFrame);
CPalette*oldPalette=appDC.SelectPalette(pPal,((HWND)wParam)!=m_hWnd);
if (oldPalette != NULL)
{
UINT nColorsChanged = appDC.RealizePalette();
if (nColorsChanged > 0)
pDoc->UpdateAllViews(NULL);
appDC.SelectPalette(oldPalette, TRUE);
}
else
{
TRACE0("\tSelectPalette failed in CDibView::OnPaletteChanged\n");
}
}
return 0L;
}
void CDibView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
ASSERT(GetDocument() != NULL);
CSize s;
s.cx=2000;
s.cy=1000;
//SetScrollSizes(MM_TEXT, GetDocument()->GetDocSize());
SetScrollSizes(MM_TEXT, s);
}
void CDibView::OnActivateView(BOOL bActivate, CView* pActivateView,
CView* pDeactiveView)
{
CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
if (bActivate)
{
ASSERT(pActivateView == this);
OnDoRealize((WPARAM)m_hWnd, 0);
}
}
void CDibView::OnEditCopy()
{
CDibDoc* pDoc = GetDocument();
if (OpenClipboard())
{
BeginWaitCursor();
EmptyClipboard();
SetClipboardData(CF_DIB,CopyHandle((HANDLE) pDoc->GetHDIB()) );
CloseClipboard();
EndWaitCursor();
}
}
void CDibView::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
pCmdUI->Enable(GetDocument()->GetHDIB() != NULL);
}
void CDibView::OnEditPaste()
{
HDIB hNewDIB = NULL;
if (OpenClipboard())
{
BeginWaitCursor();
hNewDIB = (HDIB) CopyHandle(::GetClipboardData(CF_DIB));
CloseClipboard();
if (hNewDIB != NULL)
{
CDibDoc* pDoc = GetDocument();
pDoc->ReplaceHDIB(hNewDIB);
pDoc->InitDIBData();
pDoc->SetModifiedFlag(TRUE);
SetScrollSizes(MM_TEXT, pDoc->GetDocSize());
OnDoRealize((WPARAM)m_hWnd,0);
pDoc->UpdateAllViews(NULL);
}
EndWaitCursor();
}
}
void CDibView::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
pCmdUI->Enable(::IsClipboardFormatAvailable(CF_DIB));
}
void WINAPI GetImage(HDIB hDIB,BYTE * image[])
{
LPSTR lp = (LPSTR)::GlobalLock(hDIB);
LPBITMAPINFOHEADER lh = (LPBITMAPINFOHEADER)lp;
int biWidth = DIBWidth(lp);
int biHeight = DIBHeight(lp);
if(biWidth%4!=0)
biWidth += (4-biWidth%4);
lp = FindDIBBits(lp);
if(lh ->biBitCount ==8)
for(int i=0;i<biHeight;i++)
image[i] = (BYTE *)(lp +(biHeight -1 -i)*biWidth);
else
{
AfxMessageBox("Not 8 bit bitmap!");
}
::GlobalUnlock(hDIB);
}
void MobanEdge2(HDIB hDIB,int mm[2][2])
{
BYTE * image[5000];
GetImage(hDIB,image);
HDIB newD = (HDIB)CopyHandle(hDIB);
BYTE * imagel[5000];
LPSTR lp = (LPSTR)::GlobalLock(hDIB);
GetImage(newD,imagel);
for(int i =0;i<DIBHeight(lp);i++)
for(int j=0;j<DIBWidth(lp);j++)
{
if(i<1||i>DIBHeight(lp)-2||j<1||j>DIBWidth(lp)-2)
continue;
int temp = 0;
for(int ii =0;ii<2;ii++)
for(int jj=0;jj<2;jj++)
temp += imagel[i+ii-1][j+jj-1] * mm[ii][jj];
int yuzhi = 100;
image[i][j] = abs(temp) > 100?255:0;
}
}
void MobanEdge3(HDIB hDIB,int mm[3][3])
{
BYTE * image[5000];
GetImage(hDIB,image);
HDIB newD = (HDIB)CopyHandle(hDIB);
BYTE * imagel[5000];
LPSTR lp = (LPSTR)::GlobalLock(hDIB);
GetImage(newD,imagel);
for(int i =0;i<DIBHeight(lp);i++)
for(int j=0;j<DIBWidth(lp);j++)
{
if(i<1||i>DIBHeight(lp)-2||j<1||j>DIBWidth(lp)-2)
continue;
int temp = 0;
for(int ii =0;ii<3;ii++)
for(int jj=0;jj<3;jj++)
temp += imagel[i+ii-1][j+jj-1] * mm[ii][jj];
int yuzhi = 100;
image[i][j] = abs(temp) > 100?255:0;
}
}
void MobanEdge5(HDIB hDIB,int mm[5][5])
{
BYTE * image[5000];
GetImage(hDIB,image);
HDIB newD = (HDIB)CopyHandle(hDIB);
BYTE * imagel[5000];
LPSTR lp = (LPSTR)::GlobalLock(hDIB);
GetImage(newD,imagel);
for(int i =0;i<DIBHeight(lp);i++)
for(int j=0;j<DIBWidth(lp);j++)
{
if(i<1||i>DIBHeight(lp)-2||j<1||j>DIBWidth(lp)-2)
continue;
int temp = 0;
for(int ii =0;ii<5;ii++)
for(int jj=0;jj<5;jj++)
temp += imagel[i+ii-1][j+jj-1] * mm[ii][jj];
int yuzhi = 100;
image[i][j] = abs(temp) > 100?255:0;
}
}
void CDibView::OnRobertEdge()
{
CDibDoc * pDoc = GetDocument();
HDIB hDIB = pDoc ->GetHDIB();
int mm[2][2];
for(int i =0;i<2;i++)
for(int j=0;j<2;j++)
mm[i][j] = 0;
mm[0][0] =1;
mm[1][1] = -1;
MobanEdge2(hDIB,mm);
for(int ii =0;ii<2;ii++)
for(int jj=0;jj<2;jj++)
mm[ii][jj] = 0;
mm[0][1] =1;
mm[1][0] = -1;
MobanEdge2(hDIB,mm);
Invalidate();
}
void CDibView::OnSobelEdge()
{
CDibDoc * pDoc = GetDocument();
HDIB hDIB = pDoc ->GetHDIB();
int mm[3][3];
for(int ii =0;ii<3;ii++)
for(int jj=0;jj<3;jj++)
mm[ii][jj] = 0;
mm[0][0] = -1;
mm[0][2] = 1;
mm[1][0] = -2;
mm[1][2] = 2;
mm[2][0] = -1;
mm[2][2] = 1;
MobanEdge3(hDIB,mm);
Invalidate();
}
void CDibView::OnPrewittEdge()
{
CDibDoc * pDoc = GetDocument();
HDIB hDIB = pDoc ->GetHDIB();
int mm[3][3];
for(int i =0;i<3;i++)
for(int j=0;j<3;j++)
mm[i][j] = 0;
mm[0][0] = -1;
mm[0][1] = -1;
mm[0][2] = -1;
mm[2][0] = 1;
mm[2][1] = 1;
mm[2][2] = 1;
MobanEdge3(hDIB,mm);
Invalidate();
}
void CDibView::OnLaplacianEdge()
{
CDibDoc * pDoc = GetDocument();
HDIB hDIB = pDoc ->GetHDIB();
int mm[3][3];
for(int ii =0;ii<3;ii++)
for(int jj=0;jj<3;jj++)
mm[ii][jj] = -1;
mm[1][1] = 8;
MobanEdge3(hDIB,mm);
Invalidate();
}
void CDibView::OnKirschEdge()
{
CDibDoc * pDoc = GetDocument();
HDIB hDIB = pDoc ->GetHDIB();
int mm[3][3];
for(int i =0;i<3;i++)
for(int j=0;j<3;j++)
mm[i][j] = -3;
mm[0][0] = 5;
mm[0][1] = 5;
mm[0][2] = 5;
mm[1][1] = 0;
MobanEdge3(hDIB,mm);
Invalidate();
}
void CDibView::OnLOGEdge()
{
CDibDoc * pDoc = GetDocument();
HDIB hDIB = pDoc ->GetHDIB();
int mm[5][5];
for(int i =0;i<5;i++)
for(int j=0;j<5;j++)
mm[i][j] = -4;
mm[0][0] = -2;
mm[0][4] = -2;
mm[1][1] = 0;
mm[1][2] = 8;
mm[1][3] = 0;
mm[2][1] = 8;
mm[2][2] = 24;
mm[2][3] = 8;
mm[3][1] = 0;
mm[3][2] = 8;
mm[3][3] = 0;
mm[4][0] = -2;
mm[4][4] = -2;
MobanEdge5(hDIB,mm);
Invalidate();
}