我最了个超级连接  但是现在的一个小问题就是当我的光标移动到static那个控件上的时候鼠标自动消失   其他一切都正常,按下还是可以正常打开网站!代码如下CHyperLinker::CHyperLinker()
{
        m_bAboveControl = FALSE;
m_bUnderLine = FALSE;
m_bVisited = FALSE;
}
CHyperLinker::~CHyperLinker()
{
}
BEGIN_MESSAGE_MAP(CHyperLinker, CStatic)         //{{AFX_MSG_MAP(CHyperLinker)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_CTLCOLOR_REFLECT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP() /////////////////////////////////////////////////////////////////////////////// CHyperLinker message handlers
void CHyperLinker::OnMouseMove(UINT nFlags, CPoint point)
{         // TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(rect);        // 得到当前文本框的矩形区域
static BOOL bIsIn = FALSE;       // 判断前一次鼠标是否已经在文本框区域
if (rect.PtInRect(point))   // 在区域内
{
m_bAboveControl = TRUE;      // 记录鼠标已经停留在超级链接文本框的上方
if (!bIsIn)           // 如果是第一次停留,则用其他颜色重绘文本
        {
SetCapture();   // 设置鼠标捕获
bIsIn = TRUE;
Invalidate();     // 调用CtrlColor重绘文本
        }
    }
else
    {
         m_bAboveControl = FALSE;      // 记录鼠标不在超级链接文本框的上方         if (bIsIn)             // 如果是第一次离开区域,则用其他颜色重绘文本
 {
                ReleaseCapture();   // 释放鼠标捕获
bIsIn = FALSE;
Invalidate();               // 调用CtrlColor重绘文本
         }
     }
     CStatic::OnMouseMove(nFlags, point);
} void CHyperLinker::OnLButtonDown(UINT nFlags, CPoint point)
{         // TODO: Add your message handler code here and/or call default
         OpenUsingShellExecute();                 // shell外部程序
         m_bVisited = TRUE;                   // 表示应经点击过超级链接文本框
         Invalidate();               // 调用CtrlColor重绘文本
         CStatic::OnLButtonDown(nFlags, point);
} BOOL CHyperLinker::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{         // TODO: Add your message handler code here and/or call defaul
       HCURSOR LinkCurlor = ::AfxGetApp()->LoadCursor(IDC_SIZENS);
         ::SetCursor(LinkCurlor);
         return TRUE;
         return CStatic::OnSetCursor(pWnd, nHitTest, message);} HBRUSH CHyperLinker::CtlColor(CDC* pDC, UINT nCtlColor)
{         // TODO: Change any attributes of the DC here
         ASSERT(nCtlColor == CTLCOLOR_STATIC);
         DWORD dwStyle = GetStyle();
         if (!(dwStyle & SS_NOTIFY))
         {
              ::SetWindowLong(m_hWnd, GWL_STYLE, dwStyle | SS_NOTIFY);
         }       
         HBRUSH hbr = NULL;
         if ((dwStyle & 0xFF) <= SS_RIGHT)
         {                   // modify the font to be underline
             if (!((HFONT)m_Font))
             {                  LOGFONT lf;
                  GetFont()->GetObject(sizeof(lf), &lf);
                  lf.lfUnderline = m_bUnderLine;
                  m_Font.CreateFontIndirect(&lf);
             }
             pDC->SelectObject(&m_Font);
                   // set the text color
            if (m_bVisited)
            {
                pDC->SetTextColor(m_VisitedColor);
            }
            else
            {
                 if (m_bAboveControl)
                 {
                         pDC->SetTextColor(m_CoverColor);
                 }
                 else
                 {
                          pDC->SetTextColor(m_InitColor);
                 }
            }
            pDC->SetBkMode(TRANSPARENT);
            hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
         }         // TODO: Return a non-NULL brush if the parent's handler should not be called
         return hbr;
}
void CHyperLinker::SetFont(CFont *font)
{         // 设置字体
         memcpy(&m_Font, font, sizeof(CFont));
         // 根据字体的长度和宽度设置静态框的长度和宽度
         CDC *pDC = GetDC();     
         CFont *pOldfont = pDC->SelectObject(&m_Font);
         CString str;
         GetWindowText(str);      
         CSize size = pDC->GetTextExtent(str, str.GetLength());
         SetWindowPos(NULL, 0, 0, size.cx, size.cy, SWP_NOMOVE);
         pDC->SelectObject(pOldfont);
         ReleaseDC(pDC);}BOOL CHyperLinker::OpenUsingShellExecute()
{
         HINSTANCE hRun = ShellExecute(GetParent()->GetSafeHwnd(),
                   _T("open"), m_sURL, NULL, NULL, SW_SHOW);
         if((int)hRun <= 32)
         {
                   AfxMessageBox(_T("提供的超级链接或者指定的文件无法执行"), MB_OK, 0);
                   return FALSE;
         }
         return TRUE;
}
void CHyperLinker::SetAttrbute(CString url, COLORREF InitColor, COLORREF VisitedColor,
                                     COLORREF CoverColor, BOOL bUnderLine)
{
         m_sURL = url;
         m_InitColor = InitColor;
         m_VisitedColor = VisitedColor;
         m_CoverColor = CoverColor;
         m_bUnderLine = bUnderLine;
}是这句有问题吗??
HCURSOR LinkCurlor = ::AfxGetApp()->LoadCursor(IDC_SIZENS);
这个IDC_SIZENS我换来换去都是一样!   

解决方案 »

  1.   

    BOOL CHyperLinker::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
    {         // TODO: Add your message handler code here and/or call defaul
           HCURSOR LinkCurlor = ::AfxGetApp()->LoadCursor(IDC_SIZENS);
             ::SetCursor(LinkCurlor);
             return TRUE;
             return CStatic::OnSetCursor(pWnd, nHitTest, message);

             //这是干嘛,两个return,应该根据不同条件,来调用不同的
    }
      

  2.   

    那应该写成啥样的呀!见谅  我才学习mfc  能说的细点不!呵呵   新手!
      

  3.   

    int nID=pWnd->GetDlgCtrlID();//
    if(nID==你的CStatic控件ID)
         这个时候才装载你的鼠标光标;
    else
         其他的就不要重新装载了,默认就可以了