// CutPhoto.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "CutPhoto.h" #include "SetSize.h" #include "ShowCut.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CutPhoto dialog CutPhoto::CutPhoto(CWnd* pParent /*=NULL*/) : CDialog(CutPhoto::IDD, pParent) { //{{AFX_DATA_INIT(CutPhoto) m_pImg=NULL; m_width=0; m_height=0; m_fscale=1.0; m_slider1 = 0; //}}AFX_DATA_INIT } void CutPhoto::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CutPhoto) DDX_Control(pDX, IDC_SLIDER1, m_sliderctrl); DDX_Control(pDX, IDC_COMBO1, m_combo1); DDX_Slider(pDX, IDC_SLIDER1, m_slider1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CutPhoto, CDialog) //{{AFX_MSG_MAP(CutPhoto) ON_WM_PAINT() ON_BN_CLICKED(IDC_BUTTON7, OnButton7) ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(IDC_BUTTON5, OnButton5) ON_BN_CLICKED(IDC_BUTTON6, OnButton6) ON_BN_CLICKED(IDC_BUTTON10, OnButton10) ON_BN_CLICKED(IDC_BUTTON32, OnButton32) ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER1, OnCustomdrawSlider1) ON_NOTIFY(NM_OUTOFMEMORY, IDC_SLIDER1, OnOutofmemorySlider1) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CutPhoto message handlers BOOL CutPhoto::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here g_sendhead.bsql=0; g_sendhead.code[0]=11; g_sendhead.code[1]=174; g_sendhead.tabcount=2; CString filter="id='"+m_id+"';"; g_pMainWnd->ProcessChatMessageRequest2(filter); if(g_bSendOK==0) { CDialog::OnCancel (); return 0; } CArraym_List1array; DataToArray(&m_List1array, &g_List1array); CenterWindow(); if(m_List1array.GetSize () )m_size= m_List1array.ElementAt (0).ElementAt (60); m_sliderctrl.SetRange (0, 50); m_combo1.ResetContent (); namearray.RemoveAll (); widtharray.RemoveAll (); heightarray.RemoveAll (); for(int i=0; iGetWindowRect(rc); ScreenToClient(rc); m_paintrc=rc; ::RectFitDes (m_width, m_height, m_paintrc); Graphics graph(dc.GetSafeHdc ()); LinearGradientBrush linGrBrush( Point(0, 0), Point( 1.44*max(m_paintrc.Width (),m_paintrc.Height ()), 1.44*max(m_paintrc.Width (),m_paintrc.Height ())), Color(255, 255, 250, 156), // opaque blue Color(255, 176, 125, 44)); // opaque green graph.FillRectangle(&linGrBrush, m_paintrc.left , m_paintrc.top , m_paintrc.Width (), m_paintrc.Height ()); // dc.FillSolidRect (m_paintrc, RGB(234,208,98)); m_paintrc.DeflateRect (m_slider1, m_slider1, m_slider1, m_slider1); rc=m_paintrc; CRect rc2(0,0,m_pImg->GetWidth(), m_pImg->GetHeight()); ::RectFitDes (rc.Width (), rc.Height (), rc2);m_photorcbak=rc2; if(m_photorc.right==0) { m_photorc=rc2; } else { rc2=m_photorc; } Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ()); graph.DrawImage(m_pImg, destinationRect, rc2.left , rc2.top , rc2.Width (), rc2.Height (), UnitPixel); if(m_slider1==0) dc.Draw3dRect (m_paintrc, RGB(255,0,0), RGB(255,0,0)); /////////////////// { GetDlgItem(IDC_STATIC2)->GetWindowRect(rc); ScreenToClient(rc); ::RectFitDes (m_pImg->GetWidth(), m_pImg->GetHeight(), rc); Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ()); graph.DrawImage(m_pImg, destinationRect, 0 , 0 , m_pImg->GetWidth(), m_pImg->GetHeight(), UnitPixel); float scale=(float)rc.Width ()/(float)m_pImg->GetWidth(); rc2.left *=scale; rc2.right *=scale; rc2.top *=scale; rc2.bottom *=scale; rc2.left +=rc.left ; rc2.right +=rc.left ; rc2.top +=rc.top ; rc2.bottom +=rc.top ; dc.Draw3dRect (rc2, RGB(255,0,0), RGB(255,0,0)); } } // Do not call CDialog::OnPaint() for painting messages } void CutPhoto::OnButton7() { // TODO: Add your control notification handler code here SetSize dlg; dlg.DoModal();GetSize(); } void CutPhoto::GetSize() { g_sendhead.bsql=0; g_sendhead.code[0]=174; g_sendhead.tabcount=1; g_pMainWnd->ProcessChatMessageRequest2(6); if(g_bSendOK==0) { return; } DataToArray(&g_List1array); CenterWindow(); m_combo1.ResetContent (); namearray.RemoveAll (); widtharray.RemoveAll (); heightarray.RemoveAll (); for(int i=0; iGetWidth()/(float)rc.left; rc2.left *=scale; rc2.right *=scale; rc2.top *=scale; rc2.bottom *=scale; m_photorc=rc2; } } RefreshRc(); // CString ss; // ss.Format ("%s %d,%d", namearray.ElementAt (pos), widtharray.ElementAt (pos),heightarray.ElementAt (pos)); // AfxMessageBox(ss); } void CutPhoto::OnButton1() { // TODO: Add your control notification handler code here if(m_photorc.right==0)return; int dt=m_photorc.Width ()-m_photorc.Width ()/1.2; dt/=2; m_photorc.left +=dt; m_photorc.right -=dt; if(m_photorc.left<0)m_photorc.left=0; if(m_photorc.right>m_photorcbak.right)m_photorc.right=m_photorcbak.right; dt=m_photorc.Height ()-m_photorc.Height ()/1.2; dt/=2; m_photorc.top +=dt; m_photorc.bottom =m_photorc.top+m_photorc.Width ()*m_photorcbak.Height ()/m_photorcbak.Width (); if(m_photorc.top<0)m_photorc.top=0; if(m_photorc.bottom>m_photorcbak.bottom)m_photorc.bottom=m_photorcbak.bottom; RefreshRc(); } void CutPhoto::OnButton2() { // TODO: Add your control notification handler code here if(m_photorc.right==0)return; int dt=m_photorc.Width ()-m_photorc.Width ()*0.8; dt/=2; m_photorc.left -=dt; m_photorc.right +=dt; if(m_photorc.left<0)m_photorc.left=0; if(m_photorc.right>m_photorcbak.right)m_photorc.right=m_photorcbak.right; dt=m_photorc.Height ()-m_photorc.Height ()*0.8; dt/=2; m_photorc.top -=dt; m_photorc.bottom =m_photorc.top+m_photorc.Width ()*m_photorcbak.Height ()/m_photorcbak.Width (); if(m_photorc.top<0)m_photorc.top=0; if(m_photorc.bottom>m_photorcbak.bottom)m_photorc.bottom=m_photorcbak.bottom; RefreshRc(); } void CutPhoto::OnButton3() { // TODO: Add your control notification handler code here if(m_photorc.right==0)return; int dt=m_photorcbak.Width ()/50;if(dt<1)dt=1; if( (m_photorc.right+dt)>(m_pImg->GetWidth()-1) ) dt=m_pImg->GetWidth()-m_photorc.right-1; m_photorc.left +=dt; m_photorc.right +=dt; RefreshRc(); } void CutPhoto::OnButton4() { // TODO: Add your control notification handler code here if(m_photorc.right==0)return; int dt=m_photorcbak.Width ()/50;if(dt<1)dt=1; if( (m_photorc.left-dt)<0 ) dt=m_photorc.left; m_photorc.left -=dt; m_photorc.right -=dt; RefreshRc(); } void CutPhoto::OnButton5() { // TODO: Add your control notification handler code here // TODO: Add your control notification handler code here if(m_photorc.right==0)return; int dt=m_photorcbak.Height ()/50;if(dt<1)dt=1; if( (m_photorc.bottom+dt)>(m_pImg->GetHeight()-1) ) dt=m_pImg->GetHeight()-m_photorc.bottom-1; m_photorc.top +=dt; m_photorc.bottom +=dt; RefreshRc(); } void CutPhoto::OnButton6() { // TODO: Add your control notification handler code here if(m_photorc.right==0)return; int dt=m_photorcbak.Height ()/50;if(dt<1)dt=1; if( (m_photorc.top-dt)<0 ) dt=m_photorc.top; m_photorc.top -=dt; m_photorc.bottom -=dt; RefreshRc(); } void CutPhoto::RefreshRc() { UpdateData(); CRect rc; GetDlgItem(IDC_STATIC1)->GetWindowRect(rc); ScreenToClient(rc); InvalidateRect(rc); GetDlgItem(IDC_STATIC2)->GetWindowRect(rc); ScreenToClient(rc); InvalidateRect(rc); } void CutPhoto::OnButton10() { // TODO: Add your control notification handler code here if(! (m_width && m_height) ) { AfxMessageBox("请选择尺寸!"); return; } CString str; str.Format ("%s:%s,%d,%d,%d,%d,%d,%d;", m_path, m_name, m_pImg->GetWidth(), m_pImg->GetHeight(), m_photorc.left, m_photorc.top , m_photorc.right , m_photorc.bottom ); int pos; CString header=m_path+":"+m_name+","; pos=m_size.Find (header); if(pos!=-1) { CString left,right; left=m_size.Left (pos); m_size=m_size.Right (m_size.GetLength ()-pos-header.GetLength ()); pos=m_size.Find (";"); right=m_size.Right (m_size.GetLength ()-pos-1); m_size=left+right; } m_size+=str; CString sql; sql.Format ("update dindan set size='%s' where id='%s'", m_size, m_id); g_sendhead.bsql=1; g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return; AfxMessageBox("保存成功!"); // CDialog::OnCancel (); } void CutPhoto::OnButton32() { // TODO: Add your control notification handler code here ShowCut dlg; dlg.m_id =m_id; dlg.DoModal (); g_sendhead.bsql=0; g_sendhead.code[0]=11; g_sendhead.tabcount=1; CString filter="id='"+m_id+"';"; g_pMainWnd->ProcessChatMessageRequest2(filter); if(g_bSendOK==0) { CDialog::OnCancel (); return ; } CArraym_List1array; DataToArray(&m_List1array); CenterWindow(); if(m_List1array.GetSize () ) { m_size= m_List1array.ElementAt (0).ElementAt (60); } } void CutPhoto::OnCustomdrawSlider1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here *pResult = 0; } void CutPhoto::OnOutofmemorySlider1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here *pResult = 0; } void CutPhoto::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here RefreshRc(); *pResult = 0; }