// SendInsideMsg2.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "SendInsideMsg2.h" #include "ShowPhoto.h" #include "SelFile.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // SendInsideMsg2 dialog messagebox SendInsideMsg2::SendInsideMsg2(CWnd* pParent /*=NULL*/) : CDialog(SendInsideMsg2::IDD, pParent) { //{{AFX_DATA_INIT(SendInsideMsg2) m_content = _T(""); m_path = _T(""); m_bShow=0; m_pArray=NULL; m_pos=0; //}}AFX_DATA_INIT } void SendInsideMsg2::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(SendInsideMsg2) DDX_Text(pDX, IDC_EDT_SMS, m_content); DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_path); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(SendInsideMsg2, CDialog) //{{AFX_MSG_MAP(SendInsideMsg2) ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // SendInsideMsg2 message handlers BOOL SendInsideMsg2::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here if(m_bShow && m_pArray) { SetWindowText("公告详情"); GetDlgItem(IDC_STATIC1)->SetWindowText("公告详情"); GetDlgItem(IDC_BUTTON1)->SetWindowText("查看"); GetDlgItem(IDC_BTN_SEND)->ShowWindow(SW_HIDE); if(m_pArray->GetSize ()>1) { GetDlgItem(IDC_BUTTON2)->ShowWindow(SW_SHOW); GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_SHOW); } OnButton2(); // CString str; // str.Format ("发布人(%s) 时间(%s) 内容:", sender, time); // GetDlgItem(IDC_STATIC2)->SetWindowText(str); } else if(m_bShow) { SetWindowText("公告详情"); GetDlgItem(IDC_STATIC1)->SetWindowText("公告详情"); GetDlgItem(IDC_BUTTON1)->SetWindowText("查看"); GetDlgItem(IDC_BTN_SEND)->ShowWindow(SW_HIDE); CString str; str.Format ("发布人(%s) 时间(%s) 内容:", sender, time); GetDlgItem(IDC_STATIC2)->SetWindowText(str); } CenterWindow(g_pMainWnd); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } extern void SaveImageToFile2(Image *img, CString path, ULONG quality); void SendInsideMsg2::OnBtnSend() { // TODO: Add your control notification handler code here UpdateData(); if(m_content.IsEmpty ()) { AfxMessageBox("内容不能为空!");return; } if(m_content.GetLength ()>4000) { AfxMessageBox("内容太长!");return; } CString filename,curfile,filename2; int pos=m_path.Find(";"); BYTE *pData=new BYTE[1024*200*5+4000]; DWORD length=0; DWORD fileleng; int filenum=0; while(pos!=-1 || m_path!="") { if(filenum>=5) { AfxMessageBox("注意:文件太多,仅保存了前5个文件!", MB_ICONINFORMATION); break; } if(pos!=-1) curfile=m_path.Left(pos); else { curfile=m_path; m_path=""; } CFile fp; if(fp.Open(curfile, CFile::modeRead)) { filename2=curfile.Right(curfile.GetLength()-curfile.ReverseFind('\\')-1); filename+=filename2; filename+=";"; fileleng=fp.GetLength(); if(fileleng>1024*200) { CString ext; if(curfile.Find(".")!=-1) ext=curfile.Right(curfile.GetLength()-curfile.ReverseFind('.')-1); ext.MakeLower (); if(!(ext=="jpg" || ext=="jpeg" || ext=="png"|| ext=="bmp")) { AfxMessageBox("文件太大,请上传小于200K的文件!"); fp.Close(); delete []pData; return; } else { fp.Close(); Image *m_pImg=NULL; ::LoadImageFromBuf(&m_pImg, curfile); if(m_pImg==NULL) { AfxMessageBox("无效图片!"); delete []pData; return; } Image *simg2=NULL; CRect rc2(0,0,1600,1600); RectFitDes(m_pImg->GetWidth(), m_pImg->GetHeight(), rc2); simg2=m_pImg->GetThumbnailImage(rc2.Width (), rc2.Height (), NULL, NULL); Graphics graphic2(simg2);//防止GetThumbnailImage影响质量 graphic2.Clear(Color(255,255,255,255)); graphic2.DrawImage(m_pImg, 0,0,simg2->GetWidth(), simg2->GetHeight() ); if(m_pImg)delete m_pImg;m_pImg=NULL; CString path=g_mainpath+"\\1."+ext; ::SaveImageToFile2 (simg2, path, 40); delete simg2; if(!fp.Open(path, CFile::modeRead)) { AfxMessageBox("文件打开失败!"); delete []pData; return; } fileleng=fp.GetLength(); } } memcpy(pData+length, &fileleng, sizeof(fileleng));length+=sizeof(fileleng); fp.Read(pData+length, fileleng);length+=fileleng; fp.Close(); filenum++; } else { AfxMessageBox("附件未找到!", MB_ICONINFORMATION); } if(pos!=-1) m_path=m_path.Right(m_path.GetLength()-pos-1); pos=m_path.Find(";"); } filename.TrimRight(";"); CString timestamp=g_date+" curtimereplace"; timestamp="msgtimestamp2"; CString sql="insert into insidemsg([content],[timestamp],[sender],[receiver],[file]) values('"+m_content+"','"+timestamp+"','"+g_user.name+"','','"+filename+"')"; fileleng=sql.GetLength(); memcpy(pData+length, &fileleng, sizeof(fileleng)); DWORD nSqlPos=length; length+=sizeof(fileleng); memcpy(pData+length, sql.GetBuffer(0), fileleng); sql.ReleaseBuffer(); length+=fileleng; memcpy(pData+length, &nSqlPos, sizeof(nSqlPos));length+=sizeof(nSqlPos); g_nSendCode=33; g_pMainWnd->ProcessChatMessageRequest2(pData, length); g_nSendCode=0; delete []pData; if(g_bSendOK==0)return; AfxMessageBox("公告发布成功!", MB_ICONINFORMATION); CDialog::OnOK(); /* UpdateData(); if(m_content.IsEmpty ()) { AfxMessageBox("内容不能为空!");return; } if(m_content.GetLength ()>4000) { AfxMessageBox("内容太长!");return; } CTime tm=CTime::GetCurrentTime(); CTimeSpan dt(0, 0, 0, 1); CString filename,curfile,filename2; int pos=m_path.Find(";"); while(pos!=-1 || m_path!="") { if(pos!=-1) curfile=m_path.Left(pos); else { curfile=m_path; m_path=""; } if(::PathFileExists(curfile)) { ::CreateDirectory(g_path1+"\\公告附件", NULL); CString ext; if(curfile.Find(".")!=-1) ext=curfile.Right(curfile.GetLength()-curfile.ReverseFind('.')); filename2=tm.Format ("%Y%m%d%H%M%S"); tm+=dt; filename2+=ext; filename+=filename2; filename+=";"; if(::CopyFile(curfile, g_path1+"\\公告附件\\"+filename2, 0)==0) AfxMessageBox("附件上传失败!", MB_ICONINFORMATION); } else { AfxMessageBox("附件未找到!", MB_ICONINFORMATION); } if(pos!=-1) m_path=m_path.Right(m_path.GetLength()-pos-1); pos=m_path.Find(";"); } filename.TrimRight(";"); CString timestamp=g_date+" curtimereplace"; CString sql="insert into insidemsg([content],[timestamp],[sender],[receiver],[file]) values('"+m_content+"','"+timestamp+"','"+g_user.name+"','','"+filename+"')"; g_sendhead.bsql=1; g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return; AfxMessageBox("公告发布成功!", MB_ICONINFORMATION); CDialog::OnOK(); */ } //extern void DeleteDirectory(CString strDir); void SendInsideMsg2::OnButton1() { // TODO: Add your control notification handler code here if(m_bShow) { CString m_pathtemp=m_path; CString curfile; int pos=m_path.Find(";"); CStringArray patharray; while(pos!=-1 || m_path!="") { if(pos!=-1) curfile=m_path.Left(pos); else { curfile=m_path; m_path=""; } CString str=g_path1+"\\公告附件\\"+curfile;patharray.Add(str); if(pos!=-1) m_path=m_path.Right(m_path.GetLength()-pos-1); pos=m_path.Find(";"); } m_path=m_pathtemp; char no[20]; memset(no, 0, 20); strcpy(no, time); g_nSendCode=34; g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 20); g_nSendCode=0; if(g_bSendOK==0) { return; } DWORD nReaded=0; int filepos=0; DeleteDirectory(g_mainpath+"\\公告"); ::CreateDirectory(g_mainpath+"\\公告", NULL); CStringArray patharraytemp; while(nReaded=patharray.GetSize())break; CString path=patharray.ElementAt(filepos);filepos++; path=g_mainpath+"\\公告"+path.Right(path.GetLength()-path.ReverseFind('\\')); DWORD leng; memcpy(&leng, g_pData+nReaded, sizeof(DWORD));nReaded+=sizeof(DWORD); CFile fp; fp.Open(path, CFile::modeWrite|CFile::modeCreate); fp.Write(g_pData+nReaded, leng);nReaded+=leng; fp.Close(); patharraytemp.Add(path); } patharray.RemoveAll(); patharray.Copy(patharraytemp); ShowFile(&patharray); return; } UpdateData(); CFileDialog fdlg(true, NULL,"", OFN_ALLOWMULTISELECT, "文档(*.*)|*.*||"); TCHAR szBuffer[60000]={0}; fdlg.m_ofn.lpstrFile = szBuffer; fdlg.m_ofn.nMaxFile = 60000; if(fdlg.DoModal ()!=IDOK)return; // m_path=""; POSITION pos=fdlg.GetStartPosition (); while(pos!=NULL) { m_path+=fdlg.GetNextPathName (pos); m_path+=";"; } // m_path.TrimRight(";"); // m_path=fdlg.GetPathName(); UpdateData(0); } void SendInsideMsg2::OnButton2() { // TODO: Add your control notification handler code here m_pos--; if(m_pos<0)m_pos=m_pArray->GetSize ()-1; sender=m_pArray->ElementAt (m_pos).ElementAt (0); m_content=m_pArray->ElementAt (m_pos).ElementAt (1); time=m_pArray->ElementAt (m_pos).ElementAt (2); m_path=m_pArray->ElementAt (m_pos).ElementAt (5); CString str; str.Format ("发布人(%s) 时间(%s) 内容:", sender, time); GetDlgItem(IDC_STATIC2)->SetWindowText(str); UpdateData(false); MarkRead(); } void SendInsideMsg2::OnButton3() { // TODO: Add your control notification handler code here m_pos++; if(m_pos>=m_pArray->GetSize ())m_pos=0; sender=m_pArray->ElementAt (m_pos).ElementAt (0); m_content=m_pArray->ElementAt (m_pos).ElementAt (1); time=m_pArray->ElementAt (m_pos).ElementAt (2); m_path=m_pArray->ElementAt (m_pos).ElementAt (5); CString str; str.Format ("发布人(%s) 时间(%s) 内容:", sender, time); GetDlgItem(IDC_STATIC2)->SetWindowText(str); UpdateData(false); MarkRead(); } void SendInsideMsg2::MarkRead() { CString receivers2,str; str=","+g_user.name+","; receivers2=m_pArray->ElementAt (m_pos).ElementAt (4); receivers2.TrimLeft(","); receivers2.TrimRight(","); receivers2=","+receivers2+","; if(receivers2.Find(str)==-1) { receivers2.TrimLeft(","); receivers2+=str; CString sql="update insidemsg set [receiver2]='"+receivers2+"' where [timestamp]='"+m_pArray->ElementAt (m_pos).ElementAt (2)+"' and [sender]='"+m_pArray->ElementAt (m_pos).ElementAt (0)+"'"; g_sendhead.bsql=1; g_pMainWnd->ProcessChatMessageRequest2(sql); if(g_bSendOK==1) { m_pArray->ElementAt (m_pos).SetAt (4, receivers2); } } } void SendInsideMsg2::ShowFile(CStringArray *patharray) { if(patharray->GetSize()==0)return; if(patharray->GetSize()==1) { CString str=patharray->ElementAt(0); CString ext; if(str.Find(".")!=-1) ext=str.Right(str.GetLength()-str.ReverseFind('.')-1); ext.MakeLower (); if(0)//ext=="jpg" || ext=="jpeg" || ext=="png" || ext=="gif"|| ext=="bmp") { Image *m_pImg=NULL; ::LoadImageFromBuf (&m_pImg, str); if(m_pImg==NULL) { AfxMessageBox("无效图片文件!");return; } ShowPhoto dlg; dlg.m_pImg=m_pImg; dlg.DoModal(); delete m_pImg; } else { ShellExecute(NULL, _T("open"), str, NULL, NULL, SW_SHOWMAXIMIZED); } return; } SelFile dlg; dlg.m_pArray=patharray; dlg.DoModal(); }