Compartilhar via


CMFCLinkCtrl Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CMFCLinkCtrl Class.

The CMFCLinkCtrl class displays a button as a hyperlink and invokes the link's target when the button is clicked.

Syntax

class CMFCLinkCtrl : public CMFCButton  

Members

Public Methods

Name Description
CMFCLinkCtrl::SetURL Displays a specified URL as the button text.
CMFCLinkCtrl::SetURLPrefix Sets the implicit protocol (for example, "http:") of the URL.
CMFCLinkCtrl::SizeToContent Resizes the button to contain the button text or bitmap.

Protected Methods

Name Description
CMFCLinkCtrl::OnDrawFocusRect Called by the framework before the focus rectangle of the button is drawn.

Remarks

When you click a button that is derived from the CMFCLinkCtrl class, the framework passes the URL of the button as a parameter to the ShellExecute method. Then the ShellExecute method opens the target of the URL.

Example

The following example demonstrates how to set the size of a CMFCLinkCtrl object, and how to set a url and a tooltip in a CMFCLinkCtrl object. This example is part of the New Controls sample.

   CMFCLinkCtrl m_btnLink;
   m_btnLink.SetURL(_T("https://www.microsoft.com"));
    m_btnLink.SetTooltip(_T("Visit Microsoft site"));
    // resize the button to contain the button text or bitmap
    m_btnLink.SizeToContent();

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CButton

CMFCButton

CMFCLinkCtrl

Requirements

Header: afxlinkctrl.h

CMFCLinkCtrl::OnDrawFocusRect

Called by the framework before the focus rectangle of the button is drawn.

virtual void OnDrawFocusRect(
    CDC* pDC,  
    const CRect& rectClient);

Parameters

[in] pDC
A pointer to a device context.

[in] rectClient
A rectangle that bounds the link control.

Remarks

Override this method when you want to use your own code to draw the button's focus rectangle.

CMFCLinkCtrl::SetURL

Displays a specified URL as the button text.

void SetURL(LPCTSTR lpszURL);

Parameters

[in] lpszURL
The button text to display.

Remarks

CMFCLinkCtrl::SetURLPrefix

Sets the implicit protocol (for example, "http:") of the URL.

void SetURLPrefix(LPCTSTR lpszPrefix);

Parameters

[in] lpszPrefix
The prefix of the URL protocol.

Remarks

Use this method to set the URL prefix. The prefix is not displayed on the button's face, but you can use it to help browse to the URL's target.

CMFCLinkCtrl::SizeToContent

Resizes the button to contain the button text or bitmap.

virtual CSize SizeToContent(
    BOOL bVCenter=FALSE,  
    BOOL bHCenter=FALSE);

Parameters

[in] bVCenter
TRUE to center the button text and bitmap vertically between the top and bottom of the link control; otherwise, FALSE. The default value is FALSE.

[in] bHCenter
TRUE to center the button text and bitmap horizontally between the left and right sides of the link control; otherwise, FALSE. The default value is FALSE.

Return Value

A CSize object that contains the new size of the link control.

Remarks

See Also

Hierarchy Chart
Classes
CLinkCtrl Class
CMFCButton Class