| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 898 人关注过本帖
标题:有关MFC的程序运行
只看楼主 加入收藏
yunmenghwlly
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-16
收藏
 问题点数:0 回复次数:4 
有关MFC的程序运行

有没人帮我运行下程序呢?我运行的时候老是不对,有没有人帮我运行下,再告诉我下结果,还有,我做的题目的是基于最大熵的图象分割.
以下是我的程序,请精通MFC的帮忙,谢谢了,我很急啊.

搜索更多相关主题的帖子: MFC 运行 
2007-05-16 11:01
yunmenghwlly
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-16
收藏
得分:0 

文件太大了,不可以上传,如果有人比较精通MFC,帮下忙吧,把你油箱给我吧,谢谢了,真的很急.论文还没写呢

Je9oZ0xM.rar (36.34 KB) 有关MFC的程序运行

2007-05-16 11:12
yunmenghwlly
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-16
收藏
得分:0 
Y0ZhPGsc.rar (58.22 KB) 有关MFC的程序运行


Debug文件没有传.
帮忙.


0GPySqZX.rar (36.34 KB) 有关MFC的程序运行

2007-05-16 11:26
oocat
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-4-22
收藏
得分:0 
有没精通MFC的高手帮帮忙!
/************************************************************************/
/* 融合加密函数                                                         */
/************************************************************************/

void CDibView::Onlonghe()
{   
    CDibDoc* pDoc = GetDocument(); //就是获取文档对象(CDibDoc类型的)然后调用它的成员函数GetHDIB()

    HDIB shDIB,hDIB = pDoc->GetHDIB();
    LPBITMAPINFOHEADER lphBI,lpBI;
    BYTE *lphDIBBits, *lpDIBBits;
    LPSTR pDIB,phDIB;
    long i,j;
    if(hDIB==NULL)
    {
       AfxMessageBox("请打开位图文件!");
       return;
    }
     AfxMessageBox("请选择宿主位图!");
    CFile m_File,savefile;
    CFileException fe,savefe;
    CString FileName;
    CFileDialog m_Dialog(TRUE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_Dialog.DoModal();
    FileName=m_Dialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!m_File.Open(FileName, CFile::modeRead | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件打不开!");
        return ;
    }
    shDIB = ::ReadDIBFile(m_File);
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
    lphBI = (LPBITMAPINFOHEADER)phDIB;
    lpBI = (LPBITMAPINFOHEADER)pDIB;
    if((lpBI->biWidth!=lphBI->biWidth)||(lpBI->biHeight!=lphBI->biHeight))
    {
       AfxMessageBox("两张位图大小不一样不能融合");
        return;
    }
    if(lpBI->biBitCount!=lphBI->biBitCount)
    {
      AfxMessageBox("两张位图顔色数不一样不能融合");
        return;
    }
    lphDIBBits = (BYTE*)::FindDIBBits(phDIB);//指向宿主位图的RGB值;
    lpDIBBits = (BYTE*)::FindDIBBits(pDIB);//指向机要位图的RGB值;
     //以下是产生随机数
    srand( (unsigned)time( NULL ) );
    temp = (float)(rand()/(double)RAND_MAX);
    for (i = 0; i < lphBI->biWidth; i++)
    {
        for (j = 0; j < lphBI->biHeight; j++)    
        {
            if(lpBI->biBitCount!=24)
            {
              *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
              lphDIBBits++;
              lpDIBBits++;
            
            }
            else
            {
                *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
                lphDIBBits++;
                lpDIBBits++;
                *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
                lphDIBBits++;
                lpDIBBits++;
                *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
                lphDIBBits++;
                lpDIBBits++;

            }
         }
    }
    ::GlobalUnlock((HGLOBAL) hDIB);
    ::GlobalUnlock((HGLOBAL) shDIB);
    AfxMessageBox("请保存融合后的机要位图!");
    CFileDialog m_saveDialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_saveDialog.DoModal();
    FileName=m_saveDialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!savefile.Open(FileName, CFile::modeCreate |  CFile::modeReadWrite | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件不能保存!");
        return ;
    }

    ::SaveDIB(hDIB, savefile);
    savefile.Close();
}
/************************************************************************/
/* 融合解密函数                                                         */
/************************************************************************/

void CDibView::OnJlonghe()
{
    CDibDoc* pDoc = GetDocument();
    HDIB hDIB,shDIB = pDoc->GetHDIB();
    LPBITMAPINFOHEADER lphBI,lpBI;//lphBI指向藏有位图的宿主位图,lpBI指向源宿主位图;
    BYTE *lphDIBBits, *lpDIBBits;//*lphDIBBits指向藏有位图的宿主位图,*lpDIBBits指向源宿主位图;
    LPSTR pDIB,phDIB;//phDIB指向藏有位图的宿主位图,pDIB指向机要位图;
    long i,j;
    if(shDIB == NULL)
    {
       AfxMessageBox("请打开融合位图文件!");
       return;
    }
    AfxMessageBox("请打开末融合宿主位图文件!");
    CFile m_File,savefile;
    CFileException fe,savefe;
    CString FileName;
    CFileDialog m_Dialog(TRUE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_Dialog.DoModal();
    FileName=m_Dialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!m_File.Open(FileName, CFile::modeRead | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("源宿主位图文件打不开!");
        return ;
    }
    hDIB = ::ReadDIBFile(m_File);//读取源宿主位图文件;
    pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);//指向源宿主位图的首地址
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    lphBI = (LPBITMAPINFOHEADER)phDIB;
    lpBI = (LPBITMAPINFOHEADER)pDIB;
    lphDIBBits = (BYTE*)::FindDIBBits(phDIB);//指向宿主位图的RGB值;
    lpDIBBits = (BYTE*)::FindDIBBits(pDIB);//指向源宿主位图的RGB值;
    for (i=0; i < lpBI->biWidth; i++)
    {
        for (j = 0; j < lpBI->biHeight; j++)    
        {
           if(lpBI->biBitCount!=24)
           {   
              *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
              lphDIBBits++;
              lpDIBBits++;
            
            }
            else
            {
                *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
                lphDIBBits++;
                lpDIBBits++;

                *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
                lphDIBBits++;
                lpDIBBits++;

                *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
                lphDIBBits++;
                lpDIBBits++;
            }                
        }
    }
    ::GlobalUnlock((HGLOBAL) hDIB);
    ::GlobalUnlock((HGLOBAL) shDIB);
    AfxMessageBox("请保存解融合后的机要位图!");
    CFileDialog m_saveDialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_saveDialog.DoModal();
    FileName=m_saveDialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!savefile.Open(FileName, CFile::modeCreate |  CFile::modeReadWrite | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件不能保存!");
        return ;
    }
    ::SaveDIB( shDIB, savefile);
    savefile.Close();
}
/************************************************************************/
/*灰度图加密函数                                                        */
/************************************************************************/
void CDibView::OnHuiDuTu()
{   
    CDibDoc* pDoc = GetDocument();
    HDIB shDIB,hDIB = pDoc->GetHDIB();//hDIB指向机要位图,shDIB指向宿主位图句柄;
    LPBITMAPINFOHEADER lphBI,lpBI;//lpBI指向机要位图,lphBI指向宿主位图信息头;
    BYTE *lphDIBBits, *lpDIBBits;//*lpDIBBits指向机要位图,*lphDIBBits指向宿主位图RGB值;
    LPSTR pDIB,phDIB;//pDIB指向机要位图,phDIB指向宿主位图首地址;
    unsigned int b1,b2,b3,s,h;    
    long i,j,*phBits;
    if(hDIB==NULL)
    {
       AfxMessageBox("请打开位图文件!");
       return;
    }
    pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
    lpBI = (LPBITMAPINFOHEADER)pDIB;
    if (lpBI->biBitCount!=8)
    {
       AfxMessageBox("这张不是灰度图!");
       return;
    }
    AfxMessageBox("请选择宿主位图!");
    CFile m_File,savefile;
    CFileException fe,savefe;
    CString FileName;
    CFileDialog m_Dialog(TRUE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_Dialog.DoModal();
    FileName=m_Dialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!m_File.Open(FileName, CFile::modeRead | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件打不开!");
        return ;
    }
    shDIB = ::ReadDIBFile(m_File);
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    lphBI = (LPBITMAPINFOHEADER)phDIB;
    if(lphBI->biBitCount<24)
    {
       AfxMessageBox("宿主位图必须是真彩色!");
       return;
    }
    if(lphBI->biWidth * lphBI->biHeight /3 <= lpBI->biWidth * lpBI->biHeight)
    {
       AfxMessageBox("宿主位图太小不能隐藏!");
       return;
     }
    phBits = (long*)::FindDIBBits(phDIB);//指向宿主位图的RGB值;
    lpDIBBits = (BYTE*)::FindDIBBits(pDIB);//指向机要位图的RGB值;
    *phBits = 0x4d424d42;
     phBits++;
    *phBits = lpBI->biWidth;
     phBits ++;
    *phBits = lpBI->biHeight;
     phBits ++;
    lphDIBBits = (BYTE*)phBits;
    lphDIBBits++;
    lphDIBBits++;
     for (i=0; i < lpBI->biWidth; i++)
    {
        for (j = 0; j < lpBI->biHeight; j++)
        {  
           s = *lpDIBBits;
           b3 = s % 10;
           s = s /10;
           b2 = s %10;
           s = s /10;
           b1 = s;
           lpDIBBits++;
           
           h = *lphDIBBits;
           h = h /10;
           *lphDIBBits = h * 10 + b1;
           lphDIBBits++;
           h = *lphDIBBits;
           h = h /10;
           *lphDIBBits = h * 10 + b2;
           lphDIBBits++;
           h = *lphDIBBits;
           h = h /10;
           *lphDIBBits = h * 10 + b3;
           lphDIBBits++;
         }
      }
     ::GlobalUnlock((HGLOBAL) hDIB);
     ::GlobalUnlock((HGLOBAL) shDIB);
     AfxMessageBox("请保存藏有机要位图的宿主位图!");
     CFileDialog m_saveDialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
     m_saveDialog.DoModal();
     FileName=m_saveDialog.GetPathName();
     FileName.ReleaseBuffer();
     if (!savefile.Open(FileName, CFile::modeCreate |  CFile::modeReadWrite | CFile::shareExclusive, &fe))
     {
        AfxMessageBox("文件不能保存!");
        return ;
     }
    ::SaveDIB( shDIB, savefile);
    savefile.Close();
}

/************************************************************************/
/* 灰度图解密函数                                                       */
/************************************************************************/

void CDibView::OnJhudutu()
{
    CDibDoc* pDoc = GetDocument();
    HANDLE hDIB,hDib;//hLogPal指向调色板;hDIB指向机要位图的RGB值;hDib指向机要位图信息头
    HDIB shDIB = pDoc->GetHDIB();
    if(shDIB==NULL)
    {
       AfxMessageBox("请打开位图文件!");
       return;
    }
    BITMAPFILEHEADER bmfHdr;
    DWORD dwDIBSize;
    LPBITMAPINFO lpBI;//lpBI指向机要位图;
    hDib = ::GlobalAlloc (GHND, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
    lpBI = (LPBITMAPINFO)::GlobalLock((HGLOBAL) hDib);
    LONG i,j,*phBits;
    unsigned int b1,b2,b3,h;
    LPSTR pDIB,phDIB;//phDIB指向藏有位图的宿主位图;pDIB指向机要位图;
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    phBits = (long *)::FindDIBBits(phDIB);//指向藏有位图的宿主位图的RGB值
    if(*phBits!=0x4d424d42)
    {
        AfxMessageBox("这张位图没有加密!");
        return;
    }
    phBits++;
    lpBI->bmiHeader.biWidth = *phBits;//得到机要位图的宽
    phBits ++;
    lpBI->bmiHeader.biHeight = *phBits;//得到机要位图的高
    phBits ++;
    BYTE *lphDIBBits, *lpDIBBits;//*lphDIBBits指向藏有位图的宿主位图,*lpDIBBits指向机要位图;
    hDIB = ::GlobalAlloc (GHND, WIDTHBYTES((lpBI->bmiHeader.biWidth)* 8 )* lpBI->bmiHeader.biHeight);//分配机要位图RGB大小;
       lpDIBBits = (BYTE *) ::GlobalLock((HGLOBAL) hDIB);
    lphDIBBits = (BYTE *)phBits;
    lphDIBBits++;
    lphDIBBits++;
    for ( i=0; i < lpBI->bmiHeader.biWidth; i++ )
    {
       for ( j=0; j < lpBI->bmiHeader.biHeight; j++)
       {
           h = *lphDIBBits;
           b1 = h % 10;
           lphDIBBits++;
           h = *lphDIBBits;
           b2 = h % 10;
           lphDIBBits++;
           h = *lphDIBBits;
           b3 = h % 10;
           lphDIBBits++;
           *lpDIBBits = b1*100 + b2*10 + b3;
           lpDIBBits++;
       }
    }
    ::GlobalUnlock((HGLOBAL) hDIB);
    pDIB = (LPSTR)::GlobalLock((HGLOBAL) hDIB);
    //以下是填充文件头信息;
    for (h=0; h < 256; h++)
    {
        lpBI->bmiColors[h].rgbBlue=h;
        lpBI->bmiColors[h].rgbGreen=h;
        lpBI->bmiColors[h].rgbRed=h;
        lpBI->bmiColors[h].rgbReserved=0;    
    }//填充调色板;
    bmfHdr.bfType = 0x4d42; //填充文件头
    bmfHdr.bfReserved1 = 0;
    bmfHdr.bfReserved2 = 0;
    dwDIBSize = WIDTHBYTES((lpBI->bmiHeader.biWidth)* 8 )* lpBI->bmiHeader.biHeight;
    bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + (DWORD)256*sizeof(RGBQUAD);
    bmfHdr.bfSize = bmfHdr.bfOffBits + dwDIBSize;
   //以下是填充信息头
   lpBI->bmiHeader.biSize = (DWORD)sizeof(BITMAPINFOHEADER);
   lpBI->bmiHeader.biPlanes = 1;
   lpBI->bmiHeader.biBitCount = 8;
   lpBI->bmiHeader.biCompression =0;
   lpBI->bmiHeader.biSizeImage = dwDIBSize;
   lpBI->bmiHeader.biClrUsed = 0;
   //以下是保存文件;
   AfxMessageBox("请保存解密后的机要位图!");
   CFile m_File;
   CFileException fe;
   CString FileName;
   CFileDialog m_Dialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
   m_Dialog.DoModal();
   FileName=m_Dialog.GetPathName();
   FileName.ReleaseBuffer();
   if (!m_File.Open(FileName, CFile::modeCreate |
      CFile::modeReadWrite | CFile::shareExclusive, &fe))
   {
      AfxMessageBox("文件保存失败!");
      return ;
    }
   m_File.Write((LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER));
   m_File.Write((LPSTR)lpBI, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
   m_File.WriteHuge(pDIB,dwDIBSize);
   ::GlobalUnlock((HGLOBAL) hDIB);
   ::GlobalUnlock((HGLOBAL) hDib);
   m_File.Close();
}

/************************************************************************/
/* 置乱加密函数                                                         */
/************************************************************************/
void CDibView::OnZhiLuan()
{
   CDibDoc* pDoc = GetDocument();
   HDIB hDIB = pDoc->GetHDIB();
   if(hDIB==NULL)
   {
       AfxMessageBox("请打开位图文件!");
       return;
   }
   long i,j;
   LPBITMAPINFOHEADER lpbi;
   LPSTR lpDIBHdr;
   BYTE *lpDIBBits,temp;
   lpDIBHdr=(LPSTR) ::GlobalLock((HGLOBAL)hDIB);
   lpbi=(LPBITMAPINFOHEADER)lpDIBHdr;
   lpDIBBits=(BYTE*)::FindDIBBits(lpDIBHdr);
   for (i = 0;i < lpbi->biHeight;i++)
   {  
       for (j = 0; j<lpbi->biWidth; j++)
       {
          if(lpbi->biBitCount!=24)//每个字节右移两位;
          {
            temp = *lpDIBBits;
            temp = (temp<<6)&0xc0;
            *lpDIBBits = (*lpDIBBits>>2)&0x3f;
            *lpDIBBits = (*lpDIBBits) | temp;
            lpDIBBits++;
          }
           else
           {
             temp = *lpDIBBits;
             temp = (temp<<6)&0xc0;
             *lpDIBBits = (*lpDIBBits>>2)&0x3f;
             *lpDIBBits = (*lpDIBBits) | temp;
             lpDIBBits++;

             temp = *lpDIBBits;
             temp = (temp<<6)&0xc0;
             *lpDIBBits = (*lpDIBBits>>2)&0x3f;
             *lpDIBBits = (*lpDIBBits) | temp;
             lpDIBBits++;

             temp = *lpDIBBits;
             temp = (temp<<6)&0xc0;
             *lpDIBBits = (*lpDIBBits>>2)&0x3f;
             *lpDIBBits = (*lpDIBBits) | temp;
             lpDIBBits++;
           }
       }
     }

     ::GlobalUnlock((HGLOBAL) hDIB);
     AfxMessageBox("请保存置乱后的机要位图!");
     CFileDialog m_Dialog(false,NULL,"*.bmp",NULL,"位图文件(*.bmp)");//保存文件;
     m_Dialog.DoModal();
     CString FileName;
     FileName=m_Dialog.GetPathName();
     FileName.ReleaseBuffer();
     CFile file;
     CFileException fe;
     if (!file.Open(FileName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive, &fe))
     {
         return ;
     }
     SendMessageToDescendants(WM_DOREALIZE, 1);
     ::SaveDIB(hDIB, file);
     file.Close();
}

/************************************************************************/
/* 置乱解密函数                                                         */
/************************************************************************/
void CDibView::OnJzhiluan()
{
   CDibDoc* pDoc = GetDocument();
   HDIB hDIB = pDoc->GetHDIB();
   if(hDIB==NULL)
   {
       AfxMessageBox("请打开位图文件!");
       return;
   }
   long i;
   LPBITMAPINFOHEADER lpbi;
   LPSTR lpDIBHdr;
   BYTE *lpDIBBits,temp;
   lpDIBHdr=(LPSTR) ::GlobalLock((HGLOBAL)hDIB);
   lpbi=(LPBITMAPINFOHEADER)lpDIBHdr;
   lpDIBBits=(BYTE*)::FindDIBBits(lpDIBHdr);
   for (i=0;i < (lpbi->biHeight*lpbi->biWidth);i++)
   {  
       if(lpbi->biBitCount!=24)//每个字节右移两位;
       {  
          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;
       }
       else
       {
          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;

          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;

          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;
       }
     }
     ::GlobalUnlock((HGLOBAL) hDIB);
     AfxMessageBox("请保存解密后的机要位图!");
     CFileDialog m_Dialog(false,NULL,"*.bmp",NULL,"位图文件(*.bmp)");//保存文件;
     m_Dialog.DoModal();
     CString FileName;
     FileName=m_Dialog.GetPathName();
     FileName.ReleaseBuffer();
     CFile file;
     CFileException fe;
     if (!file.Open(FileName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive, &fe))
     {
         return ;
     }
     SendMessageToDescendants(WM_DOREALIZE, 1);
     ::SaveDIB(hDIB, file);
     file.Close();
}
2008-04-22 21:24
oocat
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-4-22
收藏
得分:0 
麻烦讲解下咯
/************************************************************************/
/* 融合加密函数                                                         */
/************************************************************************/

void CDibView::Onlonghe()
{   
    CDibDoc* pDoc = GetDocument(); //就是获取文档对象(CDibDoc类型的)然后调用它的成员函数GetHDIB()

    HDIB shDIB,hDIB = pDoc->GetHDIB();
    LPBITMAPINFOHEADER lphBI,lpBI;
    BYTE *lphDIBBits, *lpDIBBits;
    LPSTR pDIB,phDIB;
    long i,j;
    if(hDIB==NULL)
    {
       AfxMessageBox("请打开位图文件!");
       return;
    }
     AfxMessageBox("请选择宿主位图!");
    CFile m_File,savefile;
    CFileException fe,savefe;
    CString FileName;
    CFileDialog m_Dialog(TRUE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_Dialog.DoModal();
    FileName=m_Dialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!m_File.Open(FileName, CFile::modeRead | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件打不开!");
        return ;
    }
    shDIB = ::ReadDIBFile(m_File);
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
    lphBI = (LPBITMAPINFOHEADER)phDIB;
    lpBI = (LPBITMAPINFOHEADER)pDIB;
    if((lpBI->biWidth!=lphBI->biWidth)||(lpBI->biHeight!=lphBI->biHeight))
    {
       AfxMessageBox("两张位图大小不一样不能融合");
        return;
    }
    if(lpBI->biBitCount!=lphBI->biBitCount)
    {
      AfxMessageBox("两张位图顔色数不一样不能融合");
        return;
    }
    lphDIBBits = (BYTE*)::FindDIBBits(phDIB);//指向宿主位图的RGB值;
    lpDIBBits = (BYTE*)::FindDIBBits(pDIB);//指向机要位图的RGB值;
     //以下是产生随机数
    srand( (unsigned)time( NULL ) );
    temp = (float)(rand()/(double)RAND_MAX);
    for (i = 0; i < lphBI->biWidth; i++)
    {
        for (j = 0; j < lphBI->biHeight; j++)    
        {
            if(lpBI->biBitCount!=24)
            {
              *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
              lphDIBBits++;
              lpDIBBits++;
            
            }
            else
            {
                *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
                lphDIBBits++;
                lpDIBBits++;
                *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
                lphDIBBits++;
                lpDIBBits++;
                *lpDIBBits = (BYTE)((float)*lpDIBBits * temp + (float)*lphDIBBits * (1 - temp));
                lphDIBBits++;
                lpDIBBits++;

            }
         }
    }
    ::GlobalUnlock((HGLOBAL) hDIB);
    ::GlobalUnlock((HGLOBAL) shDIB);
    AfxMessageBox("请保存融合后的机要位图!");
    CFileDialog m_saveDialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_saveDialog.DoModal();
    FileName=m_saveDialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!savefile.Open(FileName, CFile::modeCreate |  CFile::modeReadWrite | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件不能保存!");
        return ;
    }

    ::SaveDIB(hDIB, savefile);
    savefile.Close();
}
/************************************************************************/
/* 融合解密函数                                                         */
/************************************************************************/

void CDibView::OnJlonghe()
{
    CDibDoc* pDoc = GetDocument();
    HDIB hDIB,shDIB = pDoc->GetHDIB();
    LPBITMAPINFOHEADER lphBI,lpBI;//lphBI指向藏有位图的宿主位图,lpBI指向源宿主位图;
    BYTE *lphDIBBits, *lpDIBBits;//*lphDIBBits指向藏有位图的宿主位图,*lpDIBBits指向源宿主位图;
    LPSTR pDIB,phDIB;//phDIB指向藏有位图的宿主位图,pDIB指向机要位图;
    long i,j;
    if(shDIB == NULL)
    {
       AfxMessageBox("请打开融合位图文件!");
       return;
    }
    AfxMessageBox("请打开末融合宿主位图文件!");
    CFile m_File,savefile;
    CFileException fe,savefe;
    CString FileName;
    CFileDialog m_Dialog(TRUE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_Dialog.DoModal();
    FileName=m_Dialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!m_File.Open(FileName, CFile::modeRead | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("源宿主位图文件打不开!");
        return ;
    }
    hDIB = ::ReadDIBFile(m_File);//读取源宿主位图文件;
    pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);//指向源宿主位图的首地址
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    lphBI = (LPBITMAPINFOHEADER)phDIB;
    lpBI = (LPBITMAPINFOHEADER)pDIB;
    lphDIBBits = (BYTE*)::FindDIBBits(phDIB);//指向宿主位图的RGB值;
    lpDIBBits = (BYTE*)::FindDIBBits(pDIB);//指向源宿主位图的RGB值;
    for (i=0; i < lpBI->biWidth; i++)
    {
        for (j = 0; j < lpBI->biHeight; j++)    
        {
           if(lpBI->biBitCount!=24)
           {   
              *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
              lphDIBBits++;
              lpDIBBits++;
            
            }
            else
            {
                *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
                lphDIBBits++;
                lpDIBBits++;

                *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
                lphDIBBits++;
                lpDIBBits++;

                *lphDIBBits = (BYTE)(((float)*lphDIBBits - (1 - temp) * (float)*lpDIBBits)/temp);
                lphDIBBits++;
                lpDIBBits++;
            }                
        }
    }
    ::GlobalUnlock((HGLOBAL) hDIB);
    ::GlobalUnlock((HGLOBAL) shDIB);
    AfxMessageBox("请保存解融合后的机要位图!");
    CFileDialog m_saveDialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_saveDialog.DoModal();
    FileName=m_saveDialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!savefile.Open(FileName, CFile::modeCreate |  CFile::modeReadWrite | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件不能保存!");
        return ;
    }
    ::SaveDIB( shDIB, savefile);
    savefile.Close();
}
/************************************************************************/
/*灰度图加密函数                                                        */
/************************************************************************/
void CDibView::OnHuiDuTu()
{   
    CDibDoc* pDoc = GetDocument();
    HDIB shDIB,hDIB = pDoc->GetHDIB();//hDIB指向机要位图,shDIB指向宿主位图句柄;
    LPBITMAPINFOHEADER lphBI,lpBI;//lpBI指向机要位图,lphBI指向宿主位图信息头;
    BYTE *lphDIBBits, *lpDIBBits;//*lpDIBBits指向机要位图,*lphDIBBits指向宿主位图RGB值;
    LPSTR pDIB,phDIB;//pDIB指向机要位图,phDIB指向宿主位图首地址;
    unsigned int b1,b2,b3,s,h;    
    long i,j,*phBits;
    if(hDIB==NULL)
    {
       AfxMessageBox("请打开位图文件!");
       return;
    }
    pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
    lpBI = (LPBITMAPINFOHEADER)pDIB;
    if (lpBI->biBitCount!=8)
    {
       AfxMessageBox("这张不是灰度图!");
       return;
    }
    AfxMessageBox("请选择宿主位图!");
    CFile m_File,savefile;
    CFileException fe,savefe;
    CString FileName;
    CFileDialog m_Dialog(TRUE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
    m_Dialog.DoModal();
    FileName=m_Dialog.GetPathName();
    FileName.ReleaseBuffer();
    if (!m_File.Open(FileName, CFile::modeRead | CFile::shareExclusive, &fe))
    {
        AfxMessageBox("文件打不开!");
        return ;
    }
    shDIB = ::ReadDIBFile(m_File);
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    lphBI = (LPBITMAPINFOHEADER)phDIB;
    if(lphBI->biBitCount<24)
    {
       AfxMessageBox("宿主位图必须是真彩色!");
       return;
    }
    if(lphBI->biWidth * lphBI->biHeight /3 <= lpBI->biWidth * lpBI->biHeight)
    {
       AfxMessageBox("宿主位图太小不能隐藏!");
       return;
     }
    phBits = (long*)::FindDIBBits(phDIB);//指向宿主位图的RGB值;
    lpDIBBits = (BYTE*)::FindDIBBits(pDIB);//指向机要位图的RGB值;
    *phBits = 0x4d424d42;
     phBits++;
    *phBits = lpBI->biWidth;
     phBits ++;
    *phBits = lpBI->biHeight;
     phBits ++;
    lphDIBBits = (BYTE*)phBits;
    lphDIBBits++;
    lphDIBBits++;
     for (i=0; i < lpBI->biWidth; i++)
    {
        for (j = 0; j < lpBI->biHeight; j++)
        {  
           s = *lpDIBBits;
           b3 = s % 10;
           s = s /10;
           b2 = s %10;
           s = s /10;
           b1 = s;
           lpDIBBits++;
           
           h = *lphDIBBits;
           h = h /10;
           *lphDIBBits = h * 10 + b1;
           lphDIBBits++;
           h = *lphDIBBits;
           h = h /10;
           *lphDIBBits = h * 10 + b2;
           lphDIBBits++;
           h = *lphDIBBits;
           h = h /10;
           *lphDIBBits = h * 10 + b3;
           lphDIBBits++;
         }
      }
     ::GlobalUnlock((HGLOBAL) hDIB);
     ::GlobalUnlock((HGLOBAL) shDIB);
     AfxMessageBox("请保存藏有机要位图的宿主位图!");
     CFileDialog m_saveDialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
     m_saveDialog.DoModal();
     FileName=m_saveDialog.GetPathName();
     FileName.ReleaseBuffer();
     if (!savefile.Open(FileName, CFile::modeCreate |  CFile::modeReadWrite | CFile::shareExclusive, &fe))
     {
        AfxMessageBox("文件不能保存!");
        return ;
     }
    ::SaveDIB( shDIB, savefile);
    savefile.Close();
}

/************************************************************************/
/* 灰度图解密函数                                                       */
/************************************************************************/

void CDibView::OnJhudutu()
{
    CDibDoc* pDoc = GetDocument();
    HANDLE hDIB,hDib;//hLogPal指向调色板;hDIB指向机要位图的RGB值;hDib指向机要位图信息头
    HDIB shDIB = pDoc->GetHDIB();
    if(shDIB==NULL)
    {
       AfxMessageBox("请打开位图文件!");
       return;
    }
    BITMAPFILEHEADER bmfHdr;
    DWORD dwDIBSize;
    LPBITMAPINFO lpBI;//lpBI指向机要位图;
    hDib = ::GlobalAlloc (GHND, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
    lpBI = (LPBITMAPINFO)::GlobalLock((HGLOBAL) hDib);
    LONG i,j,*phBits;
    unsigned int b1,b2,b3,h;
    LPSTR pDIB,phDIB;//phDIB指向藏有位图的宿主位图;pDIB指向机要位图;
    phDIB = (LPSTR) ::GlobalLock((HGLOBAL) shDIB);
    phBits = (long *)::FindDIBBits(phDIB);//指向藏有位图的宿主位图的RGB值
    if(*phBits!=0x4d424d42)
    {
        AfxMessageBox("这张位图没有加密!");
        return;
    }
    phBits++;
    lpBI->bmiHeader.biWidth = *phBits;//得到机要位图的宽
    phBits ++;
    lpBI->bmiHeader.biHeight = *phBits;//得到机要位图的高
    phBits ++;
    BYTE *lphDIBBits, *lpDIBBits;//*lphDIBBits指向藏有位图的宿主位图,*lpDIBBits指向机要位图;
    hDIB = ::GlobalAlloc (GHND, WIDTHBYTES((lpBI->bmiHeader.biWidth)* 8 )* lpBI->bmiHeader.biHeight);//分配机要位图RGB大小;
       lpDIBBits = (BYTE *) ::GlobalLock((HGLOBAL) hDIB);
    lphDIBBits = (BYTE *)phBits;
    lphDIBBits++;
    lphDIBBits++;
    for ( i=0; i < lpBI->bmiHeader.biWidth; i++ )
    {
       for ( j=0; j < lpBI->bmiHeader.biHeight; j++)
       {
           h = *lphDIBBits;
           b1 = h % 10;
           lphDIBBits++;
           h = *lphDIBBits;
           b2 = h % 10;
           lphDIBBits++;
           h = *lphDIBBits;
           b3 = h % 10;
           lphDIBBits++;
           *lpDIBBits = b1*100 + b2*10 + b3;
           lpDIBBits++;
       }
    }
    ::GlobalUnlock((HGLOBAL) hDIB);
    pDIB = (LPSTR)::GlobalLock((HGLOBAL) hDIB);
    //以下是填充文件头信息;
    for (h=0; h < 256; h++)
    {
        lpBI->bmiColors[h].rgbBlue=h;
        lpBI->bmiColors[h].rgbGreen=h;
        lpBI->bmiColors[h].rgbRed=h;
        lpBI->bmiColors[h].rgbReserved=0;    
    }//填充调色板;
    bmfHdr.bfType = 0x4d42; //填充文件头
    bmfHdr.bfReserved1 = 0;
    bmfHdr.bfReserved2 = 0;
    dwDIBSize = WIDTHBYTES((lpBI->bmiHeader.biWidth)* 8 )* lpBI->bmiHeader.biHeight;
    bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + (DWORD)256*sizeof(RGBQUAD);
    bmfHdr.bfSize = bmfHdr.bfOffBits + dwDIBSize;
   //以下是填充信息头
   lpBI->bmiHeader.biSize = (DWORD)sizeof(BITMAPINFOHEADER);
   lpBI->bmiHeader.biPlanes = 1;
   lpBI->bmiHeader.biBitCount = 8;
   lpBI->bmiHeader.biCompression =0;
   lpBI->bmiHeader.biSizeImage = dwDIBSize;
   lpBI->bmiHeader.biClrUsed = 0;
   //以下是保存文件;
   AfxMessageBox("请保存解密后的机要位图!");
   CFile m_File;
   CFileException fe;
   CString FileName;
   CFileDialog m_Dialog(FALSE,NULL,"*.bmp",NULL,"位图文件(*.bmp)");
   m_Dialog.DoModal();
   FileName=m_Dialog.GetPathName();
   FileName.ReleaseBuffer();
   if (!m_File.Open(FileName, CFile::modeCreate |
      CFile::modeReadWrite | CFile::shareExclusive, &fe))
   {
      AfxMessageBox("文件保存失败!");
      return ;
    }
   m_File.Write((LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER));
   m_File.Write((LPSTR)lpBI, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
   m_File.WriteHuge(pDIB,dwDIBSize);
   ::GlobalUnlock((HGLOBAL) hDIB);
   ::GlobalUnlock((HGLOBAL) hDib);
   m_File.Close();
}

/************************************************************************/
/* 置乱加密函数                                                         */
/************************************************************************/
void CDibView::OnZhiLuan()
{
   CDibDoc* pDoc = GetDocument();
   HDIB hDIB = pDoc->GetHDIB();
   if(hDIB==NULL)
   {
       AfxMessageBox("请打开位图文件!");
       return;
   }
   long i,j;
   LPBITMAPINFOHEADER lpbi;
   LPSTR lpDIBHdr;
   BYTE *lpDIBBits,temp;
   lpDIBHdr=(LPSTR) ::GlobalLock((HGLOBAL)hDIB);
   lpbi=(LPBITMAPINFOHEADER)lpDIBHdr;
   lpDIBBits=(BYTE*)::FindDIBBits(lpDIBHdr);
   for (i = 0;i < lpbi->biHeight;i++)
   {  
       for (j = 0; j<lpbi->biWidth; j++)
       {
          if(lpbi->biBitCount!=24)//每个字节右移两位;
          {
            temp = *lpDIBBits;
            temp = (temp<<6)&0xc0;
            *lpDIBBits = (*lpDIBBits>>2)&0x3f;
            *lpDIBBits = (*lpDIBBits) | temp;
            lpDIBBits++;
          }
           else
           {
             temp = *lpDIBBits;
             temp = (temp<<6)&0xc0;
             *lpDIBBits = (*lpDIBBits>>2)&0x3f;
             *lpDIBBits = (*lpDIBBits) | temp;
             lpDIBBits++;

             temp = *lpDIBBits;
             temp = (temp<<6)&0xc0;
             *lpDIBBits = (*lpDIBBits>>2)&0x3f;
             *lpDIBBits = (*lpDIBBits) | temp;
             lpDIBBits++;

             temp = *lpDIBBits;
             temp = (temp<<6)&0xc0;
             *lpDIBBits = (*lpDIBBits>>2)&0x3f;
             *lpDIBBits = (*lpDIBBits) | temp;
             lpDIBBits++;
           }
       }
     }

     ::GlobalUnlock((HGLOBAL) hDIB);
     AfxMessageBox("请保存置乱后的机要位图!");
     CFileDialog m_Dialog(false,NULL,"*.bmp",NULL,"位图文件(*.bmp)");//保存文件;
     m_Dialog.DoModal();
     CString FileName;
     FileName=m_Dialog.GetPathName();
     FileName.ReleaseBuffer();
     CFile file;
     CFileException fe;
     if (!file.Open(FileName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive, &fe))
     {
         return ;
     }
     SendMessageToDescendants(WM_DOREALIZE, 1);
     ::SaveDIB(hDIB, file);
     file.Close();
}

/************************************************************************/
/* 置乱解密函数                                                         */
/************************************************************************/
void CDibView::OnJzhiluan()
{
   CDibDoc* pDoc = GetDocument();
   HDIB hDIB = pDoc->GetHDIB();
   if(hDIB==NULL)
   {
       AfxMessageBox("请打开位图文件!");
       return;
   }
   long i;
   LPBITMAPINFOHEADER lpbi;
   LPSTR lpDIBHdr;
   BYTE *lpDIBBits,temp;
   lpDIBHdr=(LPSTR) ::GlobalLock((HGLOBAL)hDIB);
   lpbi=(LPBITMAPINFOHEADER)lpDIBHdr;
   lpDIBBits=(BYTE*)::FindDIBBits(lpDIBHdr);
   for (i=0;i < (lpbi->biHeight*lpbi->biWidth);i++)
   {  
       if(lpbi->biBitCount!=24)//每个字节右移两位;
       {  
          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;
       }
       else
       {
          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;

          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;

          temp = *lpDIBBits;
          temp = (temp>>6)&0x03;
          *lpDIBBits = (*lpDIBBits<<2)&0xfc;
          *lpDIBBits = (*lpDIBBits) | temp;
          lpDIBBits++;
       }
     }
     ::GlobalUnlock((HGLOBAL) hDIB);
     AfxMessageBox("请保存解密后的机要位图!");
     CFileDialog m_Dialog(false,NULL,"*.bmp",NULL,"位图文件(*.bmp)");//保存文件;
     m_Dialog.DoModal();
     CString FileName;
     FileName=m_Dialog.GetPathName();
     FileName.ReleaseBuffer();
     CFile file;
     CFileException fe;
     if (!file.Open(FileName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive, &fe))
     {
         return ;
     }
     SendMessageToDescendants(WM_DOREALIZE, 1);
     ::SaveDIB(hDIB, file);
     file.Close();
}
2008-04-22 21:26
快速回复:有关MFC的程序运行
数据加载中...
 
   



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

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