PrintPreview.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. // PrintPreview.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "PrintPreview.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // PrintPreview dialog IDC_RADIO4
  8. PrintPreview::PrintPreview(CWnd* pParent /*=NULL*/)
  9. : CDialog(PrintPreview::IDD, pParent)
  10. {
  11. //{{AFX_DATA_INIT(PrintPreview)
  12. m_num = 1;
  13. //}}AFX_DATA_INIT
  14. m_pDC=NULL;
  15. m_rc.right =0;
  16. m_mode=0;
  17. m_ncopies=1;
  18. }
  19. void PrintPreview::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(PrintPreview)
  23. DDX_Control(pDX, IDC_SPIN1, m_spin);
  24. DDX_Radio(pDX, IDC_RADIO1, m_radio1);
  25. DDX_Text(pDX, IDC_EDIT3, m_num);
  26. DDV_MinMaxUInt(pDX, m_num, 1, 10);
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(PrintPreview, CDialog)
  30. //{{AFX_MSG_MAP(PrintPreview)
  31. ON_WM_CLOSE()
  32. ON_WM_PAINT()
  33. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  34. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  35. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  36. ON_WM_MOUSEWHEEL()
  37. ON_WM_LBUTTONDOWN()
  38. ON_WM_LBUTTONUP()
  39. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  40. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  41. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  42. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  43. ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
  44. ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // PrintPreview message handlers
  49. void PrintPreview::OnOK()
  50. {
  51. // TODO: Add extra validation here
  52. CDialog::OnOK();
  53. }
  54. void PrintPreview::OnCancel()
  55. {
  56. // TODO: Add extra cleanup here
  57. }
  58. void PrintPreview::OnClose()
  59. {
  60. // TODO: Add your message handler code here and/or call default
  61. CDialog::OnCancel();
  62. }
  63. BOOL PrintPreview::OnInitDialog()
  64. {
  65. CDialog::OnInitDialog();
  66. // TODO: Add extra initialization here
  67. DEVMODE dm;
  68. dm.dmSize = sizeof(DEVMODE) ;
  69. EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dm);
  70. ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,dm.dmPelsWidth,dm.dmPelsHeight,SWP_SHOWWINDOW);
  71. if(m_mode!=1)GetDlgItem(IDC_RADIO4)->ShowWindow(0);
  72. if(m_mode==0 || IsHasRights2new(49)==0)
  73. {
  74. GetDlgItem(IDC_RADIO1)->ShowWindow(0);
  75. GetDlgItem(IDC_RADIO2)->ShowWindow(0);
  76. GetDlgItem(IDC_RADIO3)->ShowWindow(0);
  77. }
  78. if(m_mode==2)GetDlgItem(IDC_RADIO3)->ShowWindow(0);
  79. if(m_mode==3)GetDlgItem(IDC_RADIO3)->ShowWindow(0);
  80. m_spin.SetRange(1, 10);
  81. #ifndef CHILD_VERSION
  82. GetDlgItem(IDC_RADIO3)->ShowWindow(0);
  83. #endif
  84. CRect rc,rc2;
  85. GetClientRect(rc);
  86. RectFitDes(m_w,m_h, rc);
  87. if(1)//m_w<m_h)
  88. {
  89. GetDlgItem(IDOK)->GetWindowRect(rc2);
  90. ScreenToClient(rc2);
  91. int wid=rc2.Width ();
  92. rc2.right =rc.left -10;
  93. rc2.left =rc2.right -wid;
  94. GetDlgItem(IDOK)->MoveWindow(rc2);
  95. GetDlgItem(IDC_BUTTON1)->GetWindowRect(rc2);
  96. ScreenToClient(rc2);
  97. rc2.right =rc.left -10;
  98. rc2.left =rc2.right -wid;
  99. GetDlgItem(IDC_BUTTON1)->MoveWindow(rc2);
  100. GetDlgItem(IDC_BUTTON2)->GetWindowRect(rc2);
  101. ScreenToClient(rc2);
  102. rc2.right =rc.left -10;
  103. rc2.left =rc2.right -wid;
  104. GetDlgItem(IDC_BUTTON2)->MoveWindow(rc2);
  105. GetDlgItem(IDC_BUTTON3)->GetWindowRect(rc2);
  106. ScreenToClient(rc2);
  107. rc2.right =rc.left -10;
  108. rc2.left =rc2.right -wid;
  109. GetDlgItem(IDC_BUTTON3)->MoveWindow(rc2);
  110. GetDlgItem(IDC_BUTTON4)->GetWindowRect(rc2);
  111. ScreenToClient(rc2);
  112. rc2.right =rc.left -10;
  113. rc2.left =rc2.right -wid;
  114. GetDlgItem(IDC_BUTTON4)->MoveWindow(rc2);
  115. GetDlgItem(IDC_BUTTON5)->GetWindowRect(rc2);
  116. ScreenToClient(rc2);
  117. rc2.right =rc.left -10;
  118. rc2.left =rc2.right -wid;
  119. GetDlgItem(IDC_BUTTON5)->MoveWindow(rc2);
  120. GetDlgItem(IDC_RADIO1)->GetWindowRect(rc2);
  121. ScreenToClient(rc2);
  122. rc2.right =rc.left -10;
  123. rc2.left =rc2.right -wid;
  124. GetDlgItem(IDC_RADIO1)->MoveWindow(rc2);
  125. GetDlgItem(IDC_RADIO2)->GetWindowRect(rc2);
  126. ScreenToClient(rc2);
  127. rc2.right =rc.left -10;
  128. rc2.left =rc2.right -wid;
  129. GetDlgItem(IDC_RADIO2)->MoveWindow(rc2);
  130. GetDlgItem(IDC_RADIO3)->GetWindowRect(rc2);
  131. ScreenToClient(rc2);
  132. rc2.right =rc.left -10;
  133. rc2.left =rc2.right -wid;
  134. GetDlgItem(IDC_RADIO3)->MoveWindow(rc2);
  135. GetDlgItem(IDC_RADIO4)->GetWindowRect(rc2);
  136. ScreenToClient(rc2);
  137. rc2.right =rc.left -10;
  138. rc2.left =rc2.right -wid;
  139. GetDlgItem(IDC_RADIO4)->MoveWindow(rc2);
  140. GetDlgItem(IDC_STATIC1)->GetWindowRect(rc2);
  141. ScreenToClient(rc2);
  142. int wid2=rc2.Width();
  143. rc2.left =rc.left -10 -wid;
  144. rc2.right=rc2.left+wid2;
  145. GetDlgItem(IDC_STATIC1)->MoveWindow(rc2);
  146. m_spin.GetWindowRect(rc2);
  147. int wid3=rc2.Width();
  148. GetDlgItem(IDC_EDIT3)->GetWindowRect(rc2);
  149. ScreenToClient(rc2);
  150. wid2=rc2.Width();
  151. rc2.right =rc.left -10-wid3;
  152. rc2.left=rc2.right-wid2;
  153. GetDlgItem(IDC_EDIT3)->MoveWindow(rc2);
  154. rc2.left=rc2.right;
  155. rc2.right=rc2.left+wid3;
  156. m_spin.MoveWindow(rc2);
  157. }
  158. else
  159. {
  160. GetDlgItem(IDOK)->GetWindowRect(rc2);
  161. ScreenToClient(rc2);
  162. int hei=rc2.Height ();
  163. rc2.bottom =rc.top -10;
  164. rc2.top =rc2.bottom -hei;
  165. GetDlgItem(IDOK)->MoveWindow(rc2);
  166. int wid=rc2.Width ()+10;
  167. rc2.left +=wid;
  168. rc2.right +=wid;
  169. GetDlgItem(IDC_BUTTON1)->MoveWindow(rc2);
  170. rc2.left +=wid;
  171. rc2.right +=wid;
  172. GetDlgItem(IDC_BUTTON2)->MoveWindow(rc2);
  173. rc2.left +=wid;
  174. rc2.right +=wid;
  175. GetDlgItem(IDC_BUTTON3)->MoveWindow(rc2);
  176. rc2.left +=wid;
  177. rc2.right +=wid;
  178. GetDlgItem(IDC_BUTTON4)->MoveWindow(rc2);
  179. rc2.left +=wid;
  180. rc2.right +=wid;
  181. GetDlgItem(IDC_BUTTON5)->MoveWindow(rc2);
  182. }
  183. if(m_mode==1)
  184. m_radio1 = atoi(g_cominfoarray.ElementAt(0).ElementAt(66));
  185. else if(m_mode==2)
  186. m_radio1 = atoi(g_cominfoarray.ElementAt(0).ElementAt(75));
  187. else if(m_mode==3)
  188. m_radio1 = atoi(g_cominfoarray.ElementAt(0).ElementAt(87));
  189. UpdateData(false);
  190. return TRUE; // return TRUE unless you set the focus to a control
  191. // EXCEPTION: OCX Property Pages should return FALSE
  192. }
  193. void PrintPreview::OnPaint()
  194. {
  195. CPaintDC dc(this); // device context for painting
  196. // TODO: Add your message handler code here
  197. if(m_pDC)
  198. {
  199. CRect rc;
  200. GetClientRect(rc);
  201. if(m_rc.right ==0)
  202. {
  203. m_rc=rc;
  204. //////////
  205. float fscale=(float)m_w/(float)m_h;
  206. float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
  207. int rcwid=m_rc.Width ();
  208. int rchei=m_rc.Height ();
  209. int dt=0;
  210. if(rcscale<fscale)
  211. {
  212. dt=(rchei-rcwid/fscale)/2;
  213. m_rc.top+=dt;
  214. m_rc.bottom-=dt;
  215. }
  216. else
  217. {
  218. dt=(rcwid-rchei*fscale)/2;
  219. m_rc.left +=dt;
  220. m_rc.right-=dt;
  221. }
  222. }
  223. dc.StretchBlt (m_rc.left ,m_rc.top ,m_rc.Width (), m_rc.Height (), m_pDC, 0, 0, m_w,m_h, SRCCOPY);
  224. }
  225. // Do not call CDialog::OnPaint() for painting messages
  226. }
  227. void PrintPreview::OnButton1()
  228. {
  229. // TODO: Add your control notification handler code here
  230. CDialog::OnCancel ();
  231. }
  232. void PrintPreview::OnButton2()
  233. {
  234. // TODO: Add your control notification handler code here
  235. CRect *pRc=&m_rc;
  236. int dtx;
  237. int dty;
  238. dtx=pRc->Width ()*0.1;
  239. dty=pRc->Height ()*0.1;
  240. pRc->left -= dtx;
  241. pRc->right += dtx;
  242. pRc->top -= dty;
  243. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  244. Invalidate();
  245. }
  246. void PrintPreview::OnButton3()
  247. {
  248. // TODO: Add your control notification handler code here
  249. CRect *pRc=&m_rc;
  250. int dtx;
  251. int dty;
  252. dtx=pRc->Width ()*0.1;
  253. dty=pRc->Height ()*0.1;
  254. if(dtx<10 || dty<10)return;
  255. pRc->left += dtx;
  256. pRc->right -= dtx;
  257. pRc->top += dty;
  258. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  259. Invalidate();
  260. }
  261. BOOL PrintPreview::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  262. {
  263. // TODO: Add your message handler code here and/or call default
  264. if(zDelta>0)
  265. {
  266. CRect *pRc=&m_rc;
  267. int dtx;
  268. int dty;
  269. dtx=pRc->Width ()*0.1;
  270. dty=pRc->Height ()*0.1;
  271. pRc->left -= dtx;
  272. pRc->right += dtx;
  273. pRc->top -= dty;
  274. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  275. Invalidate();
  276. }
  277. else
  278. {
  279. CRect *pRc=&m_rc;
  280. int dtx;
  281. int dty;
  282. dtx=pRc->Width ()*0.1;
  283. dty=pRc->Height ()*0.1;
  284. if(dtx<10 || dty<10)return 1;
  285. pRc->left += dtx;
  286. pRc->right -= dtx;
  287. pRc->top += dty;
  288. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  289. Invalidate();
  290. }
  291. return CDialog::OnMouseWheel(nFlags, zDelta, pt);
  292. }
  293. void PrintPreview::OnLButtonDown(UINT nFlags, CPoint point)
  294. {
  295. // TODO: Add your message handler code here and/or call default
  296. SetCapture();
  297. m_startpt=point;
  298. CDialog::OnLButtonDown(nFlags, point);
  299. }
  300. void PrintPreview::OnLButtonUp(UINT nFlags, CPoint point)
  301. {
  302. // TODO: Add your message handler code here and/or call default
  303. if(GetCapture()!=this)return;
  304. ReleaseCapture();
  305. m_rc.left +=point.x-m_startpt.x;
  306. m_rc.right +=point.x-m_startpt.x;
  307. m_rc.top +=point.y-m_startpt.y;
  308. m_rc.bottom +=point.y-m_startpt.y;
  309. m_startpt=point;
  310. Invalidate();
  311. CDialog::OnLButtonUp(nFlags, point);
  312. }
  313. void PrintPreview::OnButton4()
  314. {
  315. // TODO: Add your control notification handler code here
  316. m_rc.right =0;
  317. Invalidate();
  318. }
  319. void PrintPreview::OnButton5()
  320. {
  321. // TODO: Add your control notification handler code here
  322. CFileDialog fdlg(false, _T(".jpg"), m_name+_T("制作单.jpg"), OFN_HIDEREADONLY, "图片文件(*.jpg)|*.jpg||", this);
  323. if(fdlg.DoModal ()!=IDOK)return;
  324. CString path=fdlg.GetPathName ();
  325. if(m_pDC==NULL)return;
  326. Bitmap *pBmp=new Bitmap(m_w,m_h, PixelFormat24bppRGB );
  327. Graphics graph(pBmp);
  328. HDC hdc=graph.GetHDC();
  329. ::BitBlt (hdc, 0, 0, m_w,m_h, m_pDC->GetSafeHdc (), 0,0, SRCCOPY);
  330. graph.ReleaseHDC(hdc);
  331. ::SaveImageToFile (pBmp, path);
  332. delete pBmp;
  333. }
  334. void PrintPreview::OnRadio1()
  335. {
  336. // TODO: Add your control notification handler code here
  337. UpdateData();
  338. if(m_mode==1)
  339. {
  340. CString sql;
  341. sql.Format ("update version set [setprintstyle]='%d'", m_radio1);
  342. g_sendhead.bsql=1;
  343. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  344. AfxMessageBox("保存成功! 重新进入打印页面时生效!", MB_ICONINFORMATION);
  345. CString str;
  346. str.Format ("%d", m_radio1);
  347. g_cominfoarray.ElementAt(0).SetAt (66, str);
  348. }
  349. else if(m_mode==2)
  350. {
  351. CString sql;
  352. sql.Format ("update version set [setprintstyle2]='%d'", m_radio1);
  353. g_sendhead.bsql=1;
  354. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  355. AfxMessageBox("保存成功! 重新进入打印页面时生效!", MB_ICONINFORMATION);
  356. CString str;
  357. str.Format ("%d", m_radio1);
  358. g_cominfoarray.ElementAt(0).SetAt (75, str);
  359. }
  360. else if(m_mode==3)
  361. {
  362. CString sql;
  363. sql.Format ("update version set [setprintstyle3]='%d'", m_radio1);
  364. g_sendhead.bsql=1;
  365. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  366. AfxMessageBox("保存成功! 重新进入打印页面时生效!", MB_ICONINFORMATION);
  367. CString str;
  368. str.Format ("%d", m_radio1);
  369. g_cominfoarray.ElementAt(0).SetAt (87, str);
  370. }
  371. }
  372. void PrintPreview::OnRadio2()
  373. {
  374. // TODO: Add your control notification handler code here
  375. OnRadio1();
  376. }
  377. void PrintPreview::OnRadio3()
  378. {
  379. // TODO: Add your control notification handler code here
  380. OnRadio1();
  381. }
  382. void PrintPreview::OnRadio4()
  383. {
  384. // TODO: Add your control notification handler code here
  385. OnRadio1();
  386. }