📄 adjustsizedlg.cpp
字号:
// AdjustSizeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "picviewer.h"
#include "AdjustSizeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAdjustSizeDlg dialog
CAdjustSizeDlg::CAdjustSizeDlg(CWnd* pParent, FCDibEffect * dib)
: CDialog(CAdjustSizeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAdjustSizeDlg)
//}}AFX_DATA_INIT
m_pOriDib = dib ;
FCImage bk ;
bk.LoadJpeg (MAKEINTRESOURCE (JPG_BACKGROUND), _T("JPG")) ;
m_BkBrush = ::CreatePatternBrush (bk.GetHandle ()) ;
}
CAdjustSizeDlg::~CAdjustSizeDlg ()
{
::DeleteObject (m_BkBrush) ;
}
void CAdjustSizeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAdjustSizeDlg)
DDX_Control(pDX, IDC_SIZE_RATIO, m_btRatio);
DDX_Control(pDX, IDC_EDIT_WIDTH, m_editPerWidth);
DDX_Control(pDX, IDC_SIZE_WIDTH, m_staShowWidth);
DDX_Control(pDX, IDC_SIZE_HEIGHT, m_staShowHeight);
DDX_Control(pDX, IDC_SCROLLBAR_WIDTH, m_sbarWidth);
DDX_Control(pDX, IDC_SCROLLBAR_HEIGHT, m_sbarHeight);
DDX_Control(pDX, IDC_EDIT_HEIGHT, m_editPerHeight);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAdjustSizeDlg, CDialog)
//{{AFX_MSG_MAP(CAdjustSizeDlg)
ON_WM_CTLCOLOR()
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_SIZE_RATIO, OnSizeRatio)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdjustSizeDlg message handlers
HBRUSH CAdjustSizeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if ((nCtlColor == CTLCOLOR_DLG) || (nCtlColor == CTLCOLOR_STATIC))
{
pDC->SetBkMode (TRANSPARENT) ;
hbr = m_BkBrush ;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
BOOL CAdjustSizeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_sbarHeight.SetScrollRange (4, m_pOriDib->Height()*2, FALSE) ;
m_sbarHeight.SetScrollPos (m_pOriDib->Height(), FALSE) ;
CString num ;
num.Format (_T("%i"), m_pOriDib->Height()) ;
m_staShowHeight.SetWindowText (num) ;
m_editPerHeight.SetWindowText (_T("100")) ;
m_sbarWidth.SetScrollRange (4, m_pOriDib->Width()*2, FALSE) ;
m_sbarWidth.SetScrollPos (m_pOriDib->Width(), FALSE) ;
num.Format (_T("%i"), m_pOriDib->Width()) ;
m_staShowWidth.SetWindowText (num) ;
m_editPerWidth.SetWindowText (_T("100")) ;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAdjustSizeDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// Get Current Position
if ((nSBCode != SB_THUMBPOSITION) && (nSBCode != SB_THUMBTRACK))
nPos = pScrollBar->GetScrollPos () ;
switch (nSBCode)
{
case SB_LINELEFT :
nPos-- ; break ;
case SB_LINERIGHT :
nPos++ ; break ;
case SB_PAGELEFT :
nPos -= 5 ; break ;
case SB_PAGERIGHT :
nPos += 5 ; break ;
}
nPos = max (nPos, 4) ;
CString num ;
switch (pScrollBar->GetDlgCtrlID ())
{
case IDC_SCROLLBAR_HEIGHT :
nPos = min (nPos, m_pOriDib->Height()*2) ;
if (this->m_btRatio.GetCheck () == 1)
{
UINT nRatio = nPos*100 / m_pOriDib->Height() ;
num.Format ("%i", nRatio) ;
m_editPerHeight.SetWindowText (num) ;
m_editPerWidth.SetWindowText (num) ;
UINT nNewWth = m_pOriDib->Width() * nRatio / 100 ;
nNewWth = min (max (nNewWth, 4), m_pOriDib->Width()*2) ;
m_sbarWidth.SetScrollPos (nNewWth) ;
num.Format ("%i", nNewWth) ;
m_staShowWidth.SetWindowText (num) ;
num.Format ("%i", nPos) ;
m_staShowHeight.SetWindowText (num) ;
}
else
{
num.Format ("%i", nPos) ;
m_staShowHeight.SetWindowText (num) ;
num.Format ("%i", nPos*100 / m_pOriDib->Height()) ;
m_editPerHeight.SetWindowText (num) ;
}
break ;
case IDC_SCROLLBAR_WIDTH :
nPos = min (nPos, m_pOriDib->Width()*2) ;
if (this->m_btRatio.GetCheck () == 1)
{
UINT nRatio = nPos*100 / m_pOriDib->Width() ;
num.Format ("%i", nRatio) ;
m_editPerHeight.SetWindowText (num) ;
m_editPerWidth.SetWindowText (num) ;
UINT nNewHgt = m_pOriDib->Height() * nRatio / 100 ;
nNewHgt = min (max (nNewHgt, 4), m_pOriDib->Height()*2) ;
m_sbarHeight.SetScrollPos (nNewHgt) ;
num.Format ("%i", nNewHgt) ;
m_staShowHeight.SetWindowText (num) ;
num.Format ("%i", nPos) ;
m_staShowWidth.SetWindowText (num) ;
}
else
{
num.Format ("%i", nPos) ;
m_staShowWidth.SetWindowText (num) ;
num.Format ("%i", nPos*100 / m_pOriDib->Width()) ;
m_editPerWidth.SetWindowText (num) ;
}
break ;
}
pScrollBar->SetScrollPos (nPos) ;
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CAdjustSizeDlg::OnSizeRatio()
{
// TODO: Add your control notification handler code here
if (this->m_btRatio.GetCheck () == 1)
this->SendMessage (WM_HSCROLL, (WPARAM)MAKELONG(SB_THUMBPOSITION, m_sbarWidth.GetScrollPos()), (LPARAM)m_sbarWidth.GetSafeHwnd()) ;
}
void CAdjustSizeDlg::OnOK()
{
// TODO: Add extra validation here
if ((m_sbarWidth.GetScrollPos() != m_pOriDib->Width()) || (m_sbarHeight.GetScrollPos() != m_pOriDib->Height()))
m_pOriDib->Stretch (m_sbarWidth.GetScrollPos(),
m_sbarHeight.GetScrollPos(),
(m_btRatio.GetCheck() == 1)) ;
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -