| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 711 人关注过本帖
标题:请帮我看一下下面这段程序 在每句后面加解释 万分感激
只看楼主 加入收藏
夏歌花音
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-3-15
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
请帮我看一下下面这段程序 在每句后面加解释 万分感激
#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();   
}
搜索更多相关主题的帖子: include 
2013-06-06 16:48
夏歌花音
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-3-15
收藏
得分:0 
急用 万分感激
2013-06-06 16:51
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:10 
在每句后面加解释

这个不是一般人愿意做的

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-06-06 17:46
夏歌花音
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-3-15
收藏
得分:0 
回复 3楼 yuccn
不用每句都加  只需要把关键的地方加上就可以了
#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 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();
}
2013-06-06 17:53
cwj976277916
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:49
专家分:77
注 册:2012-6-4
收藏
得分:10 
关键的地方貌似不知道是哪里?我想问的是你想做什么?

静下心来,理清思路!
2013-06-07 15:17
夏歌花音
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-3-15
收藏
得分:0 
回复 5楼 cwj976277916
我做的图像边缘检测
2013-06-12 09:53
快速回复:请帮我看一下下面这段程序 在每句后面加解释 万分感激
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030008 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved