123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- // PrintPreview.cpp : implementation file
- //
- #include "stdafx.h"
- #include "LYFZIPManage.h"
- #include "PrintPreview.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // PrintPreview dialog
- PrintPreview::PrintPreview(CWnd* pParent /*=NULL*/)
- : CDialog(PrintPreview::IDD, pParent)
- {
- //{{AFX_DATA_INIT(PrintPreview)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pDC=NULL;
- m_rc.right =0;
- }
- void PrintPreview::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(PrintPreview)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(PrintPreview, CDialog)
- //{{AFX_MSG_MAP(PrintPreview)
- ON_WM_CLOSE()
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
- ON_WM_MOUSEWHEEL()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // PrintPreview message handlers
- void PrintPreview::OnOK()
- {
- // TODO: Add extra validation here
-
- CDialog::OnOK();
- }
- void PrintPreview::OnCancel()
- {
- // TODO: Add extra cleanup here
- }
- void PrintPreview::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
-
- CDialog::OnCancel();
- }
- BOOL PrintPreview::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- DEVMODE dm;
- dm.dmSize = sizeof(DEVMODE) ;
- EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dm);
- ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,dm.dmPelsWidth,dm.dmPelsHeight,SWP_SHOWWINDOW);
- CRect rc,rc2;
- GetClientRect(rc);
- RectFitDes(m_w,m_h, rc);
- GetDlgItem(IDOK)->GetWindowRect(rc2);
- ScreenToClient(rc2);
- int wid=rc2.Width ();
- rc2.right =rc.left -10;
- rc2.left =rc2.right -wid;
- GetDlgItem(IDOK)->MoveWindow(rc2);
- GetDlgItem(IDC_BUTTON1)->GetWindowRect(rc2);
- ScreenToClient(rc2);
- rc2.right =rc.left -10;
- rc2.left =rc2.right -wid;
- GetDlgItem(IDC_BUTTON1)->MoveWindow(rc2);
- GetDlgItem(IDC_BUTTON2)->GetWindowRect(rc2);
- ScreenToClient(rc2);
- rc2.right =rc.left -10;
- rc2.left =rc2.right -wid;
- GetDlgItem(IDC_BUTTON2)->MoveWindow(rc2);
- GetDlgItem(IDC_BUTTON3)->GetWindowRect(rc2);
- ScreenToClient(rc2);
- rc2.right =rc.left -10;
- rc2.left =rc2.right -wid;
- GetDlgItem(IDC_BUTTON3)->MoveWindow(rc2);
- GetDlgItem(IDC_BUTTON4)->GetWindowRect(rc2);
- ScreenToClient(rc2);
- rc2.right =rc.left -10;
- rc2.left =rc2.right -wid;
- GetDlgItem(IDC_BUTTON4)->MoveWindow(rc2);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void PrintPreview::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- if(m_pDC)
- {
- CRect rc;
- GetClientRect(rc);
- if(m_rc.right ==0)
- {
- m_rc=rc;
- //////////
- float fscale=(float)m_w/(float)m_h;
- float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
- int rcwid=m_rc.Width ();
- int rchei=m_rc.Height ();
- int dt=0;
- if(rcscale<fscale)
- {
- dt=(rchei-rcwid/fscale)/2;
- m_rc.top+=dt;
- m_rc.bottom-=dt;
- }
- else
- {
- dt=(rcwid-rchei*fscale)/2;
- m_rc.left +=dt;
- m_rc.right-=dt;
- }
- }
-
- dc.StretchBlt (m_rc.left ,m_rc.top ,m_rc.Width (), m_rc.Height (), m_pDC, 0, 0, m_w,m_h, SRCCOPY);
- }
- // Do not call CDialog::OnPaint() for painting messages
- }
- void PrintPreview::OnButton1()
- {
- // TODO: Add your control notification handler code here
- CDialog::OnCancel ();
- }
- void PrintPreview::OnButton2()
- {
- // TODO: Add your control notification handler code here
- CRect *pRc=&m_rc;
- int dtx;
- int dty;
- dtx=pRc->Width ()*0.1;
- dty=pRc->Height ()*0.1;
- pRc->left -= dtx;
- pRc->right += dtx;
- pRc->top -= dty;
-
- pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
- Invalidate();
- }
- void PrintPreview::OnButton3()
- {
- // TODO: Add your control notification handler code here
- CRect *pRc=&m_rc;
- int dtx;
- int dty;
- dtx=pRc->Width ()*0.1;
- dty=pRc->Height ()*0.1;
- if(dtx<10 || dty<10)return;
-
- pRc->left += dtx;
- pRc->right -= dtx;
- pRc->top += dty;
- pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
- Invalidate();
- }
- BOOL PrintPreview::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
- {
- // TODO: Add your message handler code here and/or call default
- if(zDelta>0)
- {
- CRect *pRc=&m_rc;
- int dtx;
- int dty;
- dtx=pRc->Width ()*0.1;
- dty=pRc->Height ()*0.1;
- pRc->left -= dtx;
- pRc->right += dtx;
- pRc->top -= dty;
- pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
- Invalidate();
- }
- else
- {
- CRect *pRc=&m_rc;
- int dtx;
- int dty;
- dtx=pRc->Width ()*0.1;
- dty=pRc->Height ()*0.1;
- if(dtx<10 || dty<10)return 1;
-
- pRc->left += dtx;
- pRc->right -= dtx;
- pRc->top += dty;
- pRc->bottom = pRc->top+pRc->Width ()*(m_h)/(m_w);
- Invalidate();
- }
- return CDialog::OnMouseWheel(nFlags, zDelta, pt);
- }
- void PrintPreview::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- SetCapture();
- m_startpt=point;
- CDialog::OnLButtonDown(nFlags, point);
- }
- void PrintPreview::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(GetCapture()!=this)return;
- ReleaseCapture();
- m_rc.left +=point.x-m_startpt.x;
- m_rc.right +=point.x-m_startpt.x;
- m_rc.top +=point.y-m_startpt.y;
- m_rc.bottom +=point.y-m_startpt.y;
- m_startpt=point;
- Invalidate();
- CDialog::OnLButtonUp(nFlags, point);
- }
- void PrintPreview::OnButton4()
- {
- // TODO: Add your control notification handler code here
- m_rc.right =0;
- Invalidate();
- }
|