123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- // 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;
- }
- CArray<CStringArray, CStringArray>m_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; i<g_List1array.GetSize (); i++)
- {
- namearray.Add (g_List1array.ElementAt (i).ElementAt (0));
- widtharray.Add (atoi(g_List1array.ElementAt (i).ElementAt (1)));
- heightarray.Add (atoi(g_List1array.ElementAt (i).ElementAt (2)));
- CString str;
- str.Format (_T("%s 宽:%d 高:%d"), g_List1array.ElementAt (i).ElementAt (0), atoi(g_List1array.ElementAt (i).ElementAt (1)), atoi(g_List1array.ElementAt (i).ElementAt (2)));
- m_combo1.AddString(str);
- }
- if(m_combo1.GetCount ())
- {
- m_combo1.SetCurSel (0);OnSelchangeCombo1();
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CutPhoto::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- if(m_width && m_height)
- {
- CRect rc;
- GetDlgItem(IDC_STATIC1)->GetWindowRect(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; i<g_List1array.GetSize (); i++)
- {
- namearray.Add (g_List1array.ElementAt (i).ElementAt (0));
- widtharray.Add (atoi(g_List1array.ElementAt (i).ElementAt (1)));
- heightarray.Add (atoi(g_List1array.ElementAt (i).ElementAt (2)));
- CString str;
- str.Format (_T("%s 宽:%d 高:%d"), g_List1array.ElementAt (i).ElementAt (0), atoi(g_List1array.ElementAt (i).ElementAt (1)), atoi(g_List1array.ElementAt (i).ElementAt (2)));
- m_combo1.AddString(str);
- }
- if(m_combo1.GetCount ())
- {
- m_combo1.SetCurSel (0);OnSelchangeCombo1();
- }
- }
- void CutPhoto::OnSelchangeCombo1()
- {
- // TODO: Add your control notification handler code here
- int pos=m_combo1.GetCurSel ();
- if(pos==-1)return;
- m_photorc.right=0;
- m_fscale=1.0;
- m_width=widtharray.ElementAt (pos);
- m_height=heightarray.ElementAt (pos);
- m_name=namearray.ElementAt (pos);
-
- CString header=m_path+":"+m_name+",";
- pos=m_size.Find (header);
- if(pos!=-1)
- {
- CString str=m_size.Right (m_size.GetLength ()-pos);
- CString size=str.Left (str.Find (";"));
- int pos=size.Find (":");
- if(pos!=-1)
- {
-
- CRect rc,rc2;
- str=size.Left (pos);
- str=size.Right (size.GetLength ()-pos-1);
- pos=str.Find (",");
- str.Delete (0, pos+1);
- pos=str.Find (",");
- rc.left=atoi(str.Left (pos));str.Delete (0, pos+1);
- pos=str.Find (",");
- rc.top=atoi(str.Left (pos));str.Delete (0, pos+1);
-
- pos=str.Find (",");
- rc2.left=atoi(str.Left (pos));str.Delete (0, pos+1);
- pos=str.Find (",");
- rc2.top=atoi(str.Left (pos));str.Delete (0, pos+1);
- pos=str.Find (",");
- rc2.right=atoi(str.Left (pos));str.Delete (0, pos+1);
- rc2.bottom=atoi(str);
-
- float scale=(float)m_pImg->GetWidth()/(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 ;
- }
- CArray<CStringArray, CStringArray>m_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;
- }
|