PrintPreview.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // PrintPreview.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZIPManage.h"
  5. #include "PrintPreview.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // PrintPreview dialog
  13. PrintPreview::PrintPreview(CWnd* pParent /*=NULL*/)
  14. : CDialog(PrintPreview::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(PrintPreview)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. m_pDC=NULL;
  20. m_rc.right =0;
  21. }
  22. void PrintPreview::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(PrintPreview)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  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. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // PrintPreview message handlers
  44. void PrintPreview::OnOK()
  45. {
  46. // TODO: Add extra validation here
  47. CDialog::OnOK();
  48. }
  49. void PrintPreview::OnCancel()
  50. {
  51. // TODO: Add extra cleanup here
  52. }
  53. void PrintPreview::OnClose()
  54. {
  55. // TODO: Add your message handler code here and/or call default
  56. CDialog::OnCancel();
  57. }
  58. BOOL PrintPreview::OnInitDialog()
  59. {
  60. CDialog::OnInitDialog();
  61. // TODO: Add extra initialization here
  62. DEVMODE dm;
  63. dm.dmSize = sizeof(DEVMODE) ;
  64. EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dm);
  65. ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,dm.dmPelsWidth,dm.dmPelsHeight,SWP_SHOWWINDOW);
  66. CRect rc,rc2;
  67. GetClientRect(rc);
  68. RectFitDes(m_w,m_h, rc);
  69. GetDlgItem(IDOK)->GetWindowRect(rc2);
  70. ScreenToClient(rc2);
  71. int wid=rc2.Width ();
  72. rc2.right =rc.left -10;
  73. rc2.left =rc2.right -wid;
  74. GetDlgItem(IDOK)->MoveWindow(rc2);
  75. GetDlgItem(IDC_BUTTON1)->GetWindowRect(rc2);
  76. ScreenToClient(rc2);
  77. rc2.right =rc.left -10;
  78. rc2.left =rc2.right -wid;
  79. GetDlgItem(IDC_BUTTON1)->MoveWindow(rc2);
  80. GetDlgItem(IDC_BUTTON2)->GetWindowRect(rc2);
  81. ScreenToClient(rc2);
  82. rc2.right =rc.left -10;
  83. rc2.left =rc2.right -wid;
  84. GetDlgItem(IDC_BUTTON2)->MoveWindow(rc2);
  85. GetDlgItem(IDC_BUTTON3)->GetWindowRect(rc2);
  86. ScreenToClient(rc2);
  87. rc2.right =rc.left -10;
  88. rc2.left =rc2.right -wid;
  89. GetDlgItem(IDC_BUTTON3)->MoveWindow(rc2);
  90. GetDlgItem(IDC_BUTTON4)->GetWindowRect(rc2);
  91. ScreenToClient(rc2);
  92. rc2.right =rc.left -10;
  93. rc2.left =rc2.right -wid;
  94. GetDlgItem(IDC_BUTTON4)->MoveWindow(rc2);
  95. return TRUE; // return TRUE unless you set the focus to a control
  96. // EXCEPTION: OCX Property Pages should return FALSE
  97. }
  98. void PrintPreview::OnPaint()
  99. {
  100. CPaintDC dc(this); // device context for painting
  101. // TODO: Add your message handler code here
  102. if(m_pDC)
  103. {
  104. CRect rc;
  105. GetClientRect(rc);
  106. if(m_rc.right ==0)
  107. {
  108. m_rc=rc;
  109. //////////
  110. float fscale=(float)m_w/(float)m_h;
  111. float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
  112. int rcwid=m_rc.Width ();
  113. int rchei=m_rc.Height ();
  114. int dt=0;
  115. if(rcscale<fscale)
  116. {
  117. dt=(rchei-rcwid/fscale)/2;
  118. m_rc.top+=dt;
  119. m_rc.bottom-=dt;
  120. }
  121. else
  122. {
  123. dt=(rcwid-rchei*fscale)/2;
  124. m_rc.left +=dt;
  125. m_rc.right-=dt;
  126. }
  127. }
  128. dc.StretchBlt (m_rc.left ,m_rc.top ,m_rc.Width (), m_rc.Height (), m_pDC, 0, 0, m_w,m_h, SRCCOPY);
  129. }
  130. // Do not call CDialog::OnPaint() for painting messages
  131. }
  132. void PrintPreview::OnButton1()
  133. {
  134. // TODO: Add your control notification handler code here
  135. CDialog::OnCancel ();
  136. }
  137. void PrintPreview::OnButton2()
  138. {
  139. // TODO: Add your control notification handler code here
  140. CRect *pRc=&m_rc;
  141. int dtx;
  142. int dty;
  143. dtx=pRc->Width ()*0.1;
  144. dty=pRc->Height ()*0.1;
  145. pRc->left -= dtx;
  146. pRc->right += dtx;
  147. pRc->top -= dty;
  148. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  149. Invalidate();
  150. }
  151. void PrintPreview::OnButton3()
  152. {
  153. // TODO: Add your control notification handler code here
  154. CRect *pRc=&m_rc;
  155. int dtx;
  156. int dty;
  157. dtx=pRc->Width ()*0.1;
  158. dty=pRc->Height ()*0.1;
  159. if(dtx<10 || dty<10)return;
  160. pRc->left += dtx;
  161. pRc->right -= dtx;
  162. pRc->top += dty;
  163. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  164. Invalidate();
  165. }
  166. BOOL PrintPreview::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  167. {
  168. // TODO: Add your message handler code here and/or call default
  169. if(zDelta>0)
  170. {
  171. CRect *pRc=&m_rc;
  172. int dtx;
  173. int dty;
  174. dtx=pRc->Width ()*0.1;
  175. dty=pRc->Height ()*0.1;
  176. pRc->left -= dtx;
  177. pRc->right += dtx;
  178. pRc->top -= dty;
  179. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  180. Invalidate();
  181. }
  182. else
  183. {
  184. CRect *pRc=&m_rc;
  185. int dtx;
  186. int dty;
  187. dtx=pRc->Width ()*0.1;
  188. dty=pRc->Height ()*0.1;
  189. if(dtx<10 || dty<10)return 1;
  190. pRc->left += dtx;
  191. pRc->right -= dtx;
  192. pRc->top += dty;
  193. pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
  194. Invalidate();
  195. }
  196. return CDialog::OnMouseWheel(nFlags, zDelta, pt);
  197. }
  198. void PrintPreview::OnLButtonDown(UINT nFlags, CPoint point)
  199. {
  200. // TODO: Add your message handler code here and/or call default
  201. SetCapture();
  202. m_startpt=point;
  203. CDialog::OnLButtonDown(nFlags, point);
  204. }
  205. void PrintPreview::OnLButtonUp(UINT nFlags, CPoint point)
  206. {
  207. // TODO: Add your message handler code here and/or call default
  208. if(GetCapture()!=this)return;
  209. ReleaseCapture();
  210. m_rc.left +=point.x-m_startpt.x;
  211. m_rc.right +=point.x-m_startpt.x;
  212. m_rc.top +=point.y-m_startpt.y;
  213. m_rc.bottom +=point.y-m_startpt.y;
  214. m_startpt=point;
  215. Invalidate();
  216. CDialog::OnLButtonUp(nFlags, point);
  217. }
  218. void PrintPreview::OnButton4()
  219. {
  220. // TODO: Add your control notification handler code here
  221. m_rc.right =0;
  222. Invalidate();
  223. }