CutPhoto.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. // CutPhoto.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "CutPhoto.h"
  6. #include "SetSize.h"
  7. #include "ShowCut.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CutPhoto dialog
  15. CutPhoto::CutPhoto(CWnd* pParent /*=NULL*/)
  16. : CDialog(CutPhoto::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CutPhoto)
  19. m_pImg=NULL;
  20. m_width=0;
  21. m_height=0;
  22. m_fscale=1.0;
  23. m_slider1 = 0;
  24. //}}AFX_DATA_INIT
  25. }
  26. void CutPhoto::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CutPhoto)
  30. DDX_Control(pDX, IDC_SLIDER1, m_sliderctrl);
  31. DDX_Control(pDX, IDC_COMBO1, m_combo1);
  32. DDX_Slider(pDX, IDC_SLIDER1, m_slider1);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CutPhoto, CDialog)
  36. //{{AFX_MSG_MAP(CutPhoto)
  37. ON_WM_PAINT()
  38. ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
  39. ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  40. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  41. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  42. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  43. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  44. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  45. ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
  46. ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
  47. ON_BN_CLICKED(IDC_BUTTON32, OnButton32)
  48. ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER1, OnCustomdrawSlider1)
  49. ON_NOTIFY(NM_OUTOFMEMORY, IDC_SLIDER1, OnOutofmemorySlider1)
  50. ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CutPhoto message handlers
  55. BOOL CutPhoto::OnInitDialog()
  56. {
  57. CDialog::OnInitDialog();
  58. // TODO: Add extra initialization here
  59. g_sendhead.bsql=0;
  60. g_sendhead.code[0]=11;
  61. g_sendhead.code[1]=174;
  62. g_sendhead.tabcount=2;
  63. CString filter="id='"+m_id+"';";
  64. g_pMainWnd->ProcessChatMessageRequest2(filter);
  65. if(g_bSendOK==0)
  66. {
  67. CDialog::OnCancel ();
  68. return 0;
  69. }
  70. CArray<CStringArray, CStringArray>m_List1array;
  71. DataToArray(&m_List1array, &g_List1array);
  72. CenterWindow();
  73. if(m_List1array.GetSize () )m_size= m_List1array.ElementAt (0).ElementAt (60);
  74. m_sliderctrl.SetRange (0, 50);
  75. m_combo1.ResetContent ();
  76. namearray.RemoveAll ();
  77. widtharray.RemoveAll ();
  78. heightarray.RemoveAll ();
  79. for(int i=0; i<g_List1array.GetSize (); i++)
  80. {
  81. namearray.Add (g_List1array.ElementAt (i).ElementAt (0));
  82. widtharray.Add (atoi(g_List1array.ElementAt (i).ElementAt (1)));
  83. heightarray.Add (atoi(g_List1array.ElementAt (i).ElementAt (2)));
  84. CString str;
  85. 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)));
  86. m_combo1.AddString(str);
  87. }
  88. if(m_combo1.GetCount ())
  89. {
  90. m_combo1.SetCurSel (0);OnSelchangeCombo1();
  91. }
  92. return TRUE; // return TRUE unless you set the focus to a control
  93. // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. void CutPhoto::OnPaint()
  96. {
  97. CPaintDC dc(this); // device context for painting
  98. // TODO: Add your message handler code here
  99. if(m_width && m_height)
  100. {
  101. CRect rc;
  102. GetDlgItem(IDC_STATIC1)->GetWindowRect(rc);
  103. ScreenToClient(rc);
  104. m_paintrc=rc;
  105. ::RectFitDes (m_width, m_height, m_paintrc);
  106. Graphics graph(dc.GetSafeHdc ());
  107. LinearGradientBrush linGrBrush(
  108. Point(0, 0),
  109. Point( 1.44*max(m_paintrc.Width (),m_paintrc.Height ()), 1.44*max(m_paintrc.Width (),m_paintrc.Height ())),
  110. Color(255, 255, 250, 156), // opaque blue
  111. Color(255, 176, 125, 44)); // opaque green
  112. graph.FillRectangle(&linGrBrush, m_paintrc.left , m_paintrc.top , m_paintrc.Width (), m_paintrc.Height ());
  113. // dc.FillSolidRect (m_paintrc, RGB(234,208,98));
  114. m_paintrc.DeflateRect (m_slider1, m_slider1, m_slider1, m_slider1);
  115. rc=m_paintrc;
  116. CRect rc2(0,0,m_pImg->GetWidth(), m_pImg->GetHeight());
  117. ::RectFitDes (rc.Width (), rc.Height (), rc2);m_photorcbak=rc2;
  118. if(m_photorc.right==0)
  119. {
  120. m_photorc=rc2;
  121. }
  122. else
  123. {
  124. rc2=m_photorc;
  125. }
  126. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  127. graph.DrawImage(m_pImg, destinationRect, rc2.left , rc2.top , rc2.Width (), rc2.Height (), UnitPixel);
  128. if(m_slider1==0)
  129. dc.Draw3dRect (m_paintrc, RGB(255,0,0), RGB(255,0,0));
  130. ///////////////////
  131. {
  132. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  133. ScreenToClient(rc);
  134. ::RectFitDes (m_pImg->GetWidth(), m_pImg->GetHeight(), rc);
  135. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  136. graph.DrawImage(m_pImg, destinationRect, 0 , 0 , m_pImg->GetWidth(), m_pImg->GetHeight(), UnitPixel);
  137. float scale=(float)rc.Width ()/(float)m_pImg->GetWidth();
  138. rc2.left *=scale;
  139. rc2.right *=scale;
  140. rc2.top *=scale;
  141. rc2.bottom *=scale;
  142. rc2.left +=rc.left ;
  143. rc2.right +=rc.left ;
  144. rc2.top +=rc.top ;
  145. rc2.bottom +=rc.top ;
  146. dc.Draw3dRect (rc2, RGB(255,0,0), RGB(255,0,0));
  147. }
  148. }
  149. // Do not call CDialog::OnPaint() for painting messages
  150. }
  151. void CutPhoto::OnButton7()
  152. {
  153. // TODO: Add your control notification handler code here
  154. SetSize dlg;
  155. dlg.DoModal();GetSize();
  156. }
  157. void CutPhoto::GetSize()
  158. {
  159. g_sendhead.bsql=0;
  160. g_sendhead.code[0]=174;
  161. g_sendhead.tabcount=1;
  162. g_pMainWnd->ProcessChatMessageRequest2(6);
  163. if(g_bSendOK==0)
  164. {
  165. return;
  166. }
  167. DataToArray(&g_List1array);
  168. CenterWindow();
  169. m_combo1.ResetContent ();
  170. namearray.RemoveAll ();
  171. widtharray.RemoveAll ();
  172. heightarray.RemoveAll ();
  173. for(int i=0; i<g_List1array.GetSize (); i++)
  174. {
  175. namearray.Add (g_List1array.ElementAt (i).ElementAt (0));
  176. widtharray.Add (atoi(g_List1array.ElementAt (i).ElementAt (1)));
  177. heightarray.Add (atoi(g_List1array.ElementAt (i).ElementAt (2)));
  178. CString str;
  179. 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)));
  180. m_combo1.AddString(str);
  181. }
  182. if(m_combo1.GetCount ())
  183. {
  184. m_combo1.SetCurSel (0);OnSelchangeCombo1();
  185. }
  186. }
  187. void CutPhoto::OnSelchangeCombo1()
  188. {
  189. // TODO: Add your control notification handler code here
  190. int pos=m_combo1.GetCurSel ();
  191. if(pos==-1)return;
  192. m_photorc.right=0;
  193. m_fscale=1.0;
  194. m_width=widtharray.ElementAt (pos);
  195. m_height=heightarray.ElementAt (pos);
  196. m_name=namearray.ElementAt (pos);
  197. CString header=m_path+":"+m_name+",";
  198. pos=m_size.Find (header);
  199. if(pos!=-1)
  200. {
  201. CString str=m_size.Right (m_size.GetLength ()-pos);
  202. CString size=str.Left (str.Find (";"));
  203. int pos=size.Find (":");
  204. if(pos!=-1)
  205. {
  206. CRect rc,rc2;
  207. str=size.Left (pos);
  208. str=size.Right (size.GetLength ()-pos-1);
  209. pos=str.Find (",");
  210. str.Delete (0, pos+1);
  211. pos=str.Find (",");
  212. rc.left=atoi(str.Left (pos));str.Delete (0, pos+1);
  213. pos=str.Find (",");
  214. rc.top=atoi(str.Left (pos));str.Delete (0, pos+1);
  215. pos=str.Find (",");
  216. rc2.left=atoi(str.Left (pos));str.Delete (0, pos+1);
  217. pos=str.Find (",");
  218. rc2.top=atoi(str.Left (pos));str.Delete (0, pos+1);
  219. pos=str.Find (",");
  220. rc2.right=atoi(str.Left (pos));str.Delete (0, pos+1);
  221. rc2.bottom=atoi(str);
  222. float scale=(float)m_pImg->GetWidth()/(float)rc.left;
  223. rc2.left *=scale;
  224. rc2.right *=scale;
  225. rc2.top *=scale;
  226. rc2.bottom *=scale;
  227. m_photorc=rc2;
  228. }
  229. }
  230. RefreshRc();
  231. // CString ss;
  232. // ss.Format ("%s %d,%d", namearray.ElementAt (pos), widtharray.ElementAt (pos),heightarray.ElementAt (pos));
  233. // AfxMessageBox(ss);
  234. }
  235. void CutPhoto::OnButton1()
  236. {
  237. // TODO: Add your control notification handler code here
  238. if(m_photorc.right==0)return;
  239. int dt=m_photorc.Width ()-m_photorc.Width ()/1.2;
  240. dt/=2;
  241. m_photorc.left +=dt;
  242. m_photorc.right -=dt;
  243. if(m_photorc.left<0)m_photorc.left=0;
  244. if(m_photorc.right>m_photorcbak.right)m_photorc.right=m_photorcbak.right;
  245. dt=m_photorc.Height ()-m_photorc.Height ()/1.2;
  246. dt/=2;
  247. m_photorc.top +=dt;
  248. m_photorc.bottom =m_photorc.top+m_photorc.Width ()*m_photorcbak.Height ()/m_photorcbak.Width ();
  249. if(m_photorc.top<0)m_photorc.top=0;
  250. if(m_photorc.bottom>m_photorcbak.bottom)m_photorc.bottom=m_photorcbak.bottom;
  251. RefreshRc();
  252. }
  253. void CutPhoto::OnButton2()
  254. {
  255. // TODO: Add your control notification handler code here
  256. if(m_photorc.right==0)return;
  257. int dt=m_photorc.Width ()-m_photorc.Width ()*0.8;
  258. dt/=2;
  259. m_photorc.left -=dt;
  260. m_photorc.right +=dt;
  261. if(m_photorc.left<0)m_photorc.left=0;
  262. if(m_photorc.right>m_photorcbak.right)m_photorc.right=m_photorcbak.right;
  263. dt=m_photorc.Height ()-m_photorc.Height ()*0.8;
  264. dt/=2;
  265. m_photorc.top -=dt;
  266. m_photorc.bottom =m_photorc.top+m_photorc.Width ()*m_photorcbak.Height ()/m_photorcbak.Width ();
  267. if(m_photorc.top<0)m_photorc.top=0;
  268. if(m_photorc.bottom>m_photorcbak.bottom)m_photorc.bottom=m_photorcbak.bottom;
  269. RefreshRc();
  270. }
  271. void CutPhoto::OnButton3()
  272. {
  273. // TODO: Add your control notification handler code here
  274. if(m_photorc.right==0)return;
  275. int dt=m_photorcbak.Width ()/50;if(dt<1)dt=1;
  276. if( (m_photorc.right+dt)>(m_pImg->GetWidth()-1) )
  277. dt=m_pImg->GetWidth()-m_photorc.right-1;
  278. m_photorc.left +=dt;
  279. m_photorc.right +=dt;
  280. RefreshRc();
  281. }
  282. void CutPhoto::OnButton4()
  283. {
  284. // TODO: Add your control notification handler code here
  285. if(m_photorc.right==0)return;
  286. int dt=m_photorcbak.Width ()/50;if(dt<1)dt=1;
  287. if( (m_photorc.left-dt)<0 )
  288. dt=m_photorc.left;
  289. m_photorc.left -=dt;
  290. m_photorc.right -=dt;
  291. RefreshRc();
  292. }
  293. void CutPhoto::OnButton5()
  294. {
  295. // TODO: Add your control notification handler code here
  296. // TODO: Add your control notification handler code here
  297. if(m_photorc.right==0)return;
  298. int dt=m_photorcbak.Height ()/50;if(dt<1)dt=1;
  299. if( (m_photorc.bottom+dt)>(m_pImg->GetHeight()-1) )
  300. dt=m_pImg->GetHeight()-m_photorc.bottom-1;
  301. m_photorc.top +=dt;
  302. m_photorc.bottom +=dt;
  303. RefreshRc();
  304. }
  305. void CutPhoto::OnButton6()
  306. {
  307. // TODO: Add your control notification handler code here
  308. if(m_photorc.right==0)return;
  309. int dt=m_photorcbak.Height ()/50;if(dt<1)dt=1;
  310. if( (m_photorc.top-dt)<0 )
  311. dt=m_photorc.top;
  312. m_photorc.top -=dt;
  313. m_photorc.bottom -=dt;
  314. RefreshRc();
  315. }
  316. void CutPhoto::RefreshRc()
  317. {
  318. UpdateData();
  319. CRect rc;
  320. GetDlgItem(IDC_STATIC1)->GetWindowRect(rc);
  321. ScreenToClient(rc);
  322. InvalidateRect(rc);
  323. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  324. ScreenToClient(rc);
  325. InvalidateRect(rc);
  326. }
  327. void CutPhoto::OnButton10()
  328. {
  329. // TODO: Add your control notification handler code here
  330. if(! (m_width && m_height) )
  331. {
  332. AfxMessageBox("请选择尺寸!");
  333. return;
  334. }
  335. CString str;
  336. 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 );
  337. int pos;
  338. CString header=m_path+":"+m_name+",";
  339. pos=m_size.Find (header);
  340. if(pos!=-1)
  341. {
  342. CString left,right;
  343. left=m_size.Left (pos);
  344. m_size=m_size.Right (m_size.GetLength ()-pos-header.GetLength ());
  345. pos=m_size.Find (";");
  346. right=m_size.Right (m_size.GetLength ()-pos-1);
  347. m_size=left+right;
  348. }
  349. m_size+=str;
  350. CString sql;
  351. sql.Format ("update dindan set size='%s' where id='%s'", m_size, m_id);
  352. g_sendhead.bsql=1;
  353. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  354. AfxMessageBox("保存成功!");
  355. // CDialog::OnCancel ();
  356. }
  357. void CutPhoto::OnButton32()
  358. {
  359. // TODO: Add your control notification handler code here
  360. ShowCut dlg;
  361. dlg.m_id =m_id;
  362. dlg.DoModal ();
  363. g_sendhead.bsql=0;
  364. g_sendhead.code[0]=11;
  365. g_sendhead.tabcount=1;
  366. CString filter="id='"+m_id+"';";
  367. g_pMainWnd->ProcessChatMessageRequest2(filter);
  368. if(g_bSendOK==0)
  369. {
  370. CDialog::OnCancel ();
  371. return ;
  372. }
  373. CArray<CStringArray, CStringArray>m_List1array;
  374. DataToArray(&m_List1array);
  375. CenterWindow();
  376. if(m_List1array.GetSize () )
  377. {
  378. m_size= m_List1array.ElementAt (0).ElementAt (60);
  379. }
  380. }
  381. void CutPhoto::OnCustomdrawSlider1(NMHDR* pNMHDR, LRESULT* pResult)
  382. {
  383. // TODO: Add your control notification handler code here
  384. *pResult = 0;
  385. }
  386. void CutPhoto::OnOutofmemorySlider1(NMHDR* pNMHDR, LRESULT* pResult)
  387. {
  388. // TODO: Add your control notification handler code here
  389. *pResult = 0;
  390. }
  391. void CutPhoto::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult)
  392. {
  393. // TODO: Add your control notification handler code here
  394. RefreshRc();
  395. *pResult = 0;
  396. }