zoukankan      html  css  js  c++  java
  • HiperLink

    //HiperLink.H
    #ifndef __HYPERLINK_H__
    #define __HYPERLINK_H__
    
    #if _MSC_VER >= 1000
    #pragma once
    #endif // _MSC_VER >= 1000
    
    /////////////////////////////////////////////////////////////////////////////
    // CHyperLink window
    
    class AFX_EXT_CLASS CHyperLink : public CStatic
    {
    // Construction/destruction
    public:
        CHyperLink();
        virtual ~CHyperLink();
    // Attributes
    public:
        CString m_strWebsite;
    // Operations
    public:
        BOOL SetCursor(HCURSOR hCursor);
        void SetInfo(LPTSTR sMailAddr,LPTSTR sName, LPTSTR sBadTips);
    
    // Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CHyperLink)
        protected:
        virtual void PreSubclassWindow();
        //}}AFX_VIRTUAL
    
    // Protected attributes
    protected:
        COLORREF m_crLinkColour;
        COLORREF m_crHoverColour;
        BOOL     m_bOverControl;
        HCURSOR  m_hLinkCursor;
        CFont    m_Font;
        CString  m_MailAddr;
        CString  m_ShowName;
        CString  m_BadTips;
        // Generated message map functions
    protected:
        //{{AFX_MSG(CHyperLink)
        afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
        afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
        afx_msg void OnMouseMove(UINT nFlags, CPoint point);
        //}}AFX_MSG
        afx_msg void OnClicked();
        DECLARE_MESSAGE_MAP()
    };
    
    /////////////////////////////////////////////////////////////////////////////
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
    
    #endif
    //HyperLink.CPP
    // HyperLink.cpp : implementation file
    
    #include "..stdafx.h"
    #include "HiperLink.h"
    #include "..Resource.h"
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CHyperLink
    
    CHyperLink::CHyperLink()
    {
        m_crLinkColour    = RGB( 0, 0, 238 );
        m_crHoverColour    = RGB( 255, 0, 255 );
        m_bOverControl    = FALSE;
    }
    
    CHyperLink::~CHyperLink()
    {
        m_Font.DeleteObject();
    }
    
    BEGIN_MESSAGE_MAP(CHyperLink, CStatic)
        //{{AFX_MSG_MAP(CHyperLink)
        ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
        ON_WM_CTLCOLOR_REFLECT()
        ON_WM_SETCURSOR()
        ON_WM_MOUSEMOVE()
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CHyperLink message handlers
    
    void CHyperLink::OnClicked()
    {
        CString strURL(m_MailAddr);
        
        //GetWindowText( strMailAddress );
        // 装配成 URL 地址
        //strURL.Format( _T("mailto:%s"), (LPCTSTR)m_MailAddr);
        
        // 调用 ShellExecute() 执行邮件发送
        int iRet = (int)ShellExecute( NULL, _T("open"), (LPCTSTR)strURL, NULL, NULL, SW_SHOW );
        if (iRet <= HINSTANCE_ERROR  && 
            MessageBox(_T("提示:发送邮件失败!
    系统未安装邮件处理程序,或未设置缺省的邮件处理程序!!
    
    是否打开我的头条号:音符的尾巴?"), 
            _T("哎哟,发不了邮件!"), MB_YESNO) == IDYES)
        {
            int iRet2 = (int)ShellExecute( NULL, _T("open"), _T("https://www.toutiao.com/c/user/64659995094/"), NULL, NULL, SW_SHOW );
            if( iRet2 <= HINSTANCE_ERROR )
                AfxMessageBox(_T("打开失败!
    系统未安装浏览器,或未设置缺省的浏览器!!
    
    "), MB_OK | MB_ICONEXCLAMATION );
        }
    }
    
    HBRUSH CHyperLink::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
        ASSERT(nCtlColor == CTLCOLOR_STATIC);
    
        if( m_bOverControl )
            pDC->SetTextColor(m_crHoverColour);
        else
            pDC->SetTextColor(m_crLinkColour);
        
        pDC->SetBkMode( TRANSPARENT );
    
        return (HBRUSH)GetStockObject( NULL_BRUSH );
    }
    
    void CHyperLink::OnMouseMove(UINT nFlags, CPoint point) 
    {
        CStatic::OnMouseMove(nFlags, point);
    
        if( m_bOverControl ) {
            CRect rc;
            GetClientRect( &rc );
    
            if( !rc.PtInRect(point) ) {
                m_bOverControl = FALSE;
                ReleaseCapture();
                RedrawWindow();
                return;
            }
        }
        else {
            m_bOverControl = TRUE;
            RedrawWindow();
            SetCapture();
        }
    }
    
    BOOL CHyperLink::OnSetCursor(CWnd* /*pWnd*/, UINT /*nHitTest*/, UINT /*message*/) 
    {
        ::SetCursor( m_hLinkCursor );
        return TRUE;
    }
    
    void CHyperLink::PreSubclassWindow() 
    {
        // 要求得到 STN_CLICKED 通知消息
        DWORD dwStyle = GetStyle();
        ::SetWindowLong( GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
    
        // 设置字体下划线
        LOGFONT lf;
        GetFont()->GetLogFont( &lf );
        lf.lfUnderline = TRUE;
        m_Font.CreateFontIndirect( &lf );
        SetFont( &m_Font );
    
        CStatic::PreSubclassWindow();
    }
    
    void CHyperLink::SetInfo(LPTSTR sMailAddr, LPTSTR sName, LPTSTR sBadTips)
    {
        m_MailAddr            = sMailAddr;
        m_ShowName            = sName;
        m_BadTips            = sBadTips;
    }
    
    BOOL CHyperLink::SetCursor(HCURSOR hCursor)
    {
        m_hLinkCursor = hCursor;
    
        return TRUE;
    }
  • 相关阅读:
    字符串匹配算法 【微软面试100题 第三十三题】
    交换元素,使两数组之和的差最小 【微软面试100题 第三十二题】
    在从1到n的正数中1出现的次数 【微软面试100题 第三十题】
    栈的push、pop序列 【微软面试100题 第二十九题】
    整数的二进制表示中1的个数 【微软面试100题 第二十八题】
    跳台阶问题 【微软面试100题 第二十七题】
    左旋转字符串 【微软面试100题 第二十六题】
    字符串中找出最长的数字串 【微软面试100题 第二十五题】
    合并链表 【微软面试100题 第二十四题】
    计算圆形是否和正方形相交 【微软面试100题 第二十三题】
  • 原文地址:https://www.cnblogs.com/autumoonchina/p/7833357.html
Copyright © 2011-2022 走看看