• 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;
    }
  • 相关阅读:
    return false 和 return true
    前端异常采集
    Performance — 前端性能监控利器
    正则笔记-忘记就来看
    JS中的正则应用
    iconfont的使用
    canvas笔记1
    树莓派3B安装DeBian 64位系统及其安装私有云网盘----可道云
    台灯改造【智能台灯】
    单片机C语言中标志位的经典应用
  • 原文地址:https://www.cnblogs.com/autumoonchina/p/7833357.html
Copyright © 2020-2023  润新知