⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applicationdlg.cpp

📁 matlab source code very useful to science study
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{        
  AfxMessageBox("不能保存位图文件");
		 return;
                  }
}
//保存文本信息到文件中
void CApplicationDlg::OnWSave() 
{
	CFileDialog dlg(FALSE, "SQL", "*.txt",OFN_HIDEREADONLY 
    | OFN_OVERWRITEPROMPT,"Text Files(*.txt)|*.txt|SQL Files(*.sql)|*.sql|All Files(*.*)|*.*||"); 
    if ( dlg.DoModal()!=IDOK ) return; 
    //获取文件的绝对路径 
     CString sFileName=dlg.GetPathName(); 
     CStdioFile out; 
      //打开文件 
      out.Open(sFileName, CFile::modeCreate | CFile::modeWrite); 
      //保存文件 
      CString sStr; 
      m_OriTxt.GetWindowText(sStr);
      if(sStr.IsEmpty())
      AfxMessageBox("没有可保存信息");
      else
      out.WriteString(sStr); 
      out.Close(); 
	// TODO: Add your control notification handler code here	
}

void CApplicationDlg::OnExit() 
{    
	//OnOK();
    if(m_pMainDib!=NULL)
	delete m_pMainDib;
    if(m_pWMainDib!=NULL)
	delete m_pWMainDib;
	DestroyWindow();	
}
//将信息嵌入到图象中
void CApplicationDlg::OnWEmbed() 
{   
    Engine *ep;
    mxArray *l_pOriImage ,*l_pEmdInfo;	
   if(	m_pMainDib==NULL)
   {        
     AfxMessageBox("没有位图");
		  return;
                  }
     CString sStr;
	 int l_nInfoLenth;
	  char  *l_cInfo;
	//  int *l_iInfo; 
     m_OriTxt.GetWindowText(sStr);  

    if(sStr.IsEmpty())
	{
	  AfxMessageBox("没有要嵌入的信息");
        return;
	}
	ep=engOpen(NULL);
   if(ep==NULL)
   {
	 AfxMessageBox("不能打开MATLAB引擎");
       engClose(ep);
	   return ;
   }
   //获得文本框中输入字符的个数
    // l_nInfoLenth=sStr.GetLength();
     l_cInfo=new char[31];
  //   l_iInfo=new int[l_nInfoLenth];
     //将文本框中的字符拷贝到新申请的内存中
	m_OriTxt.GetWindowText(l_cInfo,31);

//	 for(int i=0;i<l_nInfoLenth;i++)
//          l_iInfo[i] =l_cInfo[i];   
	//创建保存字符信息的矩阵
    l_pEmdInfo=mxCreateNumericMatrix(1,30,mxUINT8_CLASS,mxREAL);
	
	/*  l_pEmdInfo=mxCreateString(l_cInfo);
    */
	//将要嵌入的字符信息拷贝到矩阵中
    memcpy((char*)(mxGetPr(l_pEmdInfo)),(char*)l_cInfo,30);
	 //将字符信息传送到MATLAB空间
int	status=engPutVariable(ep,"dnum",l_pEmdInfo); 
   if(status!=0)
   {  
	  AfxMessageBox("不能将水印信息导入引擎空间");
	  goto failure;      
   }
    //获得打开位图的长度与宽度信息
    int l_nWidth,l_nHeight,l_nPerlineBytes; 
    char *pBits;
	l_nWidth= m_pMainDib->GetWidth();
    l_nHeight= m_pMainDib->GetHeight();
    l_nPerlineBytes =m_pMainDib->GetWidthBytes();
    pBits=(char*)m_pMainDib->GetBits();
	//创建用于保存位图数据的矩阵
    l_pOriImage=mxCreateNumericMatrix(l_nHeight,l_nWidth,mxUINT8_CLASS,mxREAL);


    memcpy((char*)(mxGetPr(l_pOriImage)),(char*)pBits,l_nWidth*l_nHeight);//?用字节还是像素
   //将位图数据信息传送到MATLAB空间
    status=engPutVariable(ep,"oimage",l_pOriImage);
   if(status!=0)
   {  
	  AfxMessageBox("不能将图象数据导入引擎空间");
	  goto failure;       
   }
 //执行嵌入函数
 status= engEvalString(ep,"image=watermark_lsb_embed(oimage,dnum)");
//status= engEvalString(ep,"image=watermark_lsb_embednew1(oimage)");

 if(status!=0)
   {  
	  AfxMessageBox("引擎执行错误");
	  goto failure;      
   }
 //将嵌入水印的图象取回并拷贝到原位图数据区中
 l_pOriImage=engGetVariable(ep,"image");


 memcpy((char*)pBits,(char*)mxGetPr(l_pOriImage),l_nWidth*l_nHeight);

 AfxMessageBox("已成功嵌入水印信息");
 

 failure: mxDestroyArray(l_pOriImage);
         mxDestroyArray(l_pEmdInfo);
         engClose(ep);
		 delete l_cInfo;
		 return;
}
//打开带水印的位图
void CApplicationDlg::OnButtonWBmpFile() 
{
	CString strFile;
	//打开位图文件
	CFileDialog FileDlg(TRUE, "", NULL, 
	OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, 
	"BMP图像(*.bmp)|*.bmp|所有文件(*.*)|*.*||",
	AfxGetMainWnd());
	if (FileDlg.DoModal () != IDOK)
		return;
     POSITION pos = FileDlg.GetStartPosition();
     strFile = FileDlg.GetNextPathName(pos);
     m_sFileName=strFile;
	 if(m_pWMainDib!=NULL)
		delete m_pWMainDib;
     m_pWMainDib = new CDib();
	 if(m_pWMainDib->Open(strFile)!=TRUE)
	 {
		 AfxMessageBox("不能打开位图文件");
		 delete m_pMainDib;
		 return;
	 }
	 CWnd *pWndBmp= GetDlgItem(IDC_HBMP_SHOW); 
	 //获得图片的设备上下文
	 CDC *pDCShow = pWndBmp->GetDC();
	 RECT rt;
	 pWndBmp->GetWindowRect(&rt);	 
    // m_nWndWidth = m_pMainDib->GetWidth();
	// m_nWndHeight= m_pMainDib->GetHeight();	 
     int l_nWndWidth=rt.right-rt.left;
	 int l_nWndHeight=rt.bottom-rt.top;
	 //将位图显示在图片框中
	m_pWMainDib->Draw(pDCShow,l_nWndWidth, l_nWndHeight);
	
}
//提取水印
void CApplicationDlg::OnWExtract() 
{
  
	Engine *ep;
   mxArray *l_pExtImage ,*l_pExtInfo,*bmpFile=NULL;
   if(m_pWMainDib==NULL)
   {        
     AfxMessageBox("没有水印图象");
	 return ;
   }    
   ep=engOpen(NULL);
   if(ep==NULL)
   {
	 AfxMessageBox("不能打开MATLAB引擎");
       engClose(ep);
	   return ;
   }

 /*   bmpFile=mxCreateString(m_sFileName);
  int status= engPutVariable(ep,"str",bmpFile);
     if(status!=0)
	 {  
	   AfxMessageBox("不能引入引擎空间");
	   goto failure;       
	 }
     status= engEvalString(ep,"einfo=watermark_lsb_extract(str)");
     if(status!=0)
   {  
	  AfxMessageBox("引擎执行错误");
	  goto failure;       
   }


     TCHAR *l_cInfo;
     l_cInfo=new TCHAR[256];
     l_pExtInfo=engGetVariable(ep,"str");
     memcpy((TCHAR*)l_cInfo,(TCHAR*)mxGetPr(l_pExtInfo),256);*/

   //获得位图的长度、宽度,及数据区的指针
   int l_nWidth = m_pWMainDib->GetWidth();
   int l_nHeight= m_pWMainDib->GetHeight();
   int l_nPerlineBytes=m_pWMainDib->GetWidthBytes();
   BYTE *pBits=m_pWMainDib->GetBits();
   //创建用于保存位图数据的矩阵
   l_pExtImage=mxCreateNumericMatrix(l_nHeight,l_nPerlineBytes,mxUINT8_CLASS,mxREAL);
   //将位图数据拷贝到矩阵中
   memcpy((BYTE*)(mxGetPr(l_pExtImage)),(BYTE*)pBits,l_nPerlineBytes*l_nHeight);
   //将位图数据引入MATLAB空间
   int status=engPutVariable(ep,"eimage",l_pExtImage);
   if(status!=0)
   {  
	  AfxMessageBox("不能引入引擎空间");
	  goto failure;       
   } 
   //创建用于保存30个字符的矩阵
   //l_pExtInfo=mxCreateNumericMatrix(1,30,mxUINT8_CLASS,mxREAL);
   /*
   TCHAR *l_cInfo=new TCHAR[30];
   l_pExtInfo=mxCreateString(l_cInfo);
   
  */
   //将矩阵引入MATLAB空间
  /*status=engPutVariable(ep,"einfo",l_pExtInfo);//该句没必要
   if(status!=0)
   {  
	  AfxMessageBox("不能引入引擎空间");
	  goto failure;       
   }
   */
   //调用水印提取函数
   status= engEvalString(ep,"einfo=watermark_lsb_extract(eimage)");
   if(status!=0)
   {  
	  AfxMessageBox("引擎执行错误");
	  goto failure;       
   }
   //获得水印信息
     l_pExtInfo=engGetVariable(ep,"einfo");
/*	 unsigned char *l_cInfo;
      l_cInfo=new unsigned char[l_nInfoLenth];
	  //将水印信息拷贝到一个字符数组中
      memcpy((unsigned char*)l_cInfo,(unsigned char*)mxGetPr(l_pExtInfo),30);
	  */
       char *l_cInfo,*l_cRes;
	  int i,j;
      l_cInfo=new  char[31];
     
	  //将水印信息拷贝到一个字符数组中
      memcpy((BYTE*)l_cInfo,(BYTE*)mxGetPr(l_pExtInfo),30);
	  l_cInfo[30]='\0';
 
      m_ExtTxt.SetWindowText(l_cInfo);
      failure: mxDestroyArray(bmpFile);
               mxDestroyArray(l_pExtInfo);
               engClose(ep);
		       delete l_cInfo;
		       return;
	// TODO: Add your control notification handler code here
	
}
/*备用的代码,在有些地方需要强制类型转换
#include "TCHAR.h"
#include "wTCHAR.h"
#include "atlconv.h"
  void main()
  {
   TCHAR    *szProgID="MAPI.Folder";   
   wTCHAR_t*   szWideProgID[128];   
   long   lLen=MultiByteToWideTCHAR(CP_ACP,0,szProgID,strlen(szProgID),szWideProgID,sizeof(szWideProgID));   
  szWideProgID[lLen]='\0';  
  cout<<lLen;
  cout<<szProgID;


  TCHAR    *szProgID="MAPI.Folder";   
   wTCHAR_t*   szWideProgID[128];   
   long   lLen=MultiByteToWideTCHAR(CP_ACP,0,szProgID,strlen(szProgID),(wTCHAR_t*)szWideProgID,sizeof(szWideProgID));   
  szWideProgID[lLen]='\0';  

  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -