www.pudn.com > src.rar > AskCharDlg.cpp
// AskCharDlg.cpp : implementation file
//
#include "stdafx.h"
#include "subresync.h"
#include "AskCharDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAskCharDlg dialog
CAskCharDlg::CAskCharDlg(bool fCanUndoExtend, bool fCanBeExtended, CPoint subpicpos,
CDC& dc, CBitmap& bm, CRect rect,
CString preview, CString suggested,
CWnd* pParent /*=NULL*/)
: CDialog(CAskCharDlg::IDD, pParent), m_dc(dc), m_bm(bm), m_rect(rect)
{
//{{AFX_DATA_INIT(CAskCharDlg)
m_str = _T("");
m_preview = _T("");
//}}AFX_DATA_INIT
m_fCanUndoExtend = fCanUndoExtend;
m_fCanBeExtended = fCanBeExtended;
m_subpicpos = subpicpos;
m_str = suggested;
m_preview = preview.Mid(preview.ReverseFind('\n')+1);
}
void CAskCharDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAskCharDlg)
DDX_Control(pDX, IDC_UNDOEXTEND, m_undoextend);
DDX_Control(pDX, IDC_EXTEND, m_extend);
DDX_Control(pDX, IDOK, m_ok);
DDX_Control(pDX, IDC_EDIT1, m_edit);
DDX_Text(pDX, IDC_EDIT1, m_str);
DDX_Text(pDX, IDC_EDIT2, m_preview);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAskCharDlg, CDialog)
//{{AFX_MSG_MAP(CAskCharDlg)
ON_BN_CLICKED(IDC_EXTEND, OnExtend)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_UNDOEXTEND, OnUndoextend)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAskCharDlg message handlers
BOOL CAskCharDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CFont* f = m_edit.GetFont();
LOGFONT lf;
f->GetLogFont(&lf);
lf.lfHeight = -32;
lf.lfWidth = 0;
m_font.CreateFontIndirect(&lf);
m_edit.SetFont(&m_font);
m_edit.SetFocus();
if(!m_str.IsEmpty()) m_edit.SetSel(0, -1);
else m_ok.SetWindowText(ResStr(IDS_SKIP));
m_undoextend.EnableWindow(m_fCanUndoExtend);
m_extend.EnableWindow(m_fCanBeExtended);
CRect r;
GetWindowRect(&r);
int w = r.Width();
int h = r.Height();
r.left = m_subpicpos.x;
r.right = r.left + w;
r.bottom = m_subpicpos.y - 10;
r.top = r.bottom - h;
MoveWindow(r);
CRect rect;
GetWindowRect(&rect);
m_orgwin = rect.Size();
GetClientRect(&rect);
m_orgcli = rect.Size();
/*
BITMAP bm;
m_bm.GetBitmap(&bm);
*/
GetWindowRect(&rect);
rect.right = rect.left + m_orgwin.cx + m_orgcli.cy * m_rect.Width() / m_rect.Height();
CRect desktoprect;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &desktoprect, 0);
// ::GetWindowRect(::GetDesktopWindow(), &desktoprect);
if(rect.bottom > desktoprect.bottom - 20) rect += CPoint(0, (desktoprect.bottom - 20) - rect.bottom);
if(rect.right > desktoprect.right - 20) rect += CPoint((desktoprect.right - 20) - rect.right);
MoveWindow(&rect);
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAskCharDlg::OnExtend()
{
EndDialog(IDC_EXTEND);
}
void CAskCharDlg::OnUndoextend()
{
EndDialog(IDC_UNDOEXTEND);
}
void CAskCharDlg::OnChangeEdit1()
{
UpdateData();
m_ok.SetWindowText(ResStr(m_str.GetLength() > 0 ? IDS_ADD : IDS_SKIP));
}
void CAskCharDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
/*
BITMAP bm;
m_bm.GetBitmap(&bm);
*/
int x = m_orgcli.cx;
int y = 0;
int cx = m_orgcli.cy * m_rect.Width() / m_rect.Height();
int cy = m_orgcli.cy;
CBitmap* oldbm = m_dc.SelectObject(&m_bm);
dc.StretchBlt(x, y, cx, cy,
&m_dc,
m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
SRCCOPY);
dc.SelectObject(&oldbm);
}