#ifndef CPOPWINDOW_H
#define CPOPWINDOW_H


class CPopWindow : public CDialog
{
    DECLARE_DYNAMIC(CPopWindow)

public:
    CPopWindow(CWnd* pParent = NULL);
    virtual ~CPopWindow();

    enum { IDD = IDD_POPUP };

protected:
    virtual void DoDataExchange(CDataExchange* pDX);

public:
    void    SetSmallRect(CRect &Crect);
    void    SetBigRect(CRect &Crect);
    void    SetImage(CRect &Crect, LPCTSTR lpszPath);

public:
    afx_msg void    OnMouseMove(UINT nFlags, CPoint point);
    LRESULT         OnMouseLeave(WPARAM wParam, LPARAM lParam);

    DECLARE_MESSAGE_MAP()

public:
    CStatic          m_Static;
    CRect            m_rcBig;
    CRect            m_rcSmall;
};


#endif //CPOPWINDOW_H



程序代码:
#define IDC_MY_STATIC    2000

IMPLEMENT_DYNAMIC(CPopWindow, CDialog)

CPopWindow::CPopWindow(CWnd* pParent /*=NULL*/)
    : CDialog(CDlgInfo::IDD, pParent)
{
}

CPopWindow::~CPopWindow()
{
}

void CPopWindow::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CPopWindow, CDialog)
    ON_WM_MOUSEMOVE()
    ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
END_MESSAGE_MAP()


BOOL CPopWindow::SetImage(CRect &Crect, LPCTSTR lpszPath)
{
    HBITMAP hBmp=(HBITMAP)::LoadImage(
                            0,
                            lpszPath,
                            IMAGE_BITMAP,
                            Crect.Width(),
                            Crect.Height(),
                            LR_LOADFROMFILE
                        );
    m_Static.Create(NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, Crect, this, IDC_MY_STATIC);
    m_Static.SetBitmap(hBmp);
}

void CPopWindow::SetSmallRect(CRect &Crect)
{
    m_rcSmall = Crect;
    MoveWindow(&m_rcSmall);
}

void CPopWindow::SetBigRect(CRect &Crect)
{
    m_rcBig = Crect;
}

void CPopWindow::OnMouseMove(UINT nFlags, CPoint point)
{
    TRACKMOUSEEVENT tme;
    tme.cbSize=sizeof(TRACKMOUSEEVENT); //监控鼠标离开
    tme.dwFlags = TME_LEAVE;
    tme.hwndTrack=this->m_hWnd;
    if(::_TrackMouseEvent(&tme))
    {
        m_Static.ShowWindow(SW_HIDE);
        MoveWindow(&m_rcBig);
    }
}

LRESULT CPopWindow::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
    CPoint pt;
    GetCursorPos(&pt);        //获取相对于屏幕的坐标
    if(!m_rcBig.PtInRect(pt))
    {
        m_Static.ShowWindow(SW_SHOW);
        MoveWindow(&m_rcSmall);
    }
    return TRUE;
}