我在DIALOG放票一个图标,要怎么要才能用mouse拖放到窗休体任意位置呀

解决方案 »

  1.   

    重载CStatic类,设置Notify属性// CNewStatic类H文件
    #if !defined(AFX_NEWSTATIC_H__FAC16146_DC25_42CA_9D81_38A03FA49932__INCLUDED_)
    #define AFX_NEWSTATIC_H__FAC16146_DC25_42CA_9D81_38A03FA49932__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // NewStatic.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CNewStatic windowclass CNewStatic : public CStatic
    {
    // Construction
    public:
    CNewStatic();// Attributes
    private:
    BOOL m_bDown;
    CPoint m_pt;
    CRect m_rc;
    // Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CNewStatic)
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CNewStatic(); // Generated message map functions
    protected:
    //{{AFX_MSG(CNewStatic)
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_NEWSTATIC_H__FAC16146_DC25_42CA_9D81_38A03FA49932__INCLUDED_)------------------------------------------
    // CNewStatic类CPP文件
    // NewStatic.cpp : implementation file
    //#include "stdafx.h"
    #include "NewStatic.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CNewStaticCNewStatic::CNewStatic()
    {
    m_bDown = FALSE;
    m_pt.x = 0;
    m_pt.y = 0;
    m_rc.SetRectEmpty();
    }CNewStatic::~CNewStatic()
    {
    }
    BEGIN_MESSAGE_MAP(CNewStatic, CStatic)
    //{{AFX_MSG_MAP(CNewStatic)
    ON_WM_LBUTTONDOWN()
    ON_WM_LBUTTONUP()
    ON_WM_MOUSEMOVE()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CNewStatic message handlersvoid CNewStatic::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    SetCapture();
    m_bDown = TRUE;
    m_pt = point;
    GetWindowRect(m_rc);
    GetParent()->ScreenToClient(m_rc);
    CStatic::OnLButtonDown(nFlags, point);
    }void CNewStatic::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    ReleaseCapture();
    m_bDown = FALSE;
    CStatic::OnLButtonUp(nFlags, point);
    }void CNewStatic::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CStatic::OnMouseMove(nFlags, point); if(m_bDown)
    {
    int cx = point.x - m_pt.x;
    int cy = point.y - m_pt.y;
    int nWidth = m_rc.Width();
    int nHight = m_rc.Height();
    m_rc.left += cx;
    m_rc.top += cy;
    m_rc.right = m_rc.left + nWidth;
    m_rc.bottom = m_rc.top + nHight;
    MoveWindow(m_rc);
    }
    }
      

  2.   

    用CRectTracker类,很容易实现.网上有例子,我的资源中也有这样的例子