有一段程序,我改后无法达到效果,请大侠进来看看,很急切!!!!!!!!!
尝试一个基于对话框的程序,
void CResizeDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
if (m_tracker)
{
CDC* pDC = GetDC();
m_tracker->Draw(pDC);
}
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CResizeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CResizeDlg::OnStart()
{
CDC* pDC = GetDC();
if (m_tracker)
{
delete m_tracker;
m_tracker = NULL;
}
LPRECT rect = new RECT;
CWnd* wnd = (CWnd*)(GetDlgItem(IDC_EDIT1));
wnd->GetWindowRect(rect) ;
ScreenToClient(rect) ;
//pDC->LPtoDP(rect);
m_tracker = new CRectTracker(rect,CRectTracker::dottedLine | CRectTracker::resizeOutside | CRectTracker::hatchedBorder );
m_tracker->Draw(pDC) ;
delete rect;
rect = NULL;
}
void CResizeDlg::OnStop()
{
if (m_tracker)
{
delete m_tracker;
m_tracker = NULL;
Invalidate(TRUE);
}
}
BOOL CResizeDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (m_tracker)
if (pWnd == this && m_tracker->SetCursor(this, nHitTest))
return TRUE;
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CResizeDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_tracker)
{
m_tracker->Track(this, point, TRUE);
Invalidate(FALSE);
CDC* pDC = GetDC();
m_tracker->Draw(pDC);
LPRECT rect = new RECT;
CWnd* wnd = (CWnd*)(GetDlgItem(IDC_EDIT1));
rect = LPRECT(m_tracker->m_rect);
wnd->MoveWindow(rect,TRUE) ;
rect = NULL;
delete rect;
rect = NULL;
}
CDialog::OnLButtonDown(nFlags, point);
}
CRectTracker* m_tracker;
IDC_EDIT1是在对话框上放置的一个Edit,以上的程序实现当实现OnStart()时,该edit可以被Resize,现在的问题是如果在这个Edit(或者其他的控件上)在增加一个控件,如何用以上的方法来移动这个控件?
十分急切希望得到答案,我尝试了一下,不能正确定位。。。。